Help needed with DirectX Matrix Math!

Started by
1 comment, last by NightCreature83 12 years, 7 months ago
If I use my World, View & Proj matrices in C++ via d3d_device->SetTransform() and then run my results though Pix, CCW ordered triangles become CW ordered and are rendered.

If I use the exact same matrices in a VertexShader, the CCW triangles remain CCW but they are not drawn.

Same results with D3DCULL_CW or D3DCULL_CCW

What am I missing there? Do I need to invert one of my matrices?
Advertisement
To answer my own question, apparently DX resets settings during the Draw phases.

So I had:

mDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);

at the beginning of the app, and nowhere else, hoping that it would be persistent.

But I have to call that every draw phase.

To answer my own question, apparently DX resets settings during the Draw phases.

So I had:

mDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);

at the beginning of the app, and nowhere else, hoping that it would be persistent.

But I have to call that every draw phase.

Renderstates are set once and not changed or reset between changes, are you sure you don't have CULLMODE=CCW; in your pass in the FX file. Remeber that the "VertexProgram" line in the effect file is just a convenient way of writing device->SetVertexShader() with the provided shader. Same goes for any of these kind of setup in the pass configuration. The drawcall is issued after these renderstates are set so reseting things after the pixel and vertex shader lines effectively does nothing to the renderstate setup.

Render states arent reset between drawcalls because these require a flush of the instructions issued to the GPU, this is slow it is faster to just submit the next batch with the same settings. Don't worry about changing renderstates being a bottleneck though as switching shader or texture is far worse, thats why all professional engines do some kind of sorting by materials.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

This topic is closed to new replies.

Advertisement