Shadow rendering on dynamic objects

Hi,

Another question. would this kind of an optimisation be ok: In ShadowRendering.cpp: 2529 the stencil setup looks like this:

// no depth test or writes, Test stencil for non-zero.
RHICmdList.SetDepthStencilState(TStaticDepthStencilState<
	false,CF_Always,
	true,CF_NotEqual,SO_Keep,SO_Keep,SO_Keep,
	false,CF_Always,SO_Keep,SO_Keep,SO_Keep,
	0xff,0xff
	>::GetRHI());

and later on there is a clear at around line 2659:

// Clear the stencil buffer to 0.
RHICmdList.Clear(false, FColor(0, 0, 0), false, 0, true, 0, FIntRect());

What if the stencil values were set to zero while rendering? Wouldn’t that make the clear unnecessary? We tried it out and saw huge perf. savings, but I just want to verify that we aren’t doing anything silly here. This is our stencil setup:

    // no depth test or writes, Test stencil for non-zero.
    RHICmdList.SetDepthStencilState(TStaticDepthStencilState<
    	false,CF_Always,
    	true,CF_NotEqual,SO_Zero,SO_Zero,SO_Zero,
    	false,CF_Always,SO_Zero,SO_Zero,SO_Zero,
    	0xff,0xff
    	>::GetRHI());

To clarify, I’m talking about stationary shadow casters here (per object stuff). The clear is a huge bottleneck on ps4, I’ve verified this using razor. I guess it’s the sync after the clear that takes so long but with this new approach there is no need for the clear.