Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes sheen intensity #4697

Merged
merged 7 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/graphics/program-lib/chunks/lit/frag/clusteredLight.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,14 +523,14 @@ void evaluateLight(ClusterLightData light) {

#ifdef LIT_CLEARCOAT
#ifdef LIT_SPECULAR_FRESNEL
ccSpecularLight += getLightSpecularCC(halfDir) * dAtten * light.color * dAtten3 * getFresnel(dot(dViewDirW, halfDir), vec3(ccSpecularity));
ccSpecularLight += getLightSpecularCC(halfDir) * dAtten * light.color * dAtten3 * getFresnelCC(dot(dViewDirW, halfDir));
#else
ccSpecularLight += getLightSpecularCC(halfDir) * dAtten * light.color * dAtten3 * vec3(ccSpecularity);
ccSpecularLight += getLightSpecularCC(halfDir) * dAtten * light.color * dAtten3;
#endif
#endif

#ifdef LIT_SHEEN
sSpecularLight += getLightSpecularSheen(halfDir) * dAtten * light.color * dAtten3 * sSpecularity;
sSpecularLight += getLightSpecularSheen(halfDir) * dAtten * light.color * dAtten3;
#endif

#endif
Expand Down
3 changes: 2 additions & 1 deletion src/graphics/program-lib/chunks/lit/frag/combine.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ vec3 combineColor() {
#ifdef LIT_REFLECTIONS
ret += dReflection.rgb * dReflection.a;
#endif

#ifdef LIT_SHEEN
float sheenScaling = 1.0 - max(max(sSpecularity.r, sSpecularity.g), sSpecularity.b) * 0.157;
ret = ret * sheenScaling + sSpecularLight + sReflection.rgb * sReflection.a;
ret = ret * sheenScaling + (sSpecularLight + sReflection.rgb) * sSpecularity;
#endif
#ifdef LIT_CLEARCOAT
float clearCoatScaling = 1.0 - ccFresnel * ccSpecularity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ void addReflectionSheen() {
float a = sGlossiness < 0.25 ? -339.2 * alphaG + 161.4 * sGlossiness - 25.9 : -8.48 * alphaG + 14.3 * sGlossiness - 9.95;
float b = sGlossiness < 0.25 ? 44.0 * alphaG - 23.7 * sGlossiness + 3.26 : 1.97 * alphaG - 3.27 * sGlossiness + 0.72;
float DG = exp( a * NoV + b ) + ( sGlossiness < 0.25 ? 0.0 : 0.1 * ( sGlossiness - 0.25 ) );
sReflection += vec4(calcReflection(dReflDirW, sGlossiness), saturate(DG * 1.0/PI));
sReflection += calcReflection(dNormalW, 0.0) * saturate(DG);
}
`;
11 changes: 5 additions & 6 deletions src/graphics/program-lib/programs/lit-shader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,6 @@ class LitShader {
code += " ccReflection.rgb *= ccFresnel;\n";
} else {
code += " ccFresnel = 0.0;\n";
code += " ccReflection.rgb *= ccSpecularity;\n";
}
}
if (options.useSpecularityFactor) {
Expand All @@ -1051,11 +1050,11 @@ class LitShader {

if (options.sheen) {
code += " addReflectionSheen();\n";
code += " sReflection.rgb *= sSpecularity;\n";
}

// Fresnel has to be applied to reflections
code += " addReflection();\n";

if (options.fresnelModel > 0) {
code += " dReflection.rgb *= getFresnel(dot(dViewDirW, dNormalW), dSpecularity);\n";
} else {
Expand Down Expand Up @@ -1248,18 +1247,18 @@ class LitShader {
if (options.clearCoat) {
code += " ccSpecularLight += getLightSpecularCC(dHalfDirW) * dAtten * light" + i + "_color";
code += usesCookieNow ? " * dAtten3" : "";
code += calcFresnel ? " * getFresnel(dot(dViewDirW, dHalfDirW), vec3(ccSpecularity))" : " * vec3(ccSpecularity)";
code += calcFresnel ? " * getFresnelCC(dot(dViewDirW, dHalfDirW))" : "";
code += ";\n";
}
if (options.sheen) {
code += " sSpecularLight += getLightSpecularSheen(dHalfDirW) * dAtten * light" + i + "_color * sSpecularity";
code += " sSpecularLight += getLightSpecularSheen(dHalfDirW) * dAtten * light" + i + "_color";
code += usesCookieNow ? " * dAtten3" : "";
code += ";\n";
}
if (options.useSpecular) {
code += " dSpecularLight += getLightSpecular(dHalfDirW) * dAtten * light" + i + "_color";
code += usesCookieNow ? " * dAtten3" : "";
code += calcFresnel ? " * getFresnel(dot(dViewDirW, dHalfDirW), dSpecularity)" : " * dSpecularity";
code += calcFresnel ? " * getFresnel(dot(dViewDirW, dHalfDirW), dSpecularity)" : "";
code += ";\n";
}
}
Expand Down Expand Up @@ -1374,7 +1373,7 @@ class LitShader {
if (code.includes("ccSpecularLight")) structCode += "vec3 ccSpecularLight;\n";
if (code.includes("ccSpecularityNoFres")) structCode += "float ccSpecularityNoFres;\n";
if (code.includes("sSpecularLight")) structCode += "vec3 sSpecularLight;\n";
if (code.includes("sReflection")) structCode += "vec4 sReflection;\n";
if (code.includes("sReflection")) structCode += "vec3 sReflection;\n";

const result = this._fsGetBeginCode() +
this.varyings +
Expand Down