Mounted image shader problem
by Justin Tolchin · in Torque Game Engine Advanced · 08/22/2005 (3:09 pm) · 5 replies
Hi all,
Just a weird little thing I've noticed. We have a player color shader that we use by setting a shader constant during the rendering of our player characters (RTSUnit's, actually). The shader works great, but when a unit has a mounted weapon and that weapon also uses the player color shader, sometimes the mounted image draws with the correct player color and sometimes it doesn't. It seems to depend on what is in the camera view at the time. I.e., if I rotate the camera around the unit in question it will occasionally draw with the right color, so I'm guessing that the mounted images just don't get rendered at the same time (necessarily) as the unit that it's mounted on. So it just gets whatever color was in the shader constant at the time the mounted image is rendered. So my question is, is there some way I can control the order of the rendering so I can get the mounted images to draw immediately after the unit itself? Or is there another way to handle this?
Thanks!
Just a weird little thing I've noticed. We have a player color shader that we use by setting a shader constant during the rendering of our player characters (RTSUnit's, actually). The shader works great, but when a unit has a mounted weapon and that weapon also uses the player color shader, sometimes the mounted image draws with the correct player color and sometimes it doesn't. It seems to depend on what is in the camera view at the time. I.e., if I rotate the camera around the unit in question it will occasionally draw with the right color, so I'm guessing that the mounted images just don't get rendered at the same time (necessarily) as the unit that it's mounted on. So it just gets whatever color was in the shader constant at the time the mounted image is rendered. So my question is, is there some way I can control the order of the rendering so I can get the mounted images to draw immediately after the unit itself? Or is there another way to handle this?
Thanks!
#2
Right now we only have 2 "teams", so when a unit from team 2 gets rendered with a mounted image, sometimes the mounted image uses team 1's color, and sometimes team 2's color. So it's not just some random color.
Currently we're using this line to set up the shader:
GFX->setPixelShaderConstF( PC_USERDEF2, (float*)mTeamcolors[teamnum], 1 );
in our "renderImage" method, just before calling "mShapeInstance->render();"
PC_USERDEF2 corresponds to register C6, as I understand it (I'm not a graphics guy).
It seems strange to me that the mounted image doesn't get rendered as part of the "render()" call, but apparently it's done separately.
When you say "add it as a constant to the material", which "it" are you referring to? The color? The team? Either way I'm not sure that makes sense: if I have a unit that uses a certain material/texture, I'm going to use the same material whether that unit belongs to team 1 or team 2, so what would I store in the material? I'm probably just not understanding what you're saying, so if you can give me some pseudo code as an example that would help a lot.
Thanks!
08/29/2005 (3:23 pm)
Hi Neo,Right now we only have 2 "teams", so when a unit from team 2 gets rendered with a mounted image, sometimes the mounted image uses team 1's color, and sometimes team 2's color. So it's not just some random color.
Currently we're using this line to set up the shader:
GFX->setPixelShaderConstF( PC_USERDEF2, (float*)mTeamcolors[teamnum], 1 );
in our "renderImage" method, just before calling "mShapeInstance->render();"
PC_USERDEF2 corresponds to register C6, as I understand it (I'm not a graphics guy).
It seems strange to me that the mounted image doesn't get rendered as part of the "render()" call, but apparently it's done separately.
When you say "add it as a constant to the material", which "it" are you referring to? The color? The team? Either way I'm not sure that makes sense: if I have a unit that uses a certain material/texture, I'm going to use the same material whether that unit belongs to team 1 or team 2, so what would I store in the material? I'm probably just not understanding what you're saying, so if you can give me some pseudo code as an example that would help a lot.
Thanks!
#3
08/29/2005 (7:53 pm)
Maybe I'm missing something, but have you tried adding the set shader constant call into ::renderMountedImage as well?
#4
Thanks, Brian. That did the trick.
08/30/2005 (9:45 am)
Actually, I was the one who was missing something. Guess I should have looked a little harder first. :-)Thanks, Brian. That did the trick.
#5
08/30/2005 (10:01 am)
Cool! Glad I could help!
Torque Owner Neo Binedell
Try using a register that will not be used by anything else to see if it is being overwritten.
But each rendered object is responsible for its own state so I don't think thats the way to
go.
One way would be to add it as a constant to the material so that it gets passed in for every
object that uses it. You can do that by either hacking material/custom material as a quick fix
or by adding general support for it.
Let me know if you need a better explanation or some help.
~neo