Open TaylorMutch opened 7 years ago
This would be awesome. I looked into doing it a while back in CVISTAS. From what I found, it basically means writing a preprocessor. Is that your take?
Essentially, yes. It would need to be hooked into the hot-reloader so that we can still tinker with shaders while the app is live, but I think it's totally doable.
Many of our shaders share common elements - they all include the
projectionMatrix
,modelViewMatrix
, andcameraPosition
uniforms, as well as theposition
attribute. However, we currently re-implement the majority of these in every shader we write.Adding a shader snippet library and integrating that into how the shaders are hot-reloaded would be greatly beneficial and ensures that shaders are written in a consistent way. The base
ShaderProgram
could then have arguments for indicating which builtin uniforms and attributes should be used, as well as the name to use for each (which can have a set of defaults).It is also sometimes necessary to change certain attribute names in the shader, depending on what the intended use of the vertex buffer is for. For example,
TerrainColorGeometry
overrides thecolor
array (i.e. standard location 3) to bevalue
, which has an impact in how the shader is written. This would need to be handled by how theShaderProgram
is compiled.The result for us is that the GLSL shaders could then be written with a
#include common
which is compiled to include necessary inputs determined above. For example, thebbox_vert.glsl
shader goes from:to