Shader Preprocessor to simplify writing shaders. [For Discussion, Do Not Merge] #6273
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
One of the issues that we have right now with our shader system is ShaderLib. It has inline shader code and manual includes of other shaders via directly referencing Shader Chunks. This is awkward.
I propose that we replace the code chunks in
ShaderLib
with just moreShaderChunks
. And then we add a shader preprocessor that understands the standard C-Style include statements. And those allow for the recursive inclusion of other shader chunks.I've made a quick prototype of this (untested) to show the idea.
material_basic_fragment.glsl
that replaces the ShaderLib specification.THREE.ShaderPreprocessor
for handling recursive #include statements in GLSL shaders. It can optionally take a directly specified shader or if one isn't provided it looks for a properly named "ShaderChunk." It also contains a caching system for speed purposes. If we want to seriously use this, one should add a check to prevent infinite recursion.We can also incrementally move towards this new system as it can be made backwards compatible with older shaders.
(PS. I also discussed that I would like a GLSL preprocess to handle "#includes" back in January 2014 here: #4271 (comment) Also UE4 has one for their *.usf files.)