Shader code cleanup;
Added punctual light evaluation in light loop;
This commit is contained in:
@@ -9,7 +9,9 @@
|
||||
#define SATURATE_BASE_COLOR_IF_SDR(x) saturate(x)
|
||||
#endif
|
||||
|
||||
#define APPLY_WEIGHT(x, y, t) lerp(x, x * y, t)
|
||||
const float rateR = 0.299;
|
||||
const float rateG = 0.587;
|
||||
const float rateB = 0.114;
|
||||
|
||||
struct UTSLightData
|
||||
{
|
||||
@@ -22,7 +24,7 @@ struct UTSLightData
|
||||
SHADOW_TYPE shadowValue;
|
||||
};
|
||||
|
||||
float GetLightAttenuation(float3 lightColor)
|
||||
float GetColorAttenuation(float3 lightColor)
|
||||
{
|
||||
float lightAttenuation = rateR * lightColor.r + rateG * lightColor.g + rateB * lightColor.b;
|
||||
return lightAttenuation;
|
||||
@@ -36,41 +38,58 @@ float3 GetLimitedLightColor(float3 lightColor)
|
||||
return result;
|
||||
}
|
||||
|
||||
DirectLighting UtsEvaluateShading_Directional(LightLoopContext lightLoopContext, PositionInputs posInput, BuiltinData builtinData, DirectionalLightData lightData, UtsBSDFData bsdfData, PreLightData preLightData, float3 V)
|
||||
DirectLighting UtsEvaluateBSDF_Directional(LightLoopContext lightLoopContext, PositionInputs posInput, BuiltinData builtinData, DirectionalLightData lightData, UtsBSDFData bsdfData, PreLightData preLightData, float3 V, float2 uv0)
|
||||
{
|
||||
DirectLighting lighting;
|
||||
ZERO_INITIALIZE(DirectLighting, lighting);
|
||||
|
||||
float3 L = -lightData.forward;
|
||||
float NdotL = dot(bsdfData.normalWS, L);
|
||||
float halfLambert = 0.5 * NdotL + 0.5;
|
||||
|
||||
SHADOW_TYPE shadow = EvaluateShadow_Directional(lightLoopContext, posInput, lightData, builtinData, bsdfData.normalWS);
|
||||
float systemShadows = saturate(shadow + 0.5f + _Tweak_SystemShadowsLevel > 0.0 ? shadow + 0.5f + _Tweak_SystemShadowsLevel : 0.0);
|
||||
float shadingGrade = lerp(halfLambert, halfLambert * systemShadows, _Set_SystemShadowsToBase);
|
||||
float firstColorFeatherForMask = lerp(_1st_ShadeColor_Feather, 0.0f, max(_ComposerMaskMode, _FirstShadeOverridden));
|
||||
SHADOW_TYPE shadow = EvaluateShadow_Directional(lightLoopContext, posInput, lightData, builtinData, bsdfData.geomNormalWS);
|
||||
|
||||
float finalShadow = saturate((shadingGrade - (_1st_ShadeColor_Step - firstColorFeatherForMask)) / (_1st_ShadeColor_Step - (_1st_ShadeColor_Step - firstColorFeatherForMask))); // Base and 1st Shade Mask
|
||||
|
||||
if (lightData.diffuseDimmer > 0.0 && finalShadow > 0.0)
|
||||
if (lightData.lightDimmer > 0.0)
|
||||
{
|
||||
float secondColorFeatherForMask = lerp(_2nd_ShadeColor_Feather, 0.0f, max(_SecondShadeOverridden, _ComposerMaskMode));
|
||||
float shadeShadow = saturate((halfLambert - (_ShadeColor_Step - secondColorFeatherForMask)) / (_ShadeColor_Step - (_ShadeColor_Step - secondColorFeatherForMask))); // 1st and 2nd Shades Mask
|
||||
|
||||
float3 diffuseTerm = lerp(lerp(bsdfData.secondShadingDiffuseColor, bsdfData.firstShadingDiffuseColor, shadeShadow), bsdfData.diffuseColor, finalShadow);
|
||||
float3 specularTerm = ComputeSpecularTerm(bsdfData, preLightData, V, L) * finalShadow;
|
||||
|
||||
// TODO: Colored shadow will overwrite the first and second shading diffuse color
|
||||
//float3 shadowColor = ComputeShadowColor(shadow, lightData.shadowTint, lightData.penumbraTint);
|
||||
float4 lightColor = EvaluateLight_Directional(lightLoopContext, posInput, lightData);
|
||||
lightColor.rgb *= ComputeShadowColor(systemShadows, lightData.shadowTint, lightData.penumbraTint) * lightColor.a * _Light_Intensity_Multiplier;
|
||||
lightColor.rgb = GetLimitedLightColor(lightColor.rgb);
|
||||
lightColor.rgb = GetLimitedLightColor(lightColor.rgb * lightColor.a * _Light_Intensity_Multiplier);
|
||||
|
||||
lighting.diffuse = diffuseTerm * lightColor.rgb * lightData.diffuseDimmer;
|
||||
lighting.specular += specularTerm * lightColor.rgb * lightData.specularDimmer;
|
||||
UtsClampRoughness(preLightData, bsdfData, lightData.minRoughness);
|
||||
|
||||
lighting = UtsShadeSurface(bsdfData, preLightData, shadow, lightColor.rgb, V, L, uv0, lightData.diffuseDimmer, lightData.specularDimmer);
|
||||
}
|
||||
|
||||
return lighting;
|
||||
}
|
||||
|
||||
DirectLighting UtsEvaluateBSDF_Punctual(LightLoopContext lightLoopContext, PositionInputs posInput, BuiltinData builtinData, LightData lightData, UtsBSDFData bsdfData, PreLightData preLightData, float3 V, float2 uv0)
|
||||
{
|
||||
DirectLighting lighting;
|
||||
ZERO_INITIALIZE(DirectLighting, lighting);
|
||||
|
||||
float3 L;
|
||||
float4 distances; // {d, d^2, 1/d, d_proj}
|
||||
GetPunctualLightVectors(posInput.positionWS, lightData, L, distances);
|
||||
|
||||
PositionInputs shadowPositionInputs = posInput;
|
||||
shadowPositionInputs.positionWS = posInput.positionWS + L * _ShadowBias;
|
||||
|
||||
SHADOW_TYPE shadow = EvaluateShadow_Punctual(lightLoopContext, shadowPositionInputs, lightData, builtinData, bsdfData.geomNormalWS, L, distances);
|
||||
|
||||
if (lightData.lightDimmer > 0.0)
|
||||
{
|
||||
// TODO: Colored shadow will overwrite the first and second shading diffuse color
|
||||
//float3 shadowColor = ComputeShadowColor(shadow, lightData.shadowTint, lightData.penumbraTint);
|
||||
float4 lightColor = EvaluateLight_Punctual(lightLoopContext, posInput, lightData, L, distances);
|
||||
lightColor.rgb = GetLimitedLightColor(lightColor.rgb * lightColor.a * _Light_Intensity_Multiplier);
|
||||
|
||||
UtsClampRoughness(preLightData, bsdfData, lightData.minRoughness);
|
||||
|
||||
lighting = UtsShadeSurface(bsdfData, preLightData, shadow, lightColor.rgb, V, L, uv0, lightData.diffuseDimmer, lightData.specularDimmer);
|
||||
}
|
||||
|
||||
return lighting;
|
||||
}
|
||||
|
||||
IndirectLighting UtsEvaluateBSDF_ScreenSpaceReflection(PositionInputs posInput, PreLightData preLightData, inout float reflectionHierarchyWeight)
|
||||
{
|
||||
IndirectLighting lighting;
|
||||
|
||||
Reference in New Issue
Block a user