From f89da17f1778947fa2b3c4e543f3da3429578440 Mon Sep 17 00:00:00 2001 From: Ian Curtis Date: Fri, 27 Oct 2023 10:45:16 +0100 Subject: [PATCH] Fix white gfx on linux / intel gpus. These optimisations originally came from toxieainc --- Src/Graphics/New3D/R3DShaderCommon.h | 10 ++++++++++ Src/Graphics/New3D/R3DShaderQuads.h | 16 ++++------------ Src/Graphics/New3D/R3DShaderTriangles.h | 7 ++++--- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/Src/Graphics/New3D/R3DShaderCommon.h b/Src/Graphics/New3D/R3DShaderCommon.h index b449dee..df12c1b 100644 --- a/Src/Graphics/New3D/R3DShaderCommon.h +++ b/Src/Graphics/New3D/R3DShaderCommon.h @@ -337,6 +337,16 @@ float CalcFog() return fog; } +float Sqr(float a) +{ + return a*a; +} + +float SqrLength(vec2 a) +{ + return a.x*a.x + a.y*a.y; +} + void WriteOutputs(vec4 colour, int layer) { vec4 blank = vec4(0.0); diff --git a/Src/Graphics/New3D/R3DShaderQuads.h b/Src/Graphics/New3D/R3DShaderQuads.h index df3387e..cf7ae90 100644 --- a/Src/Graphics/New3D/R3DShaderQuads.h +++ b/Src/Graphics/New3D/R3DShaderQuads.h @@ -249,6 +249,8 @@ float CalcFog(); void Step15Luminous(inout vec4 colour); vec4 GetTextureValue(); void WriteOutputs(vec4 colour, int layer); +float Sqr(float a); +float SqrLength(vec2 a); void QuadraticInterpolation() { @@ -354,16 +356,6 @@ void QuadraticInterpolation() gl_FragDepth = depth * 0.5 + 0.5; } -float sqr(float a) -{ - return a*a; -} - -float sqr_length(vec2 a) -{ - return a.x*a.x + a.y*a.y; -} - void main() { vec4 tex1Data; @@ -389,7 +381,7 @@ void main() } float ellipse; - ellipse = sqr_length((gl_FragCoord.xy - spotEllipse.xy) / spotEllipse.zw); // decay rate = square of distance from center + ellipse = SqrLength((gl_FragCoord.xy - spotEllipse.xy) / spotEllipse.zw); // decay rate = square of distance from center ellipse = 1.0 - ellipse; // invert ellipse = max(0.0, ellipse); // clamp @@ -414,7 +406,7 @@ void main() // inverse-linear falloff // Reference: https://imdoingitwrong.wordpress.com/2011/01/31/light-attenuation/ // y = 1 / (d/r + 1)^2 - range = 1.0 / sqr(d * inv_r - 1.0); + range = 1.0 / Sqr(d * inv_r - 1.0); range *= enable; } diff --git a/Src/Graphics/New3D/R3DShaderTriangles.h b/Src/Graphics/New3D/R3DShaderTriangles.h index e79638a..85f3037 100644 --- a/Src/Graphics/New3D/R3DShaderTriangles.h +++ b/Src/Graphics/New3D/R3DShaderTriangles.h @@ -122,6 +122,8 @@ float CalcFog(); void Step15Luminous(inout vec4 colour); vec4 GetTextureValue(); void WriteOutputs(vec4 colour, int layer); +float Sqr(float a); +float SqrLength(vec2 a); void main() { @@ -150,8 +152,7 @@ void main() } float ellipse; - ellipse = length((gl_FragCoord.xy - spotEllipse.xy) / spotEllipse.zw); - ellipse = pow(ellipse, 2.0); // decay rate = square of distance from center + ellipse = SqrLength((gl_FragCoord.xy - spotEllipse.xy) / spotEllipse.zw); // decay rate = square of distance from center ellipse = 1.0 - ellipse; // invert ellipse = max(0.0, ellipse); // clamp @@ -176,7 +177,7 @@ void main() // inverse-linear falloff // Reference: https://imdoingitwrong.wordpress.com/2011/01/31/light-attenuation/ // y = 1 / (d/r + 1)^2 - range = 1.0 / pow(d * inv_r - 1.0, 2.0); + range = 1.0 / Sqr(d * inv_r - 1.0); range *= enable; }