Hi all,
I’m trying out this thing where I use a triangle instead of a cube as an environment map in the background. But I cannot get it to work, the triangle is not visible where it should be.
In the code where there is a it should be 1,1 for the z and w in the float4() – but then I don’t see the triangle…?
I set w=4 just as an example to see the triangle as smaller and in front of everything to see that it is there and working.
So my question is why w:1 does not show the triangle as it should be in clip space at the far end behind the spinning torus?
With this technique, the idea is that I don’t have to worry about any object being clipped i 3D-space, since the env-map is always behind everything.
Hi @mk2019 - sorry for the late answer - I’ve been on break.
It’s really hard to diagnose problems like this without the full code. Your triangle appears to rendering correctly, but I don’t know what the other code is doing.
I would suggest you investigate the in and out vertex positions for your objects using the Geometry resources in the GPU debugger.
then I see the torus half cut into the environment triangle
and if I set the value to 0.99 then I fully see the torus in front of the background.
Same for 0.99999997, but 0.99999998 to 1.0 makes the background disappear.
In the debugger, this is what 0.99999997 looks like:
Thank you for providing more detail. It’s still very hard for me to see what’s going on and test out possible answers. You aren’t able to upload a small zip file?
Have you experimented with different depth stencil states?
Remember that NDC (Normalised device coordinates) for Metal are -1 to 1 in the x and y axes and 0 to 1 in the z axis.
This means that if something is positioned at z = 0.98 and the w is 1, it will be very close to the far position. If something is positioned at z = 98 and the w is 100, it will be at the same position. (Divide by w happens after the vertex function.)