From a3e2fb790603f8cdbcee2f21ba352fd51bdefc39 Mon Sep 17 00:00:00 2001 From: Ian Curtis Date: Wed, 6 Sep 2017 13:07:39 +0000 Subject: [PATCH] Calculating the length of the vertex results in quite broken values for fogging when the vertices are traversing the view frustum. The hardware also wouldn't have been doing a square root per vertex for fogging. Simply using the z values is enough. Todo check clamping of values for the near/far planes. --- Src/Graphics/New3D/R3DShader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Graphics/New3D/R3DShader.cpp b/Src/Graphics/New3D/R3DShader.cpp index b7cbc97..63c217f 100644 --- a/Src/Graphics/New3D/R3DShader.cpp +++ b/Src/Graphics/New3D/R3DShader.cpp @@ -43,7 +43,7 @@ void main(void) { fsViewVertex = vec3(gl_ModelViewMatrix * inVertex); fsViewNormal = (mat3(gl_ModelViewMatrix) * inNormal) / modelScale; - float z = length(fsViewVertex); + float z = -fsViewVertex.z; fsFogFactor = fogIntensity * clamp(fogStart + z * fogDensity, 0.0, 1.0); fsDiscard = CalcBackFace(fsViewVertex);