Skip to content

Commit 0789ca0

Browse files
authored
Apply FadeToBlack in URP Particle and Sprite shaders (Unity-Technologies#12)
* Apply FadeToBlack and forward-pass color grading to URP particle shaders * Apply FadeToBlack in URP Sprite-Lit-Default shader
1 parent a87a54c commit 0789ca0

File tree

5 files changed

+44
-2
lines changed

5 files changed

+44
-2
lines changed

com.unity.render-pipelines.universal/Shaders/2D/Sprite-Lit-Default.shader

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ Shader "Universal Render Pipeline/2D/Sprite-Lit-Default"
6565
half4 _MainTex_ST;
6666
half4 _NormalMap_ST;
6767

68+
// (ASG) Support fading to black.
69+
float _FadeToBlack;
70+
6871
#if USE_SHAPE_LIGHT_TYPE_0
6972
SHAPE_LIGHT(0)
7073
#endif
@@ -101,8 +104,12 @@ Shader "Universal Render Pipeline/2D/Sprite-Lit-Default"
101104
{
102105
half4 main = i.color * SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv);
103106
half4 mask = SAMPLE_TEXTURE2D(_MaskTex, sampler_MaskTex, i.uv);
107+
half4 color = CombinedShapeLightShared(main, mask, i.lightingUV);
108+
109+
// (ASG) Apply fade to black.
110+
color.rgb *= _FadeToBlack; // Fading happens in linear color to fade bright spots last
104111

105-
return CombinedShapeLightShared(main, mask, i.lightingUV);
112+
return color;
106113
}
107114
ENDHLSL
108115
}
@@ -194,6 +201,9 @@ Shader "Universal Render Pipeline/2D/Sprite-Lit-Default"
194201
SAMPLER(sampler_MainTex);
195202
float4 _MainTex_ST;
196203

204+
// (ASG) Support fading to black.
205+
float _FadeToBlack;
206+
197207
Varyings UnlitVertex(Attributes attributes)
198208
{
199209
Varyings o = (Varyings)0;
@@ -210,6 +220,10 @@ Shader "Universal Render Pipeline/2D/Sprite-Lit-Default"
210220
float4 UnlitFragment(Varyings i) : SV_Target
211221
{
212222
float4 mainTex = i.color * SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv);
223+
224+
// (ASG) Apply fade to black.
225+
mainTex.rgb *= _FadeToBlack; // Fading happens in linear color to fade bright spots last
226+
213227
return mainTex;
214228
}
215229
ENDHLSL

com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLitForwardPass.hlsl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ half4 ParticlesLitFragment(VaryingsParticle input) : SV_Target
123123
half4 color = UniversalFragmentPBR(inputData, surfaceData);
124124
color.rgb = MixFog(color.rgb, inputData.fogCoord);
125125

126+
// (ASG) Apply global fade to black.
127+
color.rgb *= _FadeToBlack; // Fading happens in linear color to fade bright spots last
128+
126129
// (ASG) Add tonemapping and color grading in forward pass.
127130
// This uses the same color grading function as the post processing shader.
128131
#ifdef _COLOR_TRANSFORM_IN_FORWARD

com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLitInput.hlsl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ float4 _UserLut_Params;
2929
TEXTURE2D(_UserLut);
3030
TEXTURE2D(_InternalLut);
3131
SAMPLER(sampler_LinearClamp);
32-
float _TestParam;
3332

3433
#endif
3534

35+
// (ASG) Support fading to black.
36+
float _FadeToBlack;
37+
3638
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Particles.hlsl"
3739

3840
TEXTURE2D(_MetallicGlossMap); SAMPLER(sampler_MetallicGlossMap);

com.unity.render-pipelines.universal/Shaders/Particles/ParticlesUnlitForwardPass.hlsl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,15 @@ half4 fragParticleUnlit(VaryingsParticle input) : SV_Target
112112
result = MixFog(result, fogFactor);
113113
albedo.a = OutputAlpha(albedo.a, _Surface);
114114

115+
// (ASG) Apply global fade to black.
116+
result.rgb *= _FadeToBlack; // Fading happens in linear color to fade bright spots last
117+
118+
// (ASG) Add tonemapping and color grading in forward pass.
119+
// This uses the same color grading function as the post processing shader.
120+
#ifdef _COLOR_TRANSFORM_IN_FORWARD
121+
color.rgb = ApplyColorGrading(result.rgb, _Lut_Params.w, TEXTURE2D_ARGS(_InternalLut, sampler_LinearClamp), _Lut_Params.xyz, TEXTURE2D_ARGS(_UserLut, sampler_LinearClamp), _UserLut_Params.xyz, _UserLut_Params.w);
122+
#endif
123+
115124
return half4(result, albedo.a);
116125
}
117126

com.unity.render-pipelines.universal/Shaders/Particles/ParticlesUnlitInput.hlsl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@ CBUFFER_START(UnityPerMaterial)
1818
half _Surface;
1919
CBUFFER_END
2020

21+
// (ASG) Used when tonemapping and color grading is done in the forward pass.
22+
#ifdef _COLOR_TRANSFORM_IN_FORWARD
23+
24+
float4 _Lut_Params;
25+
float4 _UserLut_Params;
26+
TEXTURE2D(_UserLut);
27+
TEXTURE2D(_InternalLut);
28+
SAMPLER(sampler_LinearClamp);
29+
30+
#endif
31+
32+
// (ASG) Support fading to black.
33+
float _FadeToBlack;
34+
2135
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Particles.hlsl"
2236

2337
#define SOFT_PARTICLE_NEAR_FADE _SoftParticleFadeParams.x

0 commit comments

Comments
 (0)