I'm trying to implement Alex Vlachos very clever technique of using a stencil mesh to write in the stencil buffer to save precious GPU cycles in my VR game. I've already done a lot of optimization to try and optimize fillrate for my game but this seems like the ideal solution to save a huge amount.
Here is the link of the technique for more info:
The whole thing is interesting but the technique I'm talking about is on slide 59.
However, I'm at a loss on how to write in the stencil buffer in UE4. I've been searching RHI commands and found some related to the stencil buffer but I don't know exactly where to start to try and implement that.
If anyone can give me an hand that would be greatly appreciated.
asked Mar 11 '15 at 03:54 PM in Rendering
To use stencil you have to bind a depthstencil target with something like this SetRenderTarget(RHICmdList, FTextureRHIRef(), GetCubeShadowDepthZSurface(ShadowResolution));
Then clear RHICmdList.ClearMRT(bClearColor, NumClearColors, Colors, bClearDepth, Depth, bClearStencil, Stencil, FIntRect());
Then render some geometry to setup the stencil mask, with something like this
// Set stencil to one. RHICmdList.SetDepthStencilState(TStaticDepthStencilState< false,CF_DepthNearOrEqual, true,CF_Always,SO_Keep,SO_Keep,SO_Replace, false,CF_Always,SO_Keep,SO_Keep,SO_Keep, 0xff,0xff >::GetRHI(), 1);
In order to get fill rate savings during the base pass, you need to set up that stencil mask before the base pass, then setup stencil state to test against 1 with SetDepthStencilState.
answered May 08 '15 at 01:33 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here