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

Fix material rendering for CurveModifier #20691

Merged
merged 3 commits into from
Nov 18, 2020
Merged

Conversation

mjurczyk
Copy link
Contributor

Solves #20687 (related #20688)

Since I was losing my mind trying to figure out the connections of shader chunks for materials anyway, I found a second to fix the issue with curve modifier - it should now work with all materials. Tested on:

  • MeshNormalMaterial
  • MeshBasicMaterial
  • MeshStandardMaterial
  • MeshPhysicalMaterial
  • MeshDepthMaterial
  • MeshDistanceMaterial
  • MeshLambertMaterial
  • MeshMatcapMaterial
  • MeshPhongMaterial
  • MeshToonMaterial
  1. Adding USE_ENVMAP was technically a solution, @WestLangley - since it unlocks this part of the basic material shader. But isn't necessary with this PR.

  2. Typo fix (@AdaRoseCannon): I think this is not legal (docs, if I'm not wrong, it just sets the color to default and passes number to setValues):

const boxMaterial = new THREE.MeshBasicMaterial( 0x99ff99 );

  1. There's no point 3, I'd just like to dedicate a single point on this list to the sanity of the person who will try to maintain these shader chunks in the future. :')

  2. Now the main part:

Removed USE_ENVMAP.

Removed includes that may duplicate declarations from the modified shader.

Moved the modified shader code to the beginning of the shader void main and placed includes in the correct order - this fixes the issue with different materials not rendering (incl. MeshBasicMaterial and MeshNormalMaterial.)

The main body of the modified shader is untouched.

This substitution seemed to be the same as the original shader chunk. When commented out it does seem to change nothing, but I may be missing something - though if we'd put the values in right places new code looks just like the old one. 🤔

@Mugen87
Copy link
Collaborator

Mugen87 commented Nov 17, 2020

It seems webgl_modifier_curve_instanced is failing now. Do you mind having a look?

@AdaRoseCannon
Copy link
Contributor

AdaRoseCannon commented Nov 17, 2020 via email

@AdaRoseCannon
Copy link
Contributor

AdaRoseCannon commented Nov 17, 2020

I don't think I know enough about instancing to put my finger on what the issue could be. I've dumped the compiled shaders and am looking at the diffs but nothing is jumping out at me yet.

Diffs: https://editor.mergely.com/EtzCNhtw/

@mjurczyk
Copy link
Contributor Author

No worries, I think I know what the reason is - I'll take care of it in a moment.

@mrdoob mrdoob added this to the r123 milestone Nov 17, 2020
@mjurczyk
Copy link
Contributor Author

As I thought, project vertex wasn't 100% same as the replaced code - if included, that chunk adds an instancing matrix. Since instancing calculations for the modifier are done earlier (L155), this wasn't a good idea.

Also - reverted the example visuals to the original state (material colours.)

@WestLangley
Copy link
Collaborator

Adding USE_ENVMAP was technically a solution, @WestLangley

I am not sure what technically a solution means.

The renderer sets USE_ENVMAP when it is appropriate. Hard-coding the DEFINE in #20688 is improper.

@AdaRoseCannon
Copy link
Contributor

Thank you so much! Tested it and it works.

Thanks also for spotting the material mistake on the handle boxes in the examples.

Would you also be able to fix the remaining new THREE.MeshBasicMaterial( 0x99ff99 ); in the instanced demo?

@mjurczyk
Copy link
Contributor Author

@WestLangley, what I meant is that in this case it did achieve the result - with a small sideeffect of non-envmap materials using the envmap chunks when going through this modifier. But yes, you are right.

@AdaRoseCannon missed that one, done.

@Mugen87
Copy link
Collaborator

Mugen87 commented Nov 18, 2020

@mrdoob Independently of this PR, I think we should be more careful with adding example code that overrides/patches existing shader chunk code. In the past, I had a different view on this topic but in the meanwhile I've realized that such examples are very fragile. Especially when shader code/chunks are refactored. webgl_materials_envmaps_parallax is a typical example for such a demo.

Thanks to E2E, it's easier now to detect failures but I'm in general no fan of this kind of code injection anymore. I suggest to implement such demos with node material instead in the future. Or in context of CurveModifier just support node materials.

@mrdoob mrdoob merged commit 7159d85 into mrdoob:dev Nov 18, 2020
@mrdoob
Copy link
Owner

mrdoob commented Nov 18, 2020

Thanks!

@mrdoob
Copy link
Owner

mrdoob commented Nov 18, 2020

@Mugen87 I agree. This is definitely not pretty.

@AdaRoseCannon
Copy link
Contributor

Yeah adapting the original code was a very fragile process. If it was in nodes it seems like it would be more resilient.

@mjurczyk mjurczyk deleted the fix-curve-modifier branch November 18, 2020 21:16
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.

None yet

5 participants