diff --git a/src/renderer.js b/src/renderer.js index 5f7a92cf..7dc193f8 100644 --- a/src/renderer.js +++ b/src/renderer.js @@ -436,6 +436,9 @@ class gltfRenderer case(DebugOutput.WORLDSPACENORMAL): fragDefines.push("DEBUG_WORLDSPACE_NORMAL 1"); break; + case(DebugOutput.GEOMETRYNORMAL): + fragDefines.push("DEBUG_GEOMETRY_NORMAL 1"); + break; case(DebugOutput.TANGENT): fragDefines.push("DEBUG_TANGENT 1"); break; diff --git a/src/rendering_parameters.js b/src/rendering_parameters.js index 904926e5..e47c3e1e 100644 --- a/src/rendering_parameters.js +++ b/src/rendering_parameters.js @@ -50,6 +50,7 @@ const DebugOutput = ROUGHNESS: "Roughness", NORMAL: "Normal", WORLDSPACENORMAL: "Worldspace Normal", + GEOMETRYNORMAL: "Geometry Normal", TANGENT: "Tangent", BITANGENT: "Bitangent", BASECOLOR: "Base Color", diff --git a/src/shaders/pbr.frag b/src/shaders/pbr.frag index 001220c3..c114f9fe 100644 --- a/src/shaders/pbr.frag +++ b/src/shaders/pbr.frag @@ -124,10 +124,12 @@ NormalInfo getNormalInfo(vec3 v) #endif // For a back-facing surface, the tangential basis vectors are negated. - float facing = step(0.0, dot(v, ng)) * 2.0 - 1.0; - t *= facing; - b *= facing; - ng *= facing; + if (gl_FrontFacing == false) + { + t *= -1.0; + b *= -1.0; + ng *= -1.0; + } // Compute pertubed normals: #ifdef HAS_NORMAL_MAP @@ -330,6 +332,13 @@ void main() #endif #endif + float ao = 1.0; + // Apply optional PBR terms for additional (optional) shading +#ifdef HAS_OCCLUSION_MAP + ao = texture(u_OcclusionSampler, getOcclusionUV()).r; + f_diffuse = mix(f_diffuse, f_diffuse * ao, u_OcclusionStrength); +#endif + #ifdef USE_PUNCTUAL for (int i = 0; i < LIGHT_COUNT; ++i) { @@ -406,13 +415,6 @@ void main() color = (f_emissive + f_diffuse + f_specular + (1.0 - reflectance) * f_sheen) * (1.0 - clearcoatFactor * clearcoatFresnel) + f_clearcoat * clearcoatFactor; - float ao = 1.0; - // Apply optional PBR terms for additional (optional) shading -#ifdef HAS_OCCLUSION_MAP - ao = texture(u_OcclusionSampler, getOcclusionUV()).r; - color = mix(color, color * ao, u_OcclusionStrength); -#endif - #ifndef DEBUG_OUTPUT // no debug #ifdef ALPHAMODE_MASK @@ -445,8 +447,12 @@ void main() #endif #endif + #ifdef DEBUG_GEOMETRY_NORMAL + g_finalColor.rgb = (normalInfo.ng + 1.0) / 2.0; + #endif + #ifdef DEBUG_WORLDSPACE_NORMAL - g_finalColor.rgb = (n + 1.0) / 2.0; + g_finalColor.rgb = (n + 1.0) / 2.0; #endif #ifdef DEBUG_TANGENT