question about shader, panda and cg

Sorry to bother you again. I have more in-depth questions this time.

The application we are creating is like an editor.
You give it meshes, and then you can put the results and move them in the scene.

This mean that we don’t know what kind of mesh we get. The application
can use a lot of different textures, or effects…

For now we implemented a converter (which uses mayatoegg2008
converter) that gives us information about the mesh (type and number
of textures used…)
We deduce the kind of shader we want to use on the mesh, based on the
information, the “format” from the mesh and based on the effect we
want to do (“highlight”, “shadow”,…)
Until now, we had no real problem.
Implementation is a bit more complicated.
if we consider only 3 kinds of texture (diffuse, normal, ambient) and
3 effects (none, highlight, shadow) and the permutation possible (
since the order of textures will change)
This creates a lot of possible shaders !

According to developers (,…), one solution is to create
an ‘ubershader’, a shader that takes all the possible effects/textures
and parameters to do only what must be done. Each permutation is
another compilation, so there is no slowdown.

The problem is, how this can be done with the way Panda uses and
compiles cg? We can’t use a function from another file…

And about this “shader_generator”? How does this thing work and can it
be used in our case?


Hmm you can generate your shared in python, shader loader does can use a regular string. Or you can spring your shader with #DEFINE and #IFDEF #ENDIF statements just like in c.

It cant do shadows so you are on your own there.