Game Creation Mastering Development

How to implement two sided view in directx 11?

I’m searching for the way to implement two sided view in directx 11, the best answer I found is this:
enter link description here

I tested to do that:

  • initialize backface culling to CCW (counter clockwise) ;
  • render the mesh with a classic vertex shader ;
  • if the object is not two-sided, we’re done with its rendering ;
  • otherwise, switch backface culling to CW (clockwise) ;
  • render the mesh with a vertex shader that inverts normals before the lighting calculation.

But my mesh constantly changes color and did not show the real color, could anyone help me,

For example, rendering skull, if I set Rasterized state to counter clockwise and inverted normals, Directx show me the inside skull color for this, but when I redraw again in the same frame the cloth with clockwise and normal normals, it draws the outside mesh, but in each frame constantly changes color from black(counterclockwise internal mesh color) to red(clockwise external mesh color) render and the expected result should be the skull with outside and inside mesh from the view position

//per frame rendering..

context_->ClearRenderTargetView(targetView_.Get(), _backgroundColor);
context_->ClearDepthStencilView(depthStencilView_.Get(), D3D11_CLEAR_DEPTH, 1.0f, 0);

//configure textures, pixel shaders, and another resources..

        renderer->setTwoSidedBuffer(XMFLOAT4{ 1,0,0,0 });
        renderer->update(_dxModel, _matrix);

        // Draws this object

        if (_twoSidedRender)
            //render first cull front with normal normals..
            renderer->setTwoSidedBuffer(XMFLOAT4{ -1,0,0,0 });

            renderer->update(_dxModel, _matrix);

            // Draws this object
HRESULT hr = swapChain_->Present(0, 0);

Leave a Reply

Your email address will not be published. Required fields are marked *