I used GPU Perf Studio to analyze Unity’s draw calls under DirectX11.
Remarks : - everything gets drawn twice into a render target the size of the resolution as if transparency is enabled on everything. Once with FrontCounterClockwise = true, and then false. The first time the pixel shader doesn’t sample any texture, the second time, it does. What is this ? It’s definetely not occlusion culling as I turned that off and I get the same results. All objects are drawn reverse order both times btw. - terrains are rendered 2 times, twice, and this is even weirder, I see the same draw call with the same vertex/pixel shader being called twice, once with DepthMask on, DepthTest On, the other with DepthMask off,DepthTest On and Blend on as if it had 2 passes. Why would it blend together the same mesh if I just have 1 pass in my custom terrain shader ? And I only got 2( or 5 ) brush textures while my GPU can support up to 32+ sampled textures ?
Well, this is rather weird cause initially it was deferred, I then switched to forward on all cameras, saved the scene, created another build, profiled that with GPU Perf Studio and I had the same double rendering thing on. The implementation definitely sounds like what I’m seeing but it kind of assumes a limited number of multiple render targets, like 1 or 2 while most systems can either do 4(DX 9_2 GLES3),8(DX11) or none (GLES2).
Side question, how do I get the final image color from a camera that is using deferred rendering ? I think I had an error where instead of the final image I had only normals when getting the Camera.targetTexture.
EDIT: I forgot to mention that first it’s the back faces and then front faces, but they’re not done through CULL_BACK / CULL_FRONT modes, but instead it changes the CCW ordering to true/false. This kind of suggests it wants to compute the distance between back and front faces as needed for subsurface scattering, which I don’t have enabled anywhere.
EDIT2 : I added 2 screenshots of the same object with the 2 different draw states shaders. You can also see how it tries to resolve 3 multisampled textures. Special effects don’t use multisampling, so 1 is the color buffer, 1 is depth, what’s the third one ? It definitely looks like deferred rendering of some sorts even though I checked “Forward” everywhere, even in Player Settings.
Well the only thing I can think of is the way DX or GL is set up, culling like the following in our engine prevents sides being rendered not seen by the camera. So that wouldn’t be an explanation for it:
They aren’t, I used a terrain with a custom shader and an object with a custom shader (with 1 pass), I think the terrain has extra passes behind the scenes though. And I know how backface culling works, it’s just that I don’t understand what Unity tries to do there.