Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions package/Shaders/Common/PBR.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,22 @@ namespace PBR
else
#endif
{
lightingOutput.diffuse += detailedLightColor * satNdotL * BRDF::Diffuse_Lambert();

float3 F;
#if defined(GLINT)
lightingOutput.specular += GetSpecularDirectLightMultiplierMicrofacetWithGlint(material.Noise, material.Roughness, material.F0, satNdotL, satNdotV, satNdotH, satVdotH, mul(tbnTr, H).x,
material.GlintLogMicrofacetDensity, material.GlintMicrofacetRoughness, material.GlintDensityRandomization, material.GlintCache, F) *
detailedLightColor * satNdotL;
float3 specular = GetSpecularDirectLightMultiplierMicrofacetWithGlint(material.Noise, material.Roughness, material.F0, satNdotL, satNdotV, satNdotH, satVdotH, mul(tbnTr, H).x,
material.GlintLogMicrofacetDensity, material.GlintMicrofacetRoughness, material.GlintDensityRandomization, material.GlintCache, F);
#else
lightingOutput.specular += GetSpecularDirectLightMultiplierMicrofacet(material.Roughness, material.F0, satNdotL, satNdotV, satNdotH, satVdotH, F) * detailedLightColor * satNdotL;
float3 specular = GetSpecularDirectLightMultiplierMicrofacet(material.Roughness, material.F0, satNdotL, satNdotV, satNdotH, satVdotH, F);
#endif
float3 kD = 1 - F;

lightingOutput.diffuse += detailedLightColor * satNdotL * BRDF::Diffuse_Lambert() * kD;
lightingOutput.specular += specular * detailedLightColor * satNdotL;

#if !defined(LANDSCAPE) && !defined(LODLANDSCAPE)
[branch] if ((PBRFlags & Flags::Fuzz) != 0)
{
float3 fuzzSpecular = GetSpecularDirectLightMultiplierMicroflakes(material.Roughness, material.FuzzColor, satNdotL, satNdotV, satNdotH, satVdotH) * context.lightColor * satNdotL;
float3 fuzzSpecular = GetSpecularDirectLightMultiplierMicroflakes(material.Roughness, material.FuzzColor, satNdotL, satNdotV, satNdotH, satVdotH) * detailedLightColor * satNdotL;
lightingOutput.specular = lerp(lightingOutput.specular, fuzzSpecular, material.FuzzWeight);
}

Expand All @@ -176,7 +177,7 @@ namespace PBR
float forwardScatter = exp2(saturate(-VdotL) * subsurfacePower - subsurfacePower);
float backScatter = saturate(satNdotL * material.Thickness + (1.0 - material.Thickness)) * 0.5;
float subsurface = lerp(backScatter, 1, forwardScatter) * (1.0 - material.Thickness);
lightingOutput.transmission += material.SubsurfaceColor * subsurface * softLightColor * BRDF::Diffuse_Lambert();
lightingOutput.transmission += material.SubsurfaceColor * subsurface * softLightColor * BRDF::Diffuse_Lambert() * kD;
}
else if ((PBRFlags & Flags::TwoLayer) != 0)
{
Expand Down Expand Up @@ -241,27 +242,25 @@ namespace PBR
float2 specularBRDF = BRDF::EnvBRDF(material.Roughness, NdotV);
lobeWeights.specular = material.F0 * specularBRDF.x + specularBRDF.y;

float3 F = BRDF::F_Schlick(material.F0, NdotV);
lobeWeights.diffuse *= 1 - F;
float3 kD = 1 - lobeWeights.specular;
lobeWeights.diffuse *= kD;

#if !defined(LANDSCAPE) && !defined(LODLANDSCAPE)
[branch] if ((PBRFlags & Flags::TwoLayer) != 0)
{
float2 coatSpecularBRDF = BRDF::EnvBRDF(material.CoatRoughness, NdotV);
float3 coatSpecularLobeWeight = material.CoatF0 * coatSpecularBRDF.x + coatSpecularBRDF.y;
float3 coatSpecularLobeSpecular = material.CoatF0 * coatSpecularBRDF.x + coatSpecularBRDF.y;

float3 coatF = BRDF::F_Schlick(material.CoatF0, NdotV);

float3 layerAttenuation = 1 - coatF * material.CoatStrength;
float3 layerAttenuation = 1 - coatSpecularLobeSpecular * material.CoatStrength;
lobeWeights.diffuse *= layerAttenuation;
lobeWeights.specular *= layerAttenuation;

[branch] if ((PBRFlags & Flags::ColoredCoat) != 0)
{
float3 coatDiffuseLobeWeight = material.CoatColor * (1 - coatSpecularLobeWeight);
float3 coatDiffuseLobeWeight = material.CoatColor * (1 - coatSpecularLobeSpecular);
lobeWeights.diffuse += coatDiffuseLobeWeight * material.CoatStrength;
}
lobeWeights.specular += coatSpecularLobeWeight * material.CoatStrength;
lobeWeights.specular += coatSpecularLobeSpecular * material.CoatStrength;
}
#endif
}
Expand Down
Loading