-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
Clean up Translucency.js #19156
Clean up Translucency.js #19156
Conversation
Thanks! |
Not until we figure out how to convert modules to non modules.
Sounds good to me! |
It seems the PR changed only the |
Sorry @Mugen87 I tought |
In the meanwhile, I'm not a fan of modifying, copying or enhancing shader chunks in experimental shader example code since these examples are hard to maintain and can easily break. A similar demo that made problems in the past is webgl_materials_envmaps_parallax. I think I would prefer to avoid demos in the future that do stuff like that since they make it harder to move forward with changes to the core shaders. |
Well since the CI is now up, the user can be notified when some example breaks in the PR. So the user gets to know where the code he is modifying is also referred, and updates it accordingly. |
Yes, that's right. I'm criticizing the idea to add such examples in general. Updating core shaders is more cumbersome the more example code has to be changed because of this approach. |
I would advise to add such features to the core OR move it as a showcase to the forum. Anyway, that should not block this particular change. I just wanted to put this somewhere since I've noticed these troubles during support. TBH, I had a different view on this topic in the past. But in the meanwhile, I think it's the more appropriate approach considering the size of the project. |
It's unclear how to make new PR in examples, why we not updated the contribution guide? |
I agree with @Mugen87. I find this shader difficult to read. I also think this example should have been a showcase originally... It relies on |
We have 6 examples with water and only one with subsufrace scattering :D
Some of them literally the same. |
@WestLangley in my opinion, this is much easier to read for a developer who doesn't know all of the Three.js internals (talking from personal experience here).
Yeah, but also in the examples is much more easier to find for users. And also subsurface scattering is such a fundamental thing, that would feel weird not having an example of it. I personally came looking for it after having used it in Unity.
In my project I removed the sampler of that texture, but do you know of a way to make it optional? I don't know if there's a better way than a boolean uniform. I can make a PR if we decide on a way. |
You are saying this technique does not require a thickness map for the model? |
I just replaced vec3 thickness = thicknessColor * texture2D(thicknessMap, uv).r; with vec3 thickness = thicknessColor; since my model shape was kinda uniform (like a sphere). This is like setting setting all of the thickness map to 1 and just playing with the color. The results were acceptable for me, however I don't know if this is technically correct since they did not mention any of this in the presentation. |
See the link at the top of the shader. In theory, a model-specific so-called thickness map is required, or must be computed prior to rendering. But you are correct, it can be used without it. The rendering will just be missing detail. |
The good news is that we now have automated pixel testing running in the examples so we'll be able to spot these things faster. |
I was adapting the Translucency shader to work with MeshStandardMaterial, and I noticed that 90% of the code from the shader is from the Phong shader.
I cleaned it up and now it basically works like this:
The Pros of this are:
The Cons of this are:
RE_Direct( directLight, geometry, material, reflectedLight );
will be changed.But I guess that's what CIs are for.
The updated example is the same of the current example since this is only a cleanup.
https://raw.githack.com/marcofugaro/three.js/translucency-update/examples/webgl_materials_translucency.html
In this PR also:
However there is a thing I wasn't able to do: make the shader work without a texture passed in
thicknessMap
.In this line, if no texture, the sampled color is
0
, making the shader output color black. How do I remove it from the equation? With a uniformuseTexture
? Know of a better way?three.js/examples/jsm/shaders/TranslucentShader.js
Line 101 in eb86390
Also, I have some suggestions:
SubsurfaceScatteringShader.js
, that's more clear and easier to find in my opinion (I was looking for subsurface scattering the Three.js and was puzzled to find nothing at first).