Skip to content

Commit

Permalink
fix(pbr): fix mlp flicker and wrong coat color, convert additional co…
Browse files Browse the repository at this point in the history
…lor maps like albedo (#967)

* fix(pbr): fix mlp flicker

* style: 🎨 apply clang-format changes

* Update Lighting.hlsl

* style: 🎨 apply clang-format changes

---------

Co-authored-by: ThePagi <[email protected]>
  • Loading branch information
ThePagi and ThePagi authored Feb 16, 2025
1 parent cabefab commit de45037
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions package/Shaders/Lighting.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,12 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace

# if defined(TRUE_PBR) && !defined(LANDSCAPE) && !defined(LODLANDSCAPE)
bool PBRParallax = false;
float4 sampledCoatProperties = PBRParams2;
[branch] if ((PBRFlags & PBR::Flags::HasFeatureTexture0) != 0)
{
sampledCoatProperties = TexRimSoftLightWorldMapOverlaySampler.Sample(SampRimSoftLightWorldMapOverlaySampler, uv);
sampledCoatProperties.rgb = Color::Diffuse(sampledCoatProperties.rgb);
}
[branch] if (SharedData::extendedMaterialSettings.EnableParallax && (PBRFlags & PBR::Flags::HasDisplacement) != 0)
{
PBRParallax = true;
Expand All @@ -1177,7 +1183,8 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
displacementParams.HeightScale = PBRParams1.y;
displacementParams.DisplacementScale = 0.5;
displacementParams.DisplacementOffset = -0.25;
eta = (1 - sqrt(MultiLayerParallaxData.y)) / (1 + sqrt(MultiLayerParallaxData.y));

eta = lerp(1.0, (1 - sqrt(MultiLayerParallaxData.y)) / (1 + sqrt(MultiLayerParallaxData.y)), sampledCoatProperties.w);
[branch] if ((PBRFlags & PBR::Flags::CoatNormal) != 0)
{
entryNormalTS = normalize(TransformNormal(TexBackLightSampler.Sample(SampBackLightSampler, uvOriginal).xyz));
Expand All @@ -1188,7 +1195,9 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
}
entryNormal = normalize(mul(tbn, entryNormalTS));
refractedViewDirection = -refract(-viewDirection, entryNormal, eta);
refractedViewDirectionWS = normalize(mul(input.World[eyeIndex], float4(refractedViewDirection, 0)));
[flatten] if (!input.WorldSpace)
refractedViewDirectionWS = normalize(mul(input.World[eyeIndex], float4(refractedViewDirection, 0)));
else refractedViewDirectionWS = refractedViewDirection;
}
else
{
Expand Down Expand Up @@ -1712,15 +1721,15 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
[branch] if ((PBRFlags & PBR::Flags::HasFeatureTexture0) != 0)
{
float4 sampledSubsurfaceProperties = TexRimSoftLightWorldMapOverlaySampler.Sample(SampRimSoftLightWorldMapOverlaySampler, uv);
pbrSurfaceProperties.SubsurfaceColor *= sampledSubsurfaceProperties.xyz;
pbrSurfaceProperties.SubsurfaceColor *= Color::Diffuse(sampledSubsurfaceProperties.xyz);
pbrSurfaceProperties.Thickness *= sampledSubsurfaceProperties.w;
}
pbrSurfaceProperties.Thickness = lerp(pbrSurfaceProperties.Thickness, 1, projectedMaterialWeight);
}
else if ((PBRFlags & PBR::Flags::TwoLayer) != 0)
{
pbrSurfaceProperties.CoatColor = PBRParams2.xyz;
pbrSurfaceProperties.CoatStrength = PBRParams2.w;
pbrSurfaceProperties.CoatColor = sampledCoatProperties.xyz;
pbrSurfaceProperties.CoatStrength = sampledCoatProperties.w;
pbrSurfaceProperties.CoatRoughness = MultiLayerParallaxData.x;
pbrSurfaceProperties.CoatF0 = MultiLayerParallaxData.y;

Expand All @@ -1729,12 +1738,6 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
{
coatUv = uvOriginal;
}
[branch] if ((PBRFlags & PBR::Flags::HasFeatureTexture0) != 0)
{
float4 sampledCoatProperties = TexRimSoftLightWorldMapOverlaySampler.Sample(SampRimSoftLightWorldMapOverlaySampler, coatUv);
pbrSurfaceProperties.CoatColor *= sampledCoatProperties.xyz;
pbrSurfaceProperties.CoatStrength *= sampledCoatProperties.w;
}
[branch] if ((PBRFlags & PBR::Flags::HasFeatureTexture1) != 0)
{
float4 sampledCoatProperties = TexBackLightSampler.Sample(SampBackLightSampler, coatUv);
Expand All @@ -1761,7 +1764,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
[branch] if ((PBRFlags & PBR::Flags::HasFeatureTexture1) != 0)
{
float4 sampledFuzzProperties = TexBackLightSampler.Sample(SampBackLightSampler, uv);
pbrSurfaceProperties.FuzzColor *= sampledFuzzProperties.xyz;
pbrSurfaceProperties.FuzzColor *= Color::Diffuse(sampledFuzzProperties.xyz);
pbrSurfaceProperties.FuzzWeight *= sampledFuzzProperties.w;
}
pbrSurfaceProperties.FuzzWeight = lerp(pbrSurfaceProperties.FuzzWeight, 0, projectedMaterialWeight);
Expand Down Expand Up @@ -2271,7 +2274,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
# endif
[branch] if (hasEmissive)
{
float3 glowColor = TexGlowSampler.Sample(SampGlowSampler, uv).xyz;
float3 glowColor = Color::Diffuse(TexGlowSampler.Sample(SampGlowSampler, uv).xyz);
emitColor *= glowColor;
}
# endif
Expand Down

0 comments on commit de45037

Please sign in to comment.