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

NormalMap Shader: prevent branching #17598

Merged
merged 1 commit into from
Sep 27, 2019
Merged

Conversation

WestLangley
Copy link
Collaborator

As proposed in #17586 (comment).

/ping @JordyvanDortmont
/ping @sunag

@mrdoob mrdoob added this to the r109 milestone Sep 27, 2019
@mrdoob mrdoob merged commit 6aa577c into mrdoob:dev Sep 27, 2019
@mrdoob
Copy link
Owner

mrdoob commented Sep 27, 2019

Thanks!

@WestLangley WestLangley deleted the dev_frontfacing branch September 27, 2019 22:56
@sunag
Copy link
Collaborator

sunag commented Sep 29, 2019

@WestLangley Is possible find a way to turn frontFacing a global constant in shader?

#ifdef FRONT_SIDE
bool frontFacing = 1.0;
#elif BACK_SIDED
bool frontFacing = -1.0;
#elif DOUBLE_SIDED
bool frontFacing = dot( cross( S, T ), N ) > 0.0 ? 1.0 : -1.0;
#endif

Thus it can be used in other functions like bump map:

fDet *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );

@sunag
Copy link
Collaborator

sunag commented Sep 30, 2019

@WestLangley Is possible find a way to turn frontFacing a global constant in shader?

Seems that is was implemented in
https://makc3d.wordpress.com/2015/09/17/alternative-to-gl_frontfacing/
http://jsfiddle.net/8sgdaknm/7/

I think that a face direction (target *= faceDir(-1 or 1), is better that target *= float( boolean ) * 2.0 - 1.0 approach.

@mrdoob
Copy link
Owner

mrdoob commented Sep 30, 2019

I think that a face direction (target *= faceDir(-1 or 1), is better that target *= float( boolean ) * 2.0 - 1.0 approach.

Why?

@WestLangley
Copy link
Collaborator Author

Is possible find a way to turn frontFacing a global constant in shader?
#elif DOUBLE_SIDED
bool frontFacing = dot( cross( S, T ), N ) > 0.0 ? 1.0 : -1.0;

We already have access to gl_FrontFacing.

Also, dot( cross( S, T ), N ) is a temporary work-around and a hack.

@sunag
Copy link
Collaborator

sunag commented Sep 30, 2019

I am creating a PR for show better the idea.
29f6248

@sunag
Copy link
Collaborator

sunag commented Sep 30, 2019

@mrdoob is about to use this approach:
sunag@3b73f1c

@mrdoob
Copy link
Owner

mrdoob commented Sep 30, 2019

@sunag yeah, would be nice to have a PR with your suggestion so we can discuss it there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants