Shader generator in Python?

Is there any good reason why shader generator is written in C++ instead of Python? I am thinking about incorporating new effects into it, and believe that having it in Python would let us do it much easier and quicker. What do you think about it?

Yes, because is integrated into the Panda3D core, e.g. the lowerlevel GSG and RenderState interfaces. Moving it to Python would greatly slow down the rendering process.

Actually I hate that the CommonFilters code is written in Python too. I’m thinking about moving that code to C++ as well.

I have toyed with the idea of having an optional Python callback in the ShaderGenerator, though, because it would be handy to be able to extend the ShaderGenerator via Python, even if it is a little slower. Supporting this sort of thing would be consistent with Panda’s rapid-development philosophy.


Hmm, for the ShaderGenerator to be fully extendable, we’ll need to split up the main synthesize call. Currently, even if you want to extend it from C++, you’ll have to override that function and with that have to rewrite all the shader synthesizing code.

Having the shader generator extendable from Python code would be cool though. Then the user can write e.g. his über-shadow-shaders while still being compatible with normal/glow maps, etc.
I thought about splitting up the generated shader into a lot of Cg functions: e.g. “float3 compute_lighting(float3 vtx_normal)”. The user will be able to set shader body that overrides or extends that particular shader function.