Skip to content

Commit a29fc3b

Browse files
authored
Task/hdrp issue6000 2 (#363)
* applied the suggested fix in #360 * Applied more. * custom light direction was mistakenly deleted.
1 parent aa9cd31 commit a29fc3b

File tree

6 files changed

+59
-9
lines changed

6 files changed

+59
-9
lines changed

com.unity.toonshader/Runtime/HDRP/Shaders/DoubleShadeWithFeatherMainLight.hlsl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ float3 UTS_MainLight(LightLoopContext lightLoopContext, FragInputs input, float3
6666
// float4 tmpColor = EvaluateLight_Directional(context, posInput, _DirectionalLightDatas[mainLightIndex]);
6767
// float3 mainLightColor = tmpColor.xyz;
6868
float3 defaultLightDirection = normalize(UNITY_MATRIX_V[2].xyz + UNITY_MATRIX_V[1].xyz);
69-
float3 defaultLightColor = saturate(max(float3(0.05, 0.05, 0.05) * _Unlit_Intensity, max(ShadeSH9(float4(0.0, 0.0, 0.0, 1.0)), ShadeSH9(float4(0.0, -1.0, 0.0, 1.0)).rgb) * _Unlit_Intensity));
69+
float3 defaultLightColor = saturate(max(float3(0.05, 0.05, 0.05) * _Unlit_Intensity, max(
70+
SampleBakedGI_UTS(posInput.positionWS, float3(0.0, 0.0, 0.0), input.texCoord1.xy, input.texCoord2.xy, true),
71+
SampleBakedGI_UTS(posInput.positionWS, float3(0.0, -1.0, 0.0), input.texCoord1.xy, input.texCoord2.xy, true)
72+
) * _Unlit_Intensity));
7073
float3 customLightDirection = normalize(mul(UNITY_MATRIX_M, float4(((float3(1.0, 0.0, 0.0) * _Offset_X_Axis_BLD * 10) + (float3(0.0, 1.0, 0.0) * _Offset_Y_Axis_BLD * 10) + (float3(0.0, 0.0, -1.0) * lerp(-1.0, 1.0, _Inverse_Z_Axis_BLD))), 0)).xyz);
7174
float3 lightDirection = normalize(lerp(defaultLightDirection, mainLihgtDirection.xyz, any(mainLihgtDirection.xyz)));
7275
lightDirection = lerp(lightDirection, customLightDirection, _Is_BLD);
@@ -288,8 +291,8 @@ float3 UTS_MainLight(LightLoopContext lightLoopContext, FragInputs input, float3
288291
float3 finalColor = lerp(_RimLight_var, matCapColorFinal, _MatCap);// Final Composition before Emissive
289292
//
290293
//v.2.0.6: GI_Intensity with Intensity Multiplier Filter
291-
float3 envLightColor = DecodeLightProbe(utsData.normalDirection) < float3(1, 1, 1) ? DecodeLightProbe(utsData.normalDirection) : float3(1, 1, 1);
292-
float envLightIntensity = 0.299 * envLightColor.r + 0.587 * envLightColor.g + 0.114 * envLightColor.b < 1 ? (0.299 * envLightColor.r + 0.587 * envLightColor.g + 0.114 * envLightColor.b) : 1;
294+
float3 envLightColor = saturate(SampleBakedGI_UTS(posInput.positionWS, utsData.normalDirection, input.texCoord1.xy, input.texCoord2.xy, true));
295+
float envLightIntensity = saturate(0.299 * envLightColor.r + 0.587 * envLightColor.g + 0.114 * envLightColor.b);
293296

294297
finalColor = SATURATE_IF_SDR(finalColor) + (envLightColor * envLightIntensity * _GI_Intensity * smoothstep(1, 0, envLightIntensity / 2)) + emissive;
295298

com.unity.toonshader/Runtime/HDRP/Shaders/HDRPToonHead.hlsl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,38 @@ float rateG = 0.587;
272272
float rateB = 0.114;
273273

274274

275+
float3 SampleBakedGI_UTS(float3 positionRWS, float3 normalWS, float2 uvStaticLightmap, float2 uvDynamicLightmap, bool needToIncludeAPV = false)
276+
{
277+
float3 bakeDiffuseLighting = float3(0, 0, 0);
278+
float3 backBakeDiffuseLighting = float3(0, 0, 0);
279+
float3 backNormalWS = float3(0, 0, 0);
280+
281+
#if !defined(_SURFACE_TYPE_TRANSPARENT) && (SHADERPASS != SHADERPASS_RAYTRACING_INDIRECT) && (SHADERPASS != SHADERPASS_RAYTRACING_GBUFFER)
282+
if (_IndirectDiffuseMode != INDIRECTDIFFUSEMODE_OFF
283+
#if (SHADERPASS == SHADERPASS_GBUFER)
284+
&& _IndirectDiffuseMode != INDIRECTDIFFUSEMODE_MIXED && _ReflectionsMode != REFLECTIONSMODE_MIXED
285+
#endif
286+
)
287+
return bakeDiffuseLighting;
288+
#endif
289+
290+
#if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON)
291+
EvaluateLightmap(positionRWS, normalWS, backNormalWS, uvStaticLightmap, uvDynamicLightmap, bakeDiffuseLighting, backBakeDiffuseLighting);
292+
#elif (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2))
293+
if (needToIncludeAPV)
294+
{
295+
EvaluateAdaptiveProbeVolume(GetAbsolutePositionWS(positionRWS), normalWS, backNormalWS, GetWorldSpaceNormalizeViewDir(positionRWS), 0.0, bakeDiffuseLighting, backBakeDiffuseLighting);
296+
}
297+
#else
298+
EvaluateLightProbeBuiltin(positionRWS, normalWS, backNormalWS, bakeDiffuseLighting, backBakeDiffuseLighting);
275299

300+
#if defined(SHADER_STAGE_RAY_TRACING)
301+
bakeDiffuseLighting *= _RayTracingAmbientProbeDimmer;
302+
backBakeDiffuseLighting *= _RayTracingAmbientProbeDimmer;
303+
#endif
304+
#endif
305+
306+
return bakeDiffuseLighting;
307+
}
276308

277309
#endif //#ifndef UCTS_HDRP_INCLUDED

com.unity.toonshader/Runtime/HDRP/Shaders/HDRPToonOutline.hlsl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,10 @@ void Frag(PackedVaryingsToPS packedInput,
150150
float4 unity_AmbientEquator = float4(0.05, 0.05, 0.05, 1.0); //Todo.
151151
//v.2.0.9
152152
float3 envLightSource_GradientEquator = unity_AmbientEquator.rgb >0.05 ? unity_AmbientEquator.rgb : half3(0.05,0.05,0.05);
153-
float3 envLightSource_SkyboxIntensity = max(ShadeSH9(half4(0.0,0.0,0.0,1.0)),ShadeSH9(half4(0.0,-1.0,0.0,1.0))).rgb;
153+
float3 envLightSource_SkyboxIntensity = max(
154+
SampleBakedGI_UTS(objPos, float3(0.0, 0.0, 0.0), input.texCoord1.xy, input.texCoord2.xy, true),
155+
SampleBakedGI_UTS(objPos, float3(0.0, -1.0, 0.0), input.texCoord1.xy, input.texCoord2.xy, true)
156+
).rgb;
154157
float3 ambientSkyColor = envLightSource_SkyboxIntensity.rgb>0.0 ? envLightSource_SkyboxIntensity*_Unlit_Intensity : envLightSource_GradientEquator*_Unlit_Intensity;
155158
//
156159
float3 lightColor = _LightColor0.rgb >0.05 ? _LightColor0.rgb : ambientSkyColor.rgb;

com.unity.toonshader/Runtime/HDRP/Shaders/ShadingGrademapMainLight.hlsl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,11 @@ float3 UTS_MainLightShadingGrademap(LightLoopContext lightLoopContext, FragInput
7373

7474
float3 defaultLightDirection = normalize(UNITY_MATRIX_V[2].xyz + UNITY_MATRIX_V[1].xyz);
7575
//v.2.0.5
76-
float3 defaultLightColor = saturate(max(float3(0.05, 0.05, 0.05) * _Unlit_Intensity, max(ShadeSH9(float4(0.0, 0.0, 0.0, 1.0)), ShadeSH9(float4(0.0, -1.0, 0.0, 1.0)).rgb) * _Unlit_Intensity));
77-
float3 customLightDirection = normalize(mul(UNITY_MATRIX_M, float4(((float3(1.0, 0.0, 0.0) * _Offset_X_Axis_BLD * 10) + (float3(0.0, 1.0, 0.0) * _Offset_Y_Axis_BLD * 10) + (float3(0.0, 0.0, -1.0) * lerp(-1.0, 1.0, _Inverse_Z_Axis_BLD))), 0)).xyz);
76+
float3 defaultLightColor = saturate(max(float3(0.05, 0.05, 0.05) * _Unlit_Intensity, max(
77+
SampleBakedGI_UTS(posInput.positionWS, float3(0.0, 0.0, 0.0), input.texCoord1.xy, input.texCoord2.xy, true),
78+
SampleBakedGI_UTS(posInput.positionWS, float3(0.0, -1.0, 0.0), input.texCoord1.xy, input.texCoord2.xy, true)
79+
) * _Unlit_Intensity));
80+
float3 customLightDirection = normalize(mul(UNITY_MATRIX_M, float4(((float3(1.0, 0.0, 0.0) * _Offset_X_Axis_BLD * 10) + (float3(0.0, 1.0, 0.0) * _Offset_Y_Axis_BLD * 10) + (float3(0.0, 0.0, -1.0) * lerp(-1.0, 1.0, _Inverse_Z_Axis_BLD))), 0)).xyz);
7881
float3 lightDirection = normalize(lerp(defaultLightDirection, mainLihgtDirection.xyz, any(mainLihgtDirection.xyz)));
7982
lightDirection = lerp(lightDirection, customLightDirection, _Is_BLD);
8083
float3 originalLightColor = mainLightColor.rgb;
@@ -387,8 +390,8 @@ float3 UTS_MainLightShadingGrademap(LightLoopContext lightLoopContext, FragInput
387390

388391

389392
//v.2.0.6: GI_Intensity with Intensity Multiplier Filter
390-
float3 envLightColor = DecodeLightProbe(utsData.normalDirection) < float3(1, 1, 1) ? DecodeLightProbe(utsData.normalDirection) : float3(1, 1, 1);
391-
float envLightIntensity = 0.299 * envLightColor.r + 0.587 * envLightColor.g + 0.114 * envLightColor.b < 1 ? (0.299 * envLightColor.r + 0.587 * envLightColor.g + 0.114 * envLightColor.b) : 1;
393+
float3 envLightColor = saturate(SampleBakedGI_UTS(posInput.positionWS, utsData.normalDirection, input.texCoord1.xy, input.texCoord2.xy, true));
394+
float envLightIntensity = saturate(0.299 * envLightColor.r + 0.587 * envLightColor.g + 0.114 * envLightColor.b);
392395

393396
finalColor = SATURATE_IF_SDR(finalColor) + (envLightColor * envLightIntensity * _GI_Intensity * smoothstep(1, 0, envLightIntensity / 2)) + emissive;
394397

com.unity.toonshader/Runtime/HDRP/Shaders/UtsSelfShadowMainLight.hlsl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ float3 UTS_SelfShdowMainLight(LightLoopContext lightLoopContext, FragInputs inpu
5757
// float4 tmpColor = EvaluateLight_Directional(context, posInput, _DirectionalLightDatas[mainLightIndex]);
5858
// float3 mainLightColor = tmpColor.xyz;
5959
float3 defaultLightDirection = normalize(UNITY_MATRIX_V[2].xyz + UNITY_MATRIX_V[1].xyz);
60-
float3 defaultLightColor = saturate(max(float3(0.05, 0.05, 0.05) * _Unlit_Intensity, max(ShadeSH9(float4(0.0, 0.0, 0.0, 1.0)), ShadeSH9(float4(0.0, -1.0, 0.0, 1.0)).rgb) * _Unlit_Intensity));
60+
float3 defaultLightColor = saturate(max(float3(0.05, 0.05, 0.05) * _Unlit_Intensity, max(
61+
SampleBakedGI_UTS(posInput.positionWS, float3(0.0, 0.0, 0.0), input.texCoord1.xy, input.texCoord2.xy, true),
62+
SampleBakedGI_UTS(posInput.positionWS, float3(0.0, -1.0, 0.0), input.texCoord1.xy, input.texCoord2.xy, true)
63+
) * _Unlit_Intensity));
6164
float3 customLightDirection = normalize(mul(UNITY_MATRIX_M, float4(((float3(1.0, 0.0, 0.0) * _Offset_X_Axis_BLD * 10) + (float3(0.0, 1.0, 0.0) * _Offset_Y_Axis_BLD * 10) + (float3(0.0, 0.0, -1.0) * lerp(-1.0, 1.0, _Inverse_Z_Axis_BLD))), 0)).xyz);
6265
float3 lightDirection = normalize(lerp(defaultLightDirection, mainLihgtDirection.xyz, any(mainLihgtDirection.xyz)));
6366
lightDirection = lerp(lightDirection, customLightDirection, _Is_BLD);

com.unity.toonshader/Runtime/Integrated/Shaders/UnityToon.shader

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,8 @@ Shader "Toon" {
964964
#pragma multi_compile _ LIGHTMAP_ON
965965
#pragma multi_compile _ DIRLIGHTMAP_COMBINED
966966
#pragma multi_compile _ DYNAMICLIGHTMAP_ON
967+
// Ensure APV path is taken if available
968+
#pragma multi_compile_fragment _ PROBE_VOLUMES_L1 PROBE_VOLUMES_L2
967969
#pragma multi_compile _ SHADOWS_SHADOWMASK
968970
// Setup DECALS_OFF so the shader stripper can remove variants
969971
#pragma multi_compile DECALS_OFF DECALS_3RT DECALS_4RT
@@ -1080,6 +1082,10 @@ Shader "Toon" {
10801082
#define SHADOW_LOW
10811083
#define LIGHTLOOP_DISABLE_TILE_AND_CLUSTER
10821084

1085+
#pragma multi_compile _ LIGHTMAP_ON
1086+
#pragma multi_compile _ DYNAMICLIGHTMAP_ON
1087+
// Ensure APV path is taken if available
1088+
#pragma multi_compile_fragment _ PROBE_VOLUMES_L1 PROBE_VOLUMES_L2
10831089
#pragma multi_compile _IS_OUTLINE_CLIPPING_NO _IS_OUTLINE_CLIPPING_YES
10841090
#pragma multi_compile _OUTLINE_NML _OUTLINE_POS
10851091
#pragma shader_feature _ _IS_CLIPPING_MATTE

0 commit comments

Comments
 (0)