[CgFX + D3D9] cgUpdatePassParameters() ignored

Started by
5 comments, last by wiegje85 12 years, 11 months ago
Greetings!

So I got this:

CGpass pass = cgGetFirstPass(technique);
while(pass)
{
// for each mesh (2 cubes)
cgSetPassState(pass);
cgSetParameterMatrixfr(...);
cgUpdatePassParameters();
RenderTheMesh();
cgResetPassState(pass);

pass = cgGetNextPass();
}


Now according to the nvidia examples this should work. It doesn't. What happens is that I have two meshes, one in position (0,0,8) and one in position (0,5,0). Both meshes render at position (0,5,0). Cg seems to render both meshes at the second and last world position that is set (0,5,0).

However, if I use two different shaders for both the cubes, it does work properly. And, if I call cgSetPassState() for each mesh that I render within the same pass, it also works... but I don't want that because I'll be state-raping my videocard to hell, as I'll be setting 264 renderstates per call to cgSetPassState().

The parameter I'm setting is a global uniform parameter (uniform float4x4 g_world : WORLD). Passing the g_world to the vertex program as a scope variable also didn't yield any results (in uniform float4x4 in_world).

Does anyone know what I'm doing wrong? :)
Advertisement
I had this issue not too long ago...

Look into 'Parameter Shadowing'. Chances are its set to true when you call cgd3d9LoadProgram and/or you need to call cgd3d9EnableParameterShadowing to turn it off. There might be a third command to enable/disable it globally but I can't recall what it is and I'm at work atm...

I had this issue not too long ago...

Look into 'Parameter Shadowing'. Chances are its set to true when you call cgd3d9LoadProgram and/or you need to call cgd3d9EnableParameterShadowing to turn it off. There might be a third command to enable/disable it globally but I can't recall what it is and I'm at work atm...


I'm using CgFX, I have no way to access the effect's program. Or am I missing something perhaps? :)
Ok now I'm home I can respond a wee bit better...

I don't use the cgfx framework so my problem was slightly different. Turned out I was loading my cg programs with 'Parameter Shadowing' enabled. What this means is that when you try to set a shader value, said value is not actually updated until a subsequent call to cgBindProgram. Calls to cgUpdateProgramParameters did nothing for me until I turned off the Parameter Shadowing.

For you theres possibly a couple of things you could try out (as I'm not using cgfx I can't really test them out myself):

When you create your effect, try calling cgGetPassProgram to obtain the CGProgram's for each pass, and then call cgD3D9EnableParameterShadowing on it passing false to turn off parameter shadowing. Something like:

CGProgram prog = cgGetPassProgram(pass, CG_VERTEX_DOMAIN); // or CG_FRAGMENT_DOMAIN
HRESULT hr = cgD3D9EnableParameterShadowing(prog, false);


Alternatively try calling cgSetPassState() after you set your parameter(s). Presumably under the hood this would call to bind the cg program and thus update any parameters you've tried to set.

Of course if you turn off parameter shadowing, be aware of what you are actually turning off....might wanna take a gander at the CG docs on it.

Hope this helps :)
HOLY HELL IT WORKS! Better inform nvidia they have a bug.

Do you know how long I've been avoiding CgFX because of this issue?! A YEAR! Thank you so much, I'd give you some manlovin' if it wasn't so weird. :D :D :D
Hehe I know your pain dude, I've had plenty of battles with CG in the past...

I wouldn't say its a bug, It's doing what the docs say it should be doing. Nvidia's doc are good at explaining what all the parts of CG do, but they don't seem particularly great at describing why or how to string things together...atleast in my experience anyway.

Glad you got it working

Hehe I know your pain dude, I've had plenty of battles with CG in the past...

I wouldn't say its a bug, It's doing what the docs say it should be doing. Nvidia's doc are good at explaining what all the parts of CG do, but they don't seem particularly great at describing why or how to string things together...atleast in my experience anyway.

Glad you got it working


Its a damn big pitfall, thats for sure :) Nvidia should indeed rewrite their documentation some time ;) Thanks again for all the help! :D

This topic is closed to new replies.

Advertisement