Improve Skybox eyeDirection precision (#7685)

This commit is contained in:
Ben Doherty
2024-03-22 12:03:06 -07:00
committed by GitHub
parent d2ce714e73
commit 9aaaad9271
+10 -1
View File
@@ -58,6 +58,15 @@ fragment {
vertex {
void materialVertex(inout MaterialVertexInputs material) {
material.eyeDirection.xyz = material.worldPosition.xyz;
// This code is taken from computeWorldPosition and assumes the vertex domain is 'device'.
vec4 p = getPosition();
// GL convention to inverted DX convention
p.z = p.z * -0.5 + 0.5;
vec4 worldPosition = getWorldFromClipMatrix() * p;
// Getting the true world position would require dividing by w, but since this is a skybox
// at inifinity, this results in very large numbers for material.eyeDirection.
// Since the eyeDirection is only used as a direction vector in the fragment shader, we can
// skip that step to improve precision.
material.eyeDirection.xyz = worldPosition.xyz;
}
}