Added new Shadow SSS Lut;

Fixed the issue that SSGI and SSAO weight not works properly;
This commit is contained in:
2025-03-17 00:02:46 +09:00
parent b2136e1ff4
commit ee0b720b6d
7 changed files with 126 additions and 58 deletions

View File

@@ -124,41 +124,39 @@ void UtsEvaluateBSDF_BakeDiffuse(PositionInputs posInput, PreLightData preLightD
lightInReflDir = float3(-1, -1, -1); // This variable is used with APV for reflection probe normalization - see code for LIGHTFEATUREFLAGS_ENV
#endif
#if defined(_PBR_MODE_OFF) || defined(_PBR_MODE_TOON)
float3 normalWS = float3(0.0, 0.0, 1.0);
#else
float3 normalWS = bsdfData.normalWS;
#endif
float3 backNormalWS = -normalWS;
// Reflect normal to get lighting for reflection probe tinting
float3 R = reflect(-V, normalWS);
#if defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2)
if (_EnableProbeVolumes)
{
EvaluateAdaptiveProbeVolume(GetAbsolutePositionWS(posInput.positionWS),
normalWS, -backNormalWS,
R, V,
posInput.positionSS, builtinData.renderingLayers,
builtinData.bakeDiffuseLighting, builtinData.backBakeDiffuseLighting, lightInReflDir);
}
else // If probe volume is disabled we fallback on the ambient probes
{
builtinData.bakeDiffuseLighting = EvaluateAmbientProbe(normalWS);
builtinData.backBakeDiffuseLighting = EvaluateAmbientProbe(backNormalWS);
}
#endif
#if !defined(_SURFACE_TYPE_TRANSPARENT) && !defined(SCREEN_SPACE_INDIRECT_DIFFUSE_DISABLED)
if (_IndirectDiffuseMode != INDIRECTDIFFUSEMODE_OFF)
{
float3 ssgiLighting = LOAD_TEXTURE2D_X(_IndirectDiffuseTexture, posInput.positionSS).xyz * GetInverseCurrentExposureMultiplier();
builtinData.bakeDiffuseLighting = lerp(builtinData.bakeDiffuseLighting, ssgiLighting.rgb, _SSGIWeight);
}
else
#endif
{
#if defined(_PBR_MODE_OFF) || defined(_PBR_MODE_TOON)
float3 normalWS = float3(0.0, 0.0, 1.0);
#else
float3 normalWS = bsdfData.normalWS;
#endif
float3 backNormalWS = -normalWS;
#if defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2)
if (_EnableProbeVolumes)
{
// Reflect normal to get lighting for reflection probe tinting
float3 R = reflect(-V, bsdfData.normalWS);
EvaluateAdaptiveProbeVolume(GetAbsolutePositionWS(posInput.positionWS),
bsdfData.normalWS, -bsdfData.normalWS,
R, V,
posInput.positionSS, builtinData.renderingLayers,
builtinData.bakeDiffuseLighting, builtinData.backBakeDiffuseLighting, lightInReflDir);
}
else // If probe volume is disabled we fallback on the ambient probes
{
builtinData.bakeDiffuseLighting = EvaluateAmbientProbe(normalWS);
builtinData.backBakeDiffuseLighting = EvaluateAmbientProbe(backNormalWS);
}
#endif
}
}
void UtsEvaluateBSDF_MatCapDiffuse(float3 positionWS, float3 normalWS, inout BuiltinData builtinData)
@@ -262,7 +260,7 @@ void AdjustIndirectLighting(PreLightData preLightData, UtsBSDFData bsdfData, ino
void UtsPostEvaluateBSDF(PositionInputs posInput, PreLightData preLightData, UtsBSDFData bsdfData, BuiltinData builtinData, AggregateLighting lighting, out LightLoopOutput lightLoopOutput)
{
#if !defined(_INDIRECT_DIFFUSE_MODE_OFF) && !defined(_INDIRECT_SPECULAR_MODE_OFF)
#if !defined(_INDIRECT_DIFFUSE_MODE_OFF) || !defined(_INDIRECT_SPECULAR_MODE_OFF)
AmbientOcclusionFactor aoFactor;
GetScreenSpaceAmbientOcclusionMultibounce(posInput.positionSS, preLightData.NdotV, bsdfData.perceptualRoughness, bsdfData.ambientOcclusion, bsdfData.specularOcclusion, bsdfData.diffuseColor, bsdfData.fresnel0, aoFactor);
ApplyAmbientOcclusion(aoFactor, builtinData, lighting);

View File

@@ -258,25 +258,24 @@ void UtsLightLoop(FragInputs fragInputs, PositionInputs posInput, UtsBSDFData bs
{
replaceBakeDiffuseLighting = true;
}
#endif
#endif
#if defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2)
#if defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2)
if (!builtinData.isLightmap)
{
replaceBakeDiffuseLighting = true;
}
#endif
#endif
#if defined(LIGHT_EVALUATION_SKIP_INDIRECT_DIFFUSE)
#if defined(LIGHT_EVALUATION_SKIP_INDIRECT_DIFFUSE)
replaceBakeDiffuseLighting = false;
#endif
#endif
if (replaceBakeDiffuseLighting)
{
UtsEvaluateBSDF_BakeDiffuse(posInput, preLightData, bsdfData, V, builtinData, lightInReflDir);
}
#elif _INDIRECT_DIFFUSE_MODE_MATCAP
//builtinData.bakeDiffuseLighting = UtsEvaluateColor_MatCap(posInput.positionWS, bsdfData.normalWS, 0.0);
UtsEvaluateBSDF_MatCapDiffuse(posInput.positionWS, bsdfData.normalWS, builtinData);
#elif _INDIRECT_DIFFUSE_MODE_RAMP
UtsEvaluateBSDF_Ramp(posInput, bsdfData, builtinData);

View File

@@ -5,12 +5,6 @@
#include "Packages/com.misaki.hdrp-toon/Runtime/Shaders/Includes/Lighting/UtsShadowEvaluation.hlsl"
struct UtsShadeMask
{
float baseShadeMask;
float firstShadeMask;
};
float RoughnessToBlinnPhongSpecularExponent(float roughness)
{
return clamp(2 * rcp(roughness * roughness) - 2, FLT_EPS, rcp(FLT_EPS));
@@ -122,9 +116,9 @@ DirectLighting UtsShadeSurface(PositionInputs posInput, UtsBSDFData bsdfData, Pr
if (Max3(lightColor.r, lightColor.g, lightColor.b) > 0.0)
{
shadow = smoothstep(0.4, 0.6, shadow);
SHADOW_TYPE sharpShadow = smoothstep(0.4, 0.6, shadow);
#if _RECEIVE_HAIR_SHADOW_ON && ENABLE_UTS_HAIR_SHAOW
shadow *= GetHairShadow(posInput, L);
sharpShadow *= GetHairShadow(posInput, L);
#endif
#if _SHADING_MODE_SDF
@@ -142,15 +136,16 @@ DirectLighting UtsShadeSurface(PositionInputs posInput, UtsBSDFData bsdfData, Pr
float NdotL = dot(bsdfData.normalWS, L);
float halfLambert = 0.5 * NdotL + 0.5;
float3 rampColor = SAMPLE_TEXTURE2D_ARRAY_LOD(_ShadingRampMap, s_linear_clamp_sampler, float2(halfLambert * shadow.x, 0.0), _ShadingIndex, 0.0).rgb;
float3 rampColor = SAMPLE_TEXTURE2D_ARRAY_LOD(_ShadingRampMap, s_linear_clamp_sampler, float2(halfLambert * shadow.x, 1.0), _ShadingIndex, 0.0).rgb;
//float3 rampColor = SAMPLE_TEXTURE2D_ARRAY_LOD(_ShadingRampMap, s_linear_clamp_sampler, float2(shadow.x, 1.0), _ShadingIndex, 0.0).rgb;
diffuseTerm = bsdfData.diffuseColor * rampColor;
specularTerm *= saturate(NdotL) * shadow;
specularTerm *= saturate(NdotL) * sharpShadow;
#elif _SHADING_MODE_SDF
float3 rampColor = SAMPLE_TEXTURE2D_ARRAY_LOD(_ShadingRampMap, s_linear_clamp_sampler, float2(sdfShadowMask * shadow.x, 0.0), _ShadingIndex, 0.0).rgb;
float3 rampColor = SAMPLE_TEXTURE2D_ARRAY_LOD(_ShadingRampMap, s_linear_clamp_sampler, float2(sdfShadowMask * sharpShadow.x, 1.0), _ShadingIndex, 0.0).rgb;
diffuseTerm = bsdfData.diffuseColor * rampColor;
specularTerm = (specularTerm + sdfHighlight) * sdfShadowMask * shadow;
specularTerm = (specularTerm + sdfHighlight) * sdfShadowMask * sharpShadow;
#endif
#else
#if _SHADING_MODE_STANDARD
@@ -159,7 +154,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.x;
baseShadeMask *= sharpShadow.x;
float secondColorFeatherForMask = lerp(_2ndShadeColorFeather, 0.0, max(_SecondShadeOverridden, _ComposerMaskMode));
float firstShadeMask = saturate((halfLambert - (_2ndShadeColorStep - secondColorFeatherForMask)) / (_2ndShadeColorStep - (_2ndShadeColorStep - secondColorFeatherForMask)));
@@ -167,7 +162,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.x;
float shadeMask = sdfShadowMask * sdfTexture.b * sharpShadow.x;
diffuseTerm = lerp(bsdfData.firstShadingDiffuseColor, bsdfData.diffuseColor, shadeMask);
specularTerm = (specularTerm + sdfHighlight) * shadeMask;