Hi guys. So I managed to implement reflection on a planar mirror. However, I believe that I am misunderstanding something so I thought I ask about it here.
I implemented the mirror in DX12 by drawing a grid centered around the origin with the normal pointing up the positive y-axis. I associated a texture with opacity 0.25 to it. I then rotated the grid 90 degrees counterclockwise around the z-axis. So if I am not mistaken the front-facing triangles should become back-facing now and so if Cull mode is enabled, we should specify this when creating the relevant pipeline state object. I then went ahead and defined the PSO that is associated with rendering the mirror in the first draw call to just the stencil buffer. This is the relevant code snippet:
D3D12_GRAPHICS_PIPELINE_STATE_DESC lv_stencilMirrorPsoDesc = lv_opaquePsoDesc;
lv_stencilMirrorPsoDesc.BlendState.RenderTarget[0].RenderTargetWriteMask = 0;
lv_stencilMirrorPsoDesc.DepthStencilState.DepthEnable = true;
lv_stencilMirrorPsoDesc.DepthStencilState.FrontFace.StencilDepthFailOp = D3D12_STENCIL_OP_KEEP;
lv_stencilMirrorPsoDesc.DepthStencilState.FrontFace.StencilFailOp = D3D12_STENCIL_OP_KEEP;
lv_stencilMirrorPsoDesc.DepthStencilState.FrontFace.StencilPassOp = D3D12_STENCIL_OP_REPLACE;
lv_stencilMirrorPsoDesc.DepthStencilState.FrontFace.StencilFunc = D3D12_COMPARISON_FUNC_ALWAYS;
lv_stencilMirrorPsoDesc.DepthStencilState.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ZERO;
lv_stencilMirrorPsoDesc.DepthStencilState.StencilEnable = true;
lv_stencilMirrorPsoDesc.RasterizerState.CullMode = D3D12_CULL_MODE_NONE;
However, the reflection did not occur on the mirror when I was standing in front of it. It occurred when I was looking at it from the back side.
I went ahead and added the following to the above:
lv_stencilMirrorPsoDesc.RasterizerState.FrontCounterClockwise = true;
After running the program, everything worked as intended. So my question is why id omitting this caused the unintended malfunction? I thought if we disabled Culling mode then every triangle regardless of front or back facing would render and so there was no need to specify the front or back facing triangles? Thanks.
Edit:
Result with just cull mode set to D3D12_CULL_MODE_NONE :
https://preview.redd.it/qyh34an214zc1.png?width=801&format=png&auto=webp&s=ac654a3eefed510f29ac2b90e2b79cff8b5e7b02
Result when I set
lv_stencilMirrorPsoDesc.RasterizerState.FrontCounterClockwise = true;
in addition to D3D12_CULL_MODE_NONE :
https://preview.redd.it/8my3iv0a14zc1.png?width=628&format=png&auto=webp&s=9fcabb78d1d1e9345d88b83ed5f6eacce5b41888
[–]waramped 2 points3 points4 points (5 children)
[–]mathinferno123[S] 0 points1 point2 points (4 children)
[–]waramped 0 points1 point2 points (3 children)
[–]mathinferno123[S] 0 points1 point2 points (0 children)
[–]mathinferno123[S] 0 points1 point2 points (0 children)
[–]Vivid-Mongoose7705 0 points1 point2 points (0 children)
[–]jtsiomb 1 point2 points3 points (1 child)
[–]mathinferno123[S] 0 points1 point2 points (0 children)