Hardware Instancing: Instance index shader input?

So we have hardware instancing: panda3d.org/blog/?p=44

Cool. How do I get some instance specific value (such as the index of the currently rendering instance) in the shader? This does not appear to be documented anywhere I can find, and without it, hardware instancing is useless. I’m using cg shaders by the way. Mainly I just want the name of the shader input, and any semantic if one is needed.

Perhaps the docs for setInstanceCount or the manual’s list of cg shader inputs ( panda3d.org/manual/index.php/L … der_Inputs ) should document this?


You can just bind an arbitrary integer scalar input that is ignored by Panda (e.g. l_ or o_) to the INSTANCEID semantic. The gp4vp documentation is supposed to cover it, but it doesn’t, unfortunately.

It’s not a Panda-specific input, so it doesn’t go into the list of possible Cg shader inputs. Also, setInstanceCount is entirely unrelated to the shader mechanism (even though its on ShaderAttrib), so documenting it there would be inappropriate.

I have it like this in my vertex shader:

in varying int o_id : INSTANCEID

Shader inputs involving arrays and arrays of vectors and matrices are being worked on actively right now and will available shortly. Stay tuned…

I’ve been hearing that recently. I’m looking forward to it!

rdb, with that I’m getting:
error C5108: unknown semantics “INSTANCEID”
I have a NVIDIA GeForce 9600M GT card, which I believe should support instancing, but the error implies otherwise. Odd. Perhaps a driver issue? I’m on OSX 10.5 btw. I can try upgrading to 10.6. My other OS installs are in virtual machines with questionable graphics support, so they are not of much help here.
Any suggestions?

You need to compile the shader under a recent profile. For starters, set “basic-shaders-only #f” in your Config.prc. If that still doesn’t work, you might need to add a “//Cg profile gp4vp” (or so) line.

I’m already using basic-shaders-only #f, and adding a “//Cg profile gp4vp” line has no effect on my shader. Is there a special place I’m suppose to put said line?

Hm… something’s certainly wrong. Are you using Panda3D 1.7?


Perhaps you could release a hardware instancing example for me to try?

At the top of my shader, I have these lines:

//Cg profile gp4vp gp4fp

Furthermore, I make sure I have set this:

loadPrcFileData("", "basic-shaders-only #f")

I still get the: error C5108: unknown semantics “INSTANCEID”
It must be failing to use the correct profile somehow, or the profile is somehow broken for me.

Craig is also using OSX.

Has this problem been solved? I am getting this same error on a Windows 7 system.

I believe my problem was that my drivers lacked the needed features. It was not Panda’s fault.