Skip to content

Commit

Permalink
faceDirection
Browse files Browse the repository at this point in the history
  • Loading branch information
sunag committed Sep 30, 2019
1 parent 70140b7 commit 29f6248
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
30 changes: 25 additions & 5 deletions src/renderers/shaders/ShaderChunk/normal_fragment_begin.glsl.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
export default /* glsl */`
#ifdef FLAT_SHADED
// Workaround for Adreno/Nexus5 not able able to do dFdx( vViewPosition ) ...
// Workaround for Adreno/Nexus5 not able able to do dFdx( vViewPosition ) ...
vec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );
vec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );
vec3 faceNormal = normalize( cross( fdx, fdy ) );
#ifdef FLAT_SHADED
vec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );
vec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );
vec3 normal = normalize( cross( fdx, fdy ) );
vec3 normal = faceNormal;
#else
Expand Down Expand Up @@ -37,4 +40,21 @@ export default /* glsl */`
vec3 geometryNormal = normal;
#ifdef DOUBLE_SIDED
// Workaround for Adreno GPUs gl_FrontFacing bug. See #15850 and #10331
float faceDirection = dot (vViewPosition, faceNormal) > 0. ? 1. : -1.;
//float faceDirection = gl_FrontFacing ? 1. : -1.;
#elif FLIP_SIDED
float faceDirection = -1.;
#else
float faceDirection = 1.;
#endif
`;
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default /* glsl */`
#else
normal = perturbNormal2Arb( -vViewPosition, normal, normalScale, normalMap );
normal = perturbNormal2Arb( -vViewPosition, normal, normalScale * faceDirection, normalMap );
#endif
Expand Down
14 changes: 0 additions & 14 deletions src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,6 @@ export default /* glsl */`
mapN.xy *= normalScale;
#ifdef DOUBLE_SIDED
// Workaround for Adreno GPUs gl_FrontFacing bug. See #15850 and #10331
bool frontFacing = dot( cross( S, T ), N ) > 0.0;
mapN.xy *= ( float( frontFacing ) * 2.0 - 1.0 );
#else
mapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );
#endif
mat3 tsn = mat3( S, T, N );
return normalize( tsn * mapN );
Expand Down

0 comments on commit 29f6248

Please sign in to comment.