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

Use onBeforeCompile callback instead of its own ThreeJS Material #5

Open
mattrei opened this issue Jul 11, 2020 · 2 comments
Open

Use onBeforeCompile callback instead of its own ThreeJS Material #5

mattrei opened this issue Jul 11, 2020 · 2 comments

Comments

@mattrei
Copy link

mattrei commented Jul 11, 2020

Currently you have registered your own Material with its Vertex and Fragment shader code which is mostly copied from ThreeJs' source code.
Because you make only small changes to the fragment shader, please consider using the onBeforeCompile callback, so that the the Mesh works on any ThreeJS shipped Material and is future proof...

See this article for an in-depth usage using onBeforeCompile.

If you want I can also try to provide a PR ... (if I find time next week)

@blaze33
Copy link
Owner

blaze33 commented Jul 11, 2020

Ah yes, I wasn't really satisfied with my option to copy-paste the entire ShaderMaterial glsl code anyway but wasn't aware of any good alternative...

The interesting bit seems to be this part:

var myMaterial = new THREE.MeshStandardMaterial()myMaterial.onBeforeCompile = shader => {
  shader.fragmentShader = //this is the fragment program string in the template format
  shader.fragmentShader.replace( //we have to transform the string
    '#include <alphamap_fragment>', //we will swap out this chunk
    require('my_alphamap_fragment.glsl') //with our own
)}

Thank you for your contributions! If you find time for a PR, just update the issue to let me know, so we don't both work on it ;) that would be awesome!

@mattrei
Copy link
Author

mattrei commented Jul 12, 2020

great, so i think you can manage to integrate it. shouldn't be that hard for you considering how your coding skills. i am a bit busy at the moment. thx

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

No branches or pull requests

2 participants