I discovered something weird: when I draw something in clip-space, that is with identity modelview and projection matrices. In DX11 mode, my geometry is drawn when it’s within the [-1;1] range, not the [0;1] range I would expect from Direct3D. Why is this?
I am writing a native plugin and I need clip space values between [0;1] for interop with my Direct3D code.
I don’t have any explanation for why you would be seeing stuff in -1 to 1. Unity uses a reversed Z with DirectX which will flip the order of things, but that still shouldn’t cause stuff outside of the 0 to 1 range to show. Are you sure you’re seeing stuff through the whole -1 to 1 range, or is it just -1 to 0?
Ok, I’ve done some more testing. It appears that when I draw in my native plugin, the geometry is correctly clipped between 0 to 1. When I draw with the GL functions in OnRenderObject, however they are clipped to be within -1 to 1. I have double checked this.
So it appears drawing within Unity itself adheres to the Opengl convention. But how can they achieve this when everything is drawn in DirectX? Is the clip volume adjustable?
I would assume they’re keeping to OpenGL conventions with the GL functions and translating them to the current platform behind the scenes. Unity was original Mac only, so I many of the legacy underpinnings are OpenGL based. i.e.: the matrix you pass to the GL function is not the one used to render on the GPU.
Basically, the default for Z is 0.0 to 1.0, but it’s configurable. OpenGL is -1 to 1 in the Z by default, though there are extensions that give you the same control as DirectX.