Shader code cleanupand bug fix.
This commit is contained in:
@@ -137,7 +137,7 @@ void UtsLightLoop(FragInputs fragInputs, PositionInputs posInput, UtsBSDFData bs
|
||||
|
||||
#ifndef LIGHTLOOP_DISABLE_TILE_AND_CLUSTER
|
||||
GetCountAndStart(posInput, LIGHTCATEGORY_PUNCTUAL, lightStart, lightCount);
|
||||
#else // LIGHTLOOP_DISABLE_TILE_AND_CLUSTER
|
||||
#else
|
||||
lightCount = _PunctualLightCount;
|
||||
lightStart = 0;
|
||||
#endif
|
||||
@@ -374,9 +374,17 @@ void UtsLightLoop(FragInputs fragInputs, PositionInputs posInput, UtsBSDFData bs
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef _LIGHT_BASE_RIM_LIGHT_ON
|
||||
if (HasFlag(bsdfData.surfaceFeatures, SURFACEFEATURE_RIM_LIGHT))
|
||||
{
|
||||
DirectLighting lighting = UtsEvaluateLighting_RimLight(posInput, bsdfData, preLightData);
|
||||
AccumulateDirectLighting(lighting, aggregateLighting);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (HasFlag(bsdfData.surfaceFeatures, SURFACEFEATURE_ANGEL_RING))
|
||||
{
|
||||
DirectLighting lighting = UtsEvaluateAngelRing(fragInputs, bsdfData.normalWS, V);
|
||||
DirectLighting lighting = UtsEvaluateLighting_AngelRing(fragInputs, bsdfData.normalWS, V);
|
||||
AccumulateDirectLighting(lighting, aggregateLighting);
|
||||
}
|
||||
|
||||
|
||||
@@ -159,7 +159,7 @@ DirectLighting UtsShadeSurface(PositionInputs posInput, UtsBSDFData bsdfData, Pr
|
||||
|
||||
float firstColorFeatherForMask = lerp(_1stShadeColorFeather, 0.0, max(_ComposerMaskMode, _FirstShadeOverridden));
|
||||
float baseShadeMask = saturate((halfLambert - (_1stShadeColorStep - firstColorFeatherForMask)) / (_1stShadeColorStep - (_1stShadeColorStep - firstColorFeatherForMask)));
|
||||
baseShadeMask *= shadow;
|
||||
baseShadeMask *= shadow.x;
|
||||
|
||||
float secondColorFeatherForMask = lerp(_2ndShadeColorFeather, 0.0, max(_SecondShadeOverridden, _ComposerMaskMode));
|
||||
float firstShadeMask = saturate((halfLambert - (_2ndShadeColorStep - secondColorFeatherForMask)) / (_2ndShadeColorStep - (_2ndShadeColorStep - secondColorFeatherForMask)));
|
||||
@@ -167,7 +167,7 @@ DirectLighting UtsShadeSurface(PositionInputs posInput, UtsBSDFData bsdfData, Pr
|
||||
diffuseTerm = lerp(lerp(bsdfData.secondShadingDiffuseColor, bsdfData.firstShadingDiffuseColor, firstShadeMask), bsdfData.diffuseColor, baseShadeMask);
|
||||
specularTerm *= baseShadeMask;
|
||||
#elif _SHADING_MODE_SDF
|
||||
float shadeMask = sdfShadowMask * sdfTexture.b * shadow;
|
||||
float shadeMask = sdfShadowMask * sdfTexture.b * shadow.x;
|
||||
|
||||
diffuseTerm = lerp(bsdfData.firstShadingDiffuseColor, bsdfData.diffuseColor, shadeMask);
|
||||
specularTerm = (specularTerm + sdfHighlight) * shadeMask;
|
||||
@@ -177,10 +177,15 @@ DirectLighting UtsShadeSurface(PositionInputs posInput, UtsBSDFData bsdfData, Pr
|
||||
lighting.diffuse += diffuseTerm * lightColor * diffuseDimmer;
|
||||
lighting.specular += specularTerm * lightColor * specularDimmer;
|
||||
|
||||
#if _LIGHT_BASE_RIM_LIGHT_ON
|
||||
if (HasFlag(bsdfData.surfaceFeatures, SURFACEFEATURE_RIM_LIGHT))
|
||||
{
|
||||
lighting.diffuse += UtsEvaluateColor_RimLight(posInput, bsdfData, preLightData, L, lightColor);
|
||||
DirectLighting rimLightLighting = UtsEvaluateLighting_RimLight(posInput, bsdfData, preLightData, L, lightColor);
|
||||
|
||||
lighting.diffuse += rimLightLighting.diffuse;
|
||||
lighting.specular += rimLightLighting.specular;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return lighting;
|
||||
|
||||
@@ -12,6 +12,7 @@ float3 UtsGetShadowNormal(UtsBSDFData bsdfData)
|
||||
|
||||
float3 SampleSDFTexture(float3 L, float2 uv, out float angle)
|
||||
{
|
||||
// TODO: Move sdf sample result to UtsBSDFData to avoid sampleing in a loop
|
||||
float2 right_uv = float2(1 - uv.x, uv.y);
|
||||
float3 left_SDFTex = SAMPLE_TEXTURE2D(_SDFShadingMap, sampler_SDFShadingMap, uv).rgb;
|
||||
float3 right_SDFTex = SAMPLE_TEXTURE2D(_SDFShadingMap, sampler_SDFShadingMap, right_uv).rgb;
|
||||
@@ -35,23 +36,19 @@ float GetHairShadow(PositionInputs posInput, float3 L)
|
||||
|
||||
if (hairShadowOpacity > 0.0)
|
||||
{
|
||||
float3 viewLightDir = TransformWorldToViewDir(L); // / posInput.deviceDepth; when linearDepth grows large, the movement amount should be lower since we are getting further from the face.
|
||||
float3 cameraDirOS = normalize(TransformWorldToObject(GetCameraPositionWS()));
|
||||
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 camDirOS = normalize(TransformWorldToObject(GetCameraPositionWS()));
|
||||
float camDirFactor = 1 - smoothstep(0.1, 0.9, camDirOS.y);
|
||||
shadowLength.y *= camDirFactor;
|
||||
float3 cameraDirOS = normalize(TransformWorldToObject(GetCameraPositionWS()));
|
||||
float cameraDirFactor = 1 - smoothstep(0.1, 0.9, cameraDirOS.y);
|
||||
shadowLength.y *= cameraDirFactor;
|
||||
|
||||
float2 samplingPoint = (posInput.positionSS + shadowLength * viewLightDir.xy * (_ScreenSize.xy / float2(1920.0f, 1080.0f))) * _ScreenSize.zw; // Use 1080p as the reference resolution to achieve consistent shadow lengths across various screen resolutions.
|
||||
|
||||
// Then sample the hair buffer, to see if the fragment lands in shadow.
|
||||
|
||||
float2 scaledUVs = samplingPoint * _HairShadowRTHandleScale.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 hairDepth = SAMPLE_TEXTURE2D(_HairShadowTex, s_linear_clamp_sampler, scaledUVs).r;
|
||||
float shadowMask = posInput.deviceDepth <= hairDepth + _HairShadowDepthBias ? 1 : 0; // Hair < Face means Hair are closer to camera
|
||||
// Note that we have LinearEyeDepth in the buffer. A comparison of depth is needed so that we don't project the shadow of hair behind the face.
|
||||
shadow = lerp(1, 1.0 - hairShadowOpacity, shadowMask);
|
||||
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);
|
||||
}
|
||||
|
||||
return shadow;
|
||||
|
||||
Reference in New Issue
Block a user