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

ShaderChunk: Bring gl_FrontFacing back #21205

Merged
merged 1 commit into from
Feb 4, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions src/renderers/shaders/ShaderChunk/normal_fragment_begin.glsl.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default /* glsl */`
float faceDirection = 1.0;
float faceDirection = float( gl_FrontFacing ) * 2.0 - 1.0;

#ifdef FLAT_SHADED

Expand All @@ -9,24 +9,12 @@ float faceDirection = 1.0;
vec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );
vec3 normal = normalize( cross( fdx, fdy ) );

faceDirection = sign( dot( vec3( 0, 0, 1 ), normal ) );

#else

vec3 normal = normalize( vNormal );

#ifdef DOUBLE_SIDED

// Workaround for Adreno GPUs not 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 ) );

// Workaround for Adreno GPUs broken gl_FrontFacing implementation
// https://stackoverflow.com/a/32621243

faceDirection = sign( dot( normal, normalize( cross( fdx, fdy ) ) ) );

normal = normal * faceDirection;

#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ export default /* glsl */`

#ifdef DOUBLE_SIDED

// We can't compute faceDirection if the model doesn't have normals

normal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );
normal = normal * faceDirection;

#endif

Expand Down