Skip to content

Commit

Permalink
Fix normal bias application for additional light shadow maps [closes #51
Browse files Browse the repository at this point in the history
]
  • Loading branch information
Delt06 committed Aug 21, 2022
1 parent 4a34a97 commit 231de54
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@

#pragma shader_feature_local_fragment _ALPHATEST_ON

#pragma multi_compile_vertex _ _CASTING_PUNCTUAL_LIGHT_SHADOW

#pragma vertex ShadowPassVertex
#pragma fragment ShadowPassFragment

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"

float3 _LightDirection;
float3 _LightPosition;

#include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderShadowCasterPass_AppData.hlsl"

Expand All @@ -23,7 +24,13 @@ float4 get_shadow_position_h_clip(appdata input)
const float3 position_ws = TransformObjectToWorld(input.positionOS.xyz);
const float3 normal_ws = TransformObjectToWorldNormal(input.normalOS);

float4 position_cs = TransformWorldToHClip(ApplyShadowBias(position_ws, normal_ws, _LightDirection));
#if _CASTING_PUNCTUAL_LIGHT_SHADOW
const float3 light_direction_ws = normalize(_LightPosition - position_ws);
#else
const float3 light_direction_ws = _LightDirection;
#endif

float4 position_cs = TransformWorldToHClip(ApplyShadowBias(position_ws, normal_ws, light_direction_ws));

#if UNITY_REVERSED_Z
position_cs.z = min(position_cs.z, position_cs.w * UNITY_NEAR_CLIP_VALUE);
Expand Down

0 comments on commit 231de54

Please sign in to comment.