From e346c3f8076f2a8e123168e98ecdced98c727b1c Mon Sep 17 00:00:00 2001 From: bjorn Date: Sun, 28 Mar 2021 10:08:10 -0600 Subject: [PATCH] Fix standard shader precision issues; - Reduce epsilon - Also use epsilon in D_GGX - Reduce shader string length to the minimum required supported length --- src/resources/shaders.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/resources/shaders.c b/src/resources/shaders.c index 26ad6cd8..60817af6 100644 --- a/src/resources/shaders.c +++ b/src/resources/shaders.c @@ -184,10 +184,10 @@ const char* lovrStandardVertexShader = "" const char* lovrStandardFragmentShader = "" "#define PI 3.14159265358979 \n" -"#ifdef GL_ES \n" -"#define EPS 1e-2 \n" +"#if defined(GL_ES) && !defined(FLAG_highp) \n" +"#define EPS 1e-4 \n" "#else \n" -"#define EPS 1e-5 \n" +"#define EPS 1e-8 \n" "#endif \n" "in vec3 vVertexPositionWorld; \n" @@ -271,7 +271,7 @@ const char* lovrStandardFragmentShader = "" " float alpha = roughness * roughness; \n" " float alpha2 = alpha * alpha; \n" " float denom = (NoH * NoH) * (alpha2 - 1.) + 1.; \n" -" return alpha2 / (PI * denom * denom); \n" +" return alpha2 / max(PI * denom * denom, EPS); \n" "} \n" "float G_SmithGGXCorrelated(float NoV, float NoL, float roughness) { \n" @@ -287,7 +287,7 @@ const char* lovrStandardFragmentShader = "" "} \n" "vec3 E_SphericalHarmonics(vec3 sh[9], vec3 n) { \n" -" n = -n; // WHY \n" +" n = -n; \n" " return max(" "sh[0] + " "sh[1] * n.y + " @@ -310,13 +310,13 @@ const char* lovrStandardFragmentShader = "" " return vec2(-1.04, 1.04) * a004 + r.zw; \n" "} \n" -"vec3 tonemap_ACES(vec3 color) { \n" +"vec3 tonemap_ACES(vec3 x) { \n" " float a = 2.51; \n" " float b = 0.03; \n" " float c = 2.43; \n" " float d = 0.59; \n" " float e = 0.14; \n" -" return (color * (a * color + b)) / (color * (c * color + d) + e); \n" +" return (x * (a * x + b)) / (x * (c * x + d) + e); \n" "}"; const char* lovrCubeVertexShader = ""