Skip to content

Commit

Permalink
Merge pull request #8 from ux3d/release/bugfixes
Browse files Browse the repository at this point in the history
Release/bugfixes
  • Loading branch information
UX3D-becher authored Nov 5, 2020
2 parents d1125b5 + a74701a commit e21a986
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 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
30 changes: 18 additions & 12 deletions src/shaders/pbr.frag
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e21a986

Please sign in to comment.