-
-
Notifications
You must be signed in to change notification settings - Fork 35.8k
ShaderChunk: Turn alphaTest into a uniform #22110
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
Conversation
I think I would prefer what @WestLangley said: #15654 (comment).
|
Oh! I missed that comment. |
src/materials/Material.js
Outdated
@@ -62,7 +62,7 @@ class Material extends EventDispatcher { | |||
|
|||
this.dithering = false; | |||
|
|||
this.alphaTest = 0; | |||
this.alphaTest = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I remember correctly having a nullable material property seemed problematic when sheen was implemented. There is also a PR that tries to remove this behavior, see https://github.com/mrdoob/three.js/pull/17700/files#diff-98984bfa7fa23284a6a8bce191397059df3700f4377553fa7312dd69a78d780fL38.
The policy for sheen right now is that null
disables its influence in the shader. With this change, this would also be true
for alphaTest
. I'm just mentioning this since #17700 should be closed if this PR is going to be merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using null
, we could keep the status quo and set USE_ALPHATEST
only when alphaTest
is greater zero. I guess I would prefer this approach. Introducing a uniform still makes sense since the engine produces less shader compilations when alphaTest
is animated (although I'm not sure how common this use case is).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I've tried to make null
work but having this double state is a nightmare, speciall in the editor...
Reverting to 0
but adding a > 0
check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using
null
, we could keep the status quo and setUSE_ALPHATEST
only whenalphaTest
is greater zero. I guess I would prefer this approach. Introducing a uniform still makes sense since the engine produces less shader compilations whenalphaTest
is animated (although I'm not sure how common this use case is).
Ha! I missed that comment. Glad that we came to the same conclusion 😀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll finish that PR after we're done with this one 👍
Um, it seems this change breaks |
Setting We can achieve the same optimization by adding |
Do you mind double checking? There was a typo when you tested it 🤞 |
It seems examples like There is also another things that bothers me: If you have a material with |
Fixed!
Hmm, yeah... I wonder if avoiding that |
@@ -18,7 +18,7 @@ const UniformsLib = { | |||
uv2Transform: { value: new Matrix3() }, | |||
|
|||
alphaMap: { value: null }, | |||
alphaTest: { value: 0 } | |||
alphaTest: { value: null } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Um, shouldn't this be 0
(similar to opacity
)?
For cases like NodeMaterial, where My suggestion in #15654 (comment) had been something like a |
@mrdoob Why not #22110 (comment)? |
Second try: #22409 |
Related issues: #19803 (comment) #15654 #5623
Description
I think this has been proposed a few times. Should make programs more reusable.