-
Notifications
You must be signed in to change notification settings - Fork 619
Trash. ShaderTemplating
In vispy we are going to rely heavily on shaders, and want to expose to users an easy way to use their own shading code (GLSL).
With visvis, I've found that much of the shading code consists of the same snippets. For instance, all volume rendering techniques use the same basic approach, but only differ in what they do at each voxel along the ray and how they determine that the ray is stopped. Likewise, some of the lighting calculations for different light models is shared between volume rendering and mesh rendering.
It would have been nice if code resuse could be achieved by writing these snippets as functions, but its not so simple; in many cases the code needs to be embedded in different parts of an existing "template" and/or may need additional uniforms definitions.
Also, templating allows things like hardcoding the number of iterations of the loop that iterates over the light sources, making the compilers job much easier than if a uniform was used for this. You can even remove the loop completely if just one light source is used. I've actually seen significant performance increases for this specific scenario.
Therefore I've set on a sort of templating approach in visvis. But the approach that I took is way too involved, and even I find it confusion to work with if I haven't done so for a while.
Therefore, I think we should aim for a much simpler system. Here we can write down our thought on how it should look like.
On this page, an application is written that obtaining pieces of shading code that are stored together in one .glsl file. It does not solve the templating problem, but an approach like this may help in organizing our different snippets. A file may look like this:
This text is ignored, because it is not in a 'cell'
-- vertex
def main() {
... some code here
}
-- fragment
def main() {
... some code here
}
--
This text is again ignored: the tag is invalid.
-- fragment.miprenderer
... mip volume render code here
In the source code, you can then obtain a snippet using for instance get_shadercode('volume.glsl', 'fragment')
.