Shader code cleanupand bug fix.
This commit is contained in:
@@ -1,28 +1,44 @@
|
||||
#ifndef UTS_SURFACE_FEATURE_EVALUATION
|
||||
#define UTS_SURFACE_FEATURE_EVALUATION
|
||||
|
||||
// Rim light is calculated per light
|
||||
float3 UtsEvaluateColor_RimLight(PositionInputs posInput, UtsBSDFData bsdfData, PreLightData preLightData, float3 L, float3 lightColor)
|
||||
DirectLighting UtsEvaluateLighting_RimLight(PositionInputs posInput, UtsBSDFData bsdfData, PreLightData preLightData
|
||||
#if _LIGHT_BASE_RIM_LIGHT_ON
|
||||
, float3 L, float3 lightColor
|
||||
#endif
|
||||
)
|
||||
{
|
||||
float clampNdotV = ClampNdotV(preLightData.NdotV);
|
||||
float rimLightWeight = 1.0 - clampNdotV;
|
||||
rimLightWeight = pow(rimLightWeight, exp2(lerp(3.0, 0.0, _RimLightLevel)));
|
||||
DirectLighting lighting;
|
||||
ZERO_INITIALIZE(DirectLighting, lighting);
|
||||
|
||||
float3 rimLightColor = _RimLightColor.rgb * _RimLightIntensity;
|
||||
|
||||
#if _SCREEN_SPACE_RIM_LIGHT_ON
|
||||
float3 normalVS = normalize(mul((float3x3)UNITY_MATRIX_V, bsdfData.geomNormalWS));
|
||||
float2 depthUV = posInput.positionNDC.xy + normalVS * (_RimLightLevel * 0.05 / posInput.linearDepth);
|
||||
float2 depthUV = posInput.positionNDC.xy + normalVS.xy * (_RimLightLevel * 0.05 / posInput.linearDepth);
|
||||
float offsetedDepth = SampleCameraDepth(depthUV);
|
||||
float depthDiff = saturate(posInput.deviceDepth - offsetedDepth);
|
||||
|
||||
float rimLightMask = step(0.0025 / posInput.linearDepth, depthDiff);
|
||||
#else
|
||||
float clampNdotV = ClampNdotV(preLightData.NdotV);
|
||||
float rimLightMask = pow(1.0 - clampNdotV, exp2(lerp(3.0, 0.0, _RimLightLevel)));
|
||||
rimLightMask = lerp(rimLightMask, step(_RimLightClippingLevel, rimLightMask), _RimLightClipping);
|
||||
#endif
|
||||
|
||||
#if _LIGHT_BASE_RIM_LIGHT_ON
|
||||
float halfLambert = 0.5 * dot(bsdfData.normalWS, L) + 0.5;
|
||||
//float rimLightMask = lerp(0.5 * lambert + 0.5, saturate(lambert), _Tweak_LightDirection_MaskLevel * 2.0);
|
||||
float rimLightMask = saturate(smoothstep(_Tweak_LightDirection_MaskLevel, 1.0, halfLambert));
|
||||
float lightBaseMask = saturate(smoothstep(_LightDirectionRimLightLevel, 1.0, halfLambert));
|
||||
|
||||
rimLightWeight = step(0.0025 / posInput.linearDepth, depthDiff);
|
||||
float3 outColor = rimLightWeight * lightColor * _RimLightColor * _RimLightStrength;
|
||||
return outColor * rimLightMask;
|
||||
rimLightMask *= lightBaseMask;
|
||||
rimLightColor *= lightColor;
|
||||
#endif
|
||||
|
||||
lighting.diffuse = rimLightMask * rimLightColor;
|
||||
|
||||
return lighting;
|
||||
}
|
||||
|
||||
DirectLighting UtsEvaluateAngelRing(FragInputs input, float3 normalWS, float3 V)
|
||||
DirectLighting UtsEvaluateLighting_AngelRing(FragInputs input, float3 normalWS, float3 V)
|
||||
{
|
||||
DirectLighting lighting;
|
||||
ZERO_INITIALIZE(DirectLighting, lighting);
|
||||
@@ -40,13 +56,13 @@ DirectLighting UtsEvaluateAngelRing(FragInputs input, float3 normalWS, float3 V)
|
||||
|
||||
float2 arOffsetU = lerp(mul(UNITY_MATRIX_V, float4(normalWS, 0)).xyz, float3(0, 0, 1), _AngelRingOffsetU).xy;
|
||||
arOffsetU = arOffsetU * 0.5 + 0.5;
|
||||
float2 arvnRotate = RotateUV(arOffsetU, -(cameraDir * cameraRoll), 0.5, 1.0);
|
||||
float2 arvnRotate = RotateUV(arOffsetU, -(cameraDir * cameraRoll).x, 0.5, 1.0);
|
||||
float2 arOffsetUV = float2(arvnRotate.x, lerp(input.texCoord0.y, arvnRotate.y, _AngelRingOffsetV));
|
||||
float4 angelRingColor = SAMPLE_TEXTURE2D(_AngelRingColorMap, sampler_AngelRingColorMap, TRANSFORM_TEX(arOffsetUV, _AngelRingColorMap)) * _AngelRingColor * _AngelRingIntensity;
|
||||
|
||||
float weight = saturate(dot(normalize(V), normalWS));
|
||||
|
||||
lighting.specular += angelRingColor.r * angelRingColor.a * weight;
|
||||
lighting.specular = angelRingColor.r * angelRingColor.a * weight;
|
||||
|
||||
return lighting;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user