moeller
04-05-2006, 04:30 AM
I have added simple vertex shader 1.1 support to my direct3d implementation of my render system. My goal is to add shadowing with shadow volume and therefor vertex shaders could be handy. My framework is a bit complicated, using C# on .Net or Mono, Linux or Windows, and OpenGL or Direct3D9. But everything works nicely so far except for the Direct3D vertex shader part.
The general implementation seems to work ok. I read the shader code in Cg, compile it to vs_1_1 and load it on the device. Connect a vertex buffer and index buffer together with a vertex declaration and set the shader constants. I got a few sample shaders working 100% correct.
Now when it comes to the shadow volume extrusion shader I get some glitches. If I render the scene with the exact same configuration I get different looking frames at times. A correct one, and at times a wrong one. If I reduce the frame rate with a delay in my main loop I only get correct frames. If I use software vertex processing I only get correct frames. But using hardware vertex processing on my Geforce4 Ti 4200 I can get two different frames from the same render instructions.
What I debuged so far (in many sleepless nights) is that the visible glitches (shadows where no shadows should be, different renderings of the same data) are caused by the "slt" instruction. If the float x I compare (x < 0) is near 0, the shader decides not always the same, even if it is the same data I provide. I could reproduce this problem with different shader codes.
The fact that I get two different frames from the same data looked to me at first as if it is a problem with wrong data (index buffer) or not initialized data. But I have triple checked all now. So I really do not have any idea what might be wrong, beside some difference how the shader is executed.
Btw. compiling the same Cg code and using the same data buffers on my OpenGl implementation works 100% correct as well. So only the direct3d hardware case causes problems.
I can't believe that there are "different" vertex shader units on my card, processing the data in a different way. Or that directx processes half in software and half in hardware, while they are not 100% identical.
Anyone has ever had a similar problem? Or anyone got an idea how I could track down the problem.
Thank's for any ideas or comments.
Michael
The general implementation seems to work ok. I read the shader code in Cg, compile it to vs_1_1 and load it on the device. Connect a vertex buffer and index buffer together with a vertex declaration and set the shader constants. I got a few sample shaders working 100% correct.
Now when it comes to the shadow volume extrusion shader I get some glitches. If I render the scene with the exact same configuration I get different looking frames at times. A correct one, and at times a wrong one. If I reduce the frame rate with a delay in my main loop I only get correct frames. If I use software vertex processing I only get correct frames. But using hardware vertex processing on my Geforce4 Ti 4200 I can get two different frames from the same render instructions.
What I debuged so far (in many sleepless nights) is that the visible glitches (shadows where no shadows should be, different renderings of the same data) are caused by the "slt" instruction. If the float x I compare (x < 0) is near 0, the shader decides not always the same, even if it is the same data I provide. I could reproduce this problem with different shader codes.
The fact that I get two different frames from the same data looked to me at first as if it is a problem with wrong data (index buffer) or not initialized data. But I have triple checked all now. So I really do not have any idea what might be wrong, beside some difference how the shader is executed.
Btw. compiling the same Cg code and using the same data buffers on my OpenGl implementation works 100% correct as well. So only the direct3d hardware case causes problems.
I can't believe that there are "different" vertex shader units on my card, processing the data in a different way. Or that directx processes half in software and half in hardware, while they are not 100% identical.
Anyone has ever had a similar problem? Or anyone got an idea how I could track down the problem.
Thank's for any ideas or comments.
Michael