Added stencil setup in UTSAPI;
Changed hair shadow length from screen space to world space;
This commit is contained in:
@@ -117,8 +117,8 @@ DirectLighting UtsShadeSurface(PositionInputs posInput, UtsBSDFData bsdfData, Pr
|
||||
|
||||
if (Max3(lightColor.r, lightColor.g, lightColor.b) > 0.0)
|
||||
{
|
||||
SHADOW_TYPE sharpShadow = smoothstep(0.4, 0.6, shadow);
|
||||
//SHADOW_TYPE sharpShadow = shadow;
|
||||
//SHADOW_TYPE sharpShadow = smoothstep(0.4, 0.6, shadow);
|
||||
SHADOW_TYPE sharpShadow = shadow;
|
||||
#if _RECEIVE_HAIR_SHADOW_ON && ENABLE_UTS_HAIR_SHAOW
|
||||
sharpShadow *= GetHairShadow(posInput, L);
|
||||
#endif
|
||||
@@ -188,8 +188,6 @@ DirectLighting UtsShadeSurface(PositionInputs posInput, UtsBSDFData bsdfData, Pr
|
||||
lighting.specular += rimLightLighting.specular;
|
||||
}
|
||||
#endif
|
||||
|
||||
// lighting.diffuse = sharpShadow;
|
||||
}
|
||||
|
||||
return lighting;
|
||||
|
||||
@@ -37,17 +37,15 @@ float GetHairShadow(PositionInputs posInput, float3 L)
|
||||
if (hairShadowOpacity > 0.0)
|
||||
{
|
||||
float3 viewLightDir = TransformWorldToViewDir(L);
|
||||
float shadowLengthY = _HairShadowDistance * 5.0 * max(0.5, posInput.linearDepth * _HairShadowDistanceScaleFactor) / posInput.linearDepth;
|
||||
float2 shadowLength = float2(shadowLengthY * 2.0f, shadowLengthY);
|
||||
float3 viewOffsetPos = TransformWorldToView(posInput.positionWS) + viewLightDir * _HairShadowDistance * 0.01;
|
||||
float4 clipPos = mul(UNITY_MATRIX_P, float4(viewOffsetPos, 1.0));
|
||||
float2 samplingPointSS = clipPos.xy / clipPos.w;
|
||||
samplingPointSS = samplingPointSS * 0.5 + 0.5;
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
samplingPointSS.y = 1.0 - samplingPointSS.y;
|
||||
#endif
|
||||
|
||||
float3 cameraDirOS = normalize(TransformWorldToObject(GetCameraPositionWS()));
|
||||
float cameraDirFactor = 1.0 - smoothstep(0.1, 0.9, cameraDirOS.y);
|
||||
// shadowLength.y *= cameraDirFactor;
|
||||
|
||||
// TODO: sample point is still shifting when fov change.
|
||||
float2 samplingPoint = (posInput.positionSS + shadowLength * viewLightDir.xy) * _ScreenSize.zw; // Use 1080p as the reference resolution to achieve consistent shadow lengths across various screen resolutions.
|
||||
|
||||
float2 scaledUVs = samplingPoint * _RTHandleScale.xy; // We have to including the scaling factor for our shadow map since we are not going to allocate new texture if the rendering resolution changed.
|
||||
float2 scaledUVs = samplingPointSS * _RTHandleScale.xy; // We have to including the scaling factor for our shadow map since we are not going to allocate new texture if the rendering resolution changed.
|
||||
float hairShadow = SAMPLE_TEXTURE2D_SHADOW(_HairShadowTex, s_linear_clamp_compare_sampler, float3(scaledUVs, posInput.deviceDepth + _HairShadowDepthBias)).r;
|
||||
shadow = lerp(1.0 - hairShadowOpacity, 1.0, hairShadow);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user