Skip to content

Commit

Permalink
Merge pull request #4 from ux3d/fix/edge_bug
Browse files Browse the repository at this point in the history
Fix/edge bug
  • Loading branch information
UX3D-haertl authored Nov 5, 2020
2 parents de6f6b4 + a6ec8b4 commit a74701a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/rendering_parameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const DebugOutput =
ROUGHNESS: "Roughness",
NORMAL: "Normal",
WORLDSPACENORMAL: "Worldspace Normal",
GEOMETRYNORMAL: "Geometry Normal",
TANGENT: "Tangent",
BITANGENT: "Bitangent",
BASECOLOR: "Base Color",
Expand Down
16 changes: 11 additions & 5 deletions src/shaders/pbr.frag
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,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;
}

// Due to anisoptry, the tangent can be further rotated around the geometric normal.
vec3 direction;
Expand Down Expand Up @@ -684,8 +686,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
Expand Down

0 comments on commit a74701a

Please sign in to comment.