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

Added #include_once shader directive and circular inclusion detection #13282

Closed
wants to merge 4 commits into from

Conversation

patrickguenther
Copy link

I've spent the last day or so trying to figure out how to create my own shader by reusing as much as possible from three.js's included ShaderChunk library. What I found particularly annoying about it, was figuring out how these chunks depend on each other, since they never include their own dependencies, like the common chunk.

With these changes, each chunk should be able to declare #include_once <...> to declare their dependencies without having to worry about including chunks more than once. And while I was at it I also added circular inclusion detection for regular includes.

I didn't know how to write unit tests for parseIncludes() without exporting it or writing actual shaders that do compile. Examples seem to still work as expected.

I didn't actually rewrite glsl files for now, but I hope this can be used to write more comprehensive shader libraries in the future.

@patrickguenther
Copy link
Author

I don't know about that LensFlare.tests.js conflict. I had to change the case of a letter somewhere or the tests wouldn't have run on my machine.

@Mugen87
Copy link
Collaborator

Mugen87 commented Feb 9, 2018

@patrickfuller You can revert these changes. It's already fixed in dev.

@WestLangley
Copy link
Collaborator

Related: #9035.

@mrdoob mrdoob added this to the rXX milestone Feb 10, 2018
@bhouston
Copy link
Contributor

@WestLangley this is not a bad idea. It is actually simplier, although not as smart, than our previous defineonce ideas.

@bhouston
Copy link
Contributor

BTW the format method of this is "#pragma once" in C preprocessor parlance: https://en.wikipedia.org/wiki/Pragma_once

@WestLangley
Copy link
Collaborator

@bhouston If I am not mistaken, this PR does not prevent the redeclaration of variables, as described in #9035 (comment), it only prevents the re-inclusion of chunks -- well, as the chunks are currently written.

@Mugen87
Copy link
Collaborator

Mugen87 commented Apr 18, 2024

In the meanwhile it's fair to state that instead of enhancing the shader chunk system in WebGLRenderer (like adding new validation checks), it's better to focus on NodeMaterial, TSL and WebGPURenderer.

@Mugen87 Mugen87 closed this Apr 18, 2024
@Mugen87 Mugen87 removed this from the r??? milestone Apr 18, 2024
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.

5 participants