panda3d shading system isnt Cg 1.5 or is it?

Shading is what the fixed function pipe line does. It computes shadow based on the normals the old fashioned way.

Now when i use Cg shaders it should override that. But it does not. I get the fixed functions shading + my own bump panning + glow shader. But when i try to reproduce that on a smaller scale in a little demo. It does not work. And I boke this in game so now i don’t see it either.

Now other issues with the cg shaders came up and i am rewriting them and cant get the “fixed function” shading to work with my own shader system as it had nicly before, it looks like the only thing i did before is added color to my computation but now that is does not work. It was illogical how it worked before fixedfun -> COLOR -> my vshader -> fixedfun -> fshader … it was odd and maybe was one of the numerous wearinesses of the Cg system.

Now looking through the Cg 1.5 documentation it does not look like panda3d shading system at all. This is part of the Cg 1.5 not supported by panda:

technique bumpdemo_arb {

  pass {

    FragmentProgram =

      compile arbfp1 C8E4f_specSurf(Ambient,

                                    float4(DiffuseMaterial  * LightColor, 1),

                                    float4(SpecularMaterial * LightColor, 1),




    VertexProgram =

      compile arbvp1 C8E6v_torus(LightPosition,



                                 float2(OuterRadius, InnerRadius));



what is light color in the 1st place? There is no light in the panda shading system. I find this in one of the tutorials: “ mspos_light “ the mysterious valuable that is not listed any where in the documentation. And this the Texture.FTShadow? Can some one explain how the system work and ties in to the Nvid’s Cg so that we can use its documentation? Also what is that in the work arounds “We have found that if you manually allocate registers by supplying a semantic string for each parameter, this problem is bypassed.â€

Whew, that was a lot of questions for one post.

The Cg program you list is not allowed by panda. Panda does not allow all of Cg - it only allows programs that follow a certain template:

void vshader(…) { … }
void fshader(…) { … }

Next, you ask why you are seeing lighting when you’re using a shader. To answer that, realize that there is absolutely no built-in lighting support in the shader subsystem. You shouldn’t have any unless you implement it yourself. That’s why you didn’t find any mention of it in any of the documentation. If you’re seeing something that looks like lighting, there are several possibilities:

  1. Panda contains a bug, or
  2. Your shader didn’t compile at all, and what you’re seeing is fixed function pipeline. If that’s the case, you should have an error message on the output.
  3. Your shader did compile and is producing results that look a lot like the fixed function pipeline.

Finally, you ask about that sample program. The shader contains the parameter:

    uniform float4 mspos_light

That means: give me the model-space position of the nodepath whose name is “light.” When the panda runtime system sees this, it searches for a nodepath with that name (“light”), calculates the position of it relative to the model’s coordinate system, and passes it into the shader.

The python code contains this:"light", plnp)

So the panda program is passing a nodepath (plnp) to the shader, and giving it a name, “light.” This is stored in a little table of nodepaths accessible to the shader. When I said that panda “searches” for a nodepath named “light,” I mean it searches this little table.

Don’t forget to read the panda manual on Pixel and Vertex shaders.

“mspos” would is a great help now i know :slight_smile: some how i missed that.

So there is no built in vars that i can get that tell me the lights? So i would have to pass every thing like position, color, and intensity myself per each of the lights? Also i would have to pass material parameters my self too? And not forget about semantic strings to fix the compiler.

Is TEXCOORD0, a semantic string:
" in float2 vtx_texcoord0 : TEXCOORD0, " ?

Panda contains a bug that confused me too which allows to used fixed function with my own shader. I don’t think i have reproduced it since and would drop the quest for it:).

so for inputing all the lights i would have to do some thing like this:

thanks Josh!

To answer your first question, yes, “TEXCOORD0” is a semantic string.

And, fortunately, I now understand your other question. No, sadly, there’s no way to access the light list. But before I explain why that is, let me explain the problem in more detail.

Right now, there are four reasonable ways for a 3D engine to handle multiple lights. Of those, panda only currently supports three.

Option 1 is multi-pass rendering: put multiple copies of the model in your scene graph, all at the same position, but each with a different light. So the shader only handles one light at a time. Therefore, the shader only has one set of light parameters:

  uniform float4 mspos_light
  uniform float4 k_light_color
  uniform float4 k_light_specular

To use this method, you have to manually set these parameters using setShaderInput.

Option 2 is deferred shading: this is tricky, but rather elegant. What’s amazing about it is that you don’t have to assign lights at all: it’s all fully automatic. The sample program shows how it is done.

Option 3 is dynamic shader generation: actually synthesize a different shader for each model, based on the attributes of that model. For example, you could do this:

def generateShader(model):
    body = "//Cg" + SHADERHEADER
    for i,light in enumerate(model.getLightList()):
      body = body + "  color = color + complicatedfn(k_light",i,");"
    body = body + SHADERFOOTER
    shader = Shader.make(body)

So there, each time you use “setLight” to alter the lights on a model, you also have to call generateShader to create the shader for those lights.

With this option, you’re going to generate a combinatorial explosion of different shaders. It would be best if you could keep the explosion under control - try to limit it to under 100 unique shaders. This is because each time you generate a never-before-seen shader, that shader has to get compiled, which is a slow process.

Option 4 is this: pass an array of lights into the shader. Then, using a shader that contains a loop, traverse the array. Of course, this requires shader model 3, because only shader model 3 supports true looping. Unfortunately, currently, Panda has no way to pass an array to a shader. So this option is not yet viable for Panda users.

Oh, and finally, I should say: when I implemented the shader subsystem, shader model 3 didn’t exist. So there wasn’t really any need to pass arrays to shaders. Now that we have shader model 3, I should add that feature. After I add that, I can add support for fetching the light array.

Yha shader model 4 is out :slight_smile:. IF i hack in a GLSL will it be possible then? I have worked with GLSL with pyOpenGL and it was not that complex. Although i will probably not do this right now but will keep that on the list of things to improve.

No, adding GLSL isn’t the answer. Panda3D already supports Cg, and Cg already supports shader model 3. What’s missing is a way to pass an array to a shader.

Which is not to say that GLSL support wouldn’t be nice, but it would suffer the same problem.

ok but passing a hard coded array with a known length should not be the problem just would look like this:


that’s right. For that, you don’t even need SM3.