Aetheria/Assets/Shaders/Compute/Stardust/Stardust.shader

113 lines
3.9 KiB
Text
Raw Normal View History

2026-06-30 19:14:49 +01:00
Shader "Aetheria/Stardust (Compute)"
{
2026-06-30 19:14:49 +01:00
Properties
{
[HDR] _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
_DistanceSizeExponent ("Distance Size Exponent", Float) = 1
_DistanceIntensityExponent ("Distance Intensity Exponent", Float) = 1
_EmissionGain ("Emission Gain", Range(0, 1)) = 0.3
_Power ("Power", Float) = 2
2026-07-16 18:16:39 +01:00
[HideInInspector] _DitheringTex ("Dithering Texture", 2D) = "white" {}
2026-06-30 19:14:49 +01:00
}
2026-06-30 19:14:49 +01:00
SubShader
{
Tags
{
2026-07-16 18:16:39 +01:00
"Queue" = "AlphaTest"
"RenderType" = "TransparentCutout"
2026-06-30 19:14:49 +01:00
"IgnoreProjector" = "True"
"RenderPipeline" = "UniversalPipeline"
}
Pass
{
Name "Stardust"
Tags { "LightMode" = "UniversalForward" }
2026-07-16 18:16:39 +01:00
Blend One Zero
2026-06-30 19:14:49 +01:00
Cull Off
2026-07-16 18:16:39 +01:00
ZWrite On
2026-06-30 19:14:49 +01:00
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment Frag
#pragma target 5.0
2026-06-30 19:14:49 +01:00
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
struct Particle
{
float3 position;
float3 color;
float size;
};
2026-06-30 19:14:49 +01:00
StructuredBuffer<Particle> particles;
StructuredBuffer<float3> quadPoints;
2026-06-30 19:14:49 +01:00
CBUFFER_START(UnityPerMaterial)
float4 _TintColor;
float _EmissionGain;
float _Power;
float _DistanceSizeExponent;
float _DistanceIntensityExponent;
CBUFFER_END
2026-07-16 18:16:39 +01:00
TEXTURE2D(_DitheringTex);
SAMPLER(sampler_DitheringTex);
float4 _DitheringCoords;
int _FrameNumber;
2026-06-30 19:14:49 +01:00
struct Varyings
{
2026-06-30 19:14:49 +01:00
float4 positionCS : SV_POSITION;
float2 uv : TEXCOORD0;
2026-07-16 18:16:39 +01:00
float4 screenPosition : TEXCOORD1;
float4 color : COLOR;
};
2026-06-30 19:14:49 +01:00
Varyings Vert(uint vertexId : SV_VertexID, uint instanceId : SV_InstanceID)
{
2026-06-30 19:14:49 +01:00
Varyings output;
float3 worldPosition = particles[instanceId].position;
float dist = max(length(worldPosition - _WorldSpaceCameraPos.xyz), 0.001);
float4 viewPosition = mul(UNITY_MATRIX_V, float4(worldPosition, 1.0));
float3 quadPoint = float3(quadPoints[vertexId].xy, 0.0)
* particles[instanceId].size
* pow(dist, _DistanceSizeExponent)
/ pow(100.0, _DistanceSizeExponent);
output.positionCS = mul(UNITY_MATRIX_P, viewPosition + float4(quadPoint, 0.0));
output.uv = quadPoints[vertexId].xy + 0.5;
2026-07-16 18:16:39 +01:00
output.screenPosition = ComputeScreenPos(output.positionCS);
2026-06-30 19:14:49 +01:00
output.color = float4(
particles[instanceId].color * _TintColor.rgb,
100.0 * pow(100.0, _DistanceIntensityExponent) / pow(dist, _DistanceIntensityExponent));
return output;
}
2026-06-30 19:14:49 +01:00
float PowerPulse(float x, float power)
{
2026-06-30 19:14:49 +01:00
x = saturate(abs(x));
return pow((x + 1.0) * (1.0 - x), power);
}
2026-06-30 19:14:49 +01:00
float4 Frag(Varyings input) : SV_Target
{
2026-06-30 19:14:49 +01:00
float emission = PowerPulse(length(input.uv - float2(0.5, 0.5)) * 2.0, _Power);
2026-07-16 18:16:39 +01:00
float2 screenUv = input.screenPosition.xy / input.screenPosition.w;
half dither = frac(SAMPLE_TEXTURE2D(
_DitheringTex,
sampler_DitheringTex,
screenUv * _DitheringCoords.xy).r + _FrameNumber * 1.61803398875);
float alpha = emission * input.color.a;
clip(alpha - dither - 0.001 * (1.0 - ceil(alpha)));
return input.color * emission * exp(_EmissionGain * 5.0);
}
2026-06-30 19:14:49 +01:00
ENDHLSL
}
2026-06-30 19:14:49 +01:00
}
}