Advertisement Jump to content
Sign in to follow this  

shader parameter question

This topic is 4972 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have a problem with the world matrix I recieve in my HLSL shader. I do the following:

this.effect.SetValue( "g_ViewMatrix",  device.Transform.View );
this.effect.SetValue( "g_ProjectMatrix", device.Transform.Projection );
this.effect.SetValue( "g_ViewProjectMatrix",  device.Transform.View *  device.Transform.Projection );

int passes = this.effect.Begin(0);

for (int pass = 0; pass < passes; pass++)
   // process child nodes
   foreach ( AbstractRenderNode childNode in node.Nodes )
     Process( childNode ); 


in the processing of my renderable objects I do this:
if ( this.effect != null )
  this.effect.SetValue( "g_WorldMatrix", renderable.Transform );

  this.device.Transform.World = renderable.Transform;

renderable.Render( this.device );    

So my problem is now: if I skip the effect loop and render my renderables directly the world matrix is set in the device and the scene is rendered correctly. But if I use the shader pipeline the objects are rendered correctly but the world matrix is always the one of the last renderable that was processed. I debugged the shader to see this. My question: is the shader executed with the effect.EndPass() statement, so my setting of the world matrix is always overwritten? If yes, what is the appropriate thing to do, to feed the vertex shader with the right world matrix? Thanks! Constantin

Share this post

Link to post
Share on other sites
you can put it safely within the begin / end pass, but you need to call CommitChanges() after you set the constants. I'm fairly sure that the CommitChanges() or equivalent is actually called within BeginPass() based on the documentation.



If the application changes any effect state using the Effect class members that modify state, such as Effect.StateManager, inside of an Effect.BeginPass/Effect.EndPass matching pair, the application must call Effect.CommitChanges

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!