From 72ae17123314e96c86e46ffd31426f1ed4a308a1 Mon Sep 17 00:00:00 2001 From: havoc Date: Sun, 6 Aug 2017 15:33:55 +0000 Subject: [PATCH] Use the invariant keyword on gl_Position on GLSL 1.20 or higher and GLSL ES 1.00 or higher, this should resolve zfighting between light polygons and base surfaces. A long long time ago this was using ftransform() which ensured invariance but use of the invariant keyword was not added when we switched away from that. Thanks for the bug report: https://www.reddit.com/r/quake/comments/6rwwm5/need_some_help_getting_quake_running_with/ git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12336 d7cf8633-e32d-0410-b094-e92efae38249 --- gl_rmain.c | 21 +++++++++++++++++++++ shader_glsl.h | 3 +++ 2 files changed, 24 insertions(+) diff --git a/gl_rmain.c b/gl_rmain.c index 92e0d76c..6a316432 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -1115,6 +1115,27 @@ static void R_GLSL_CompilePermutation(r_glsl_permutation_t *p, unsigned int mode geomstrings_list[geomstrings_count++] = "#define GLSL130\n"; fragstrings_list[fragstrings_count++] = "#define GLSL130\n"; } + // if we can do #version 120, we should (this adds the invariant keyword) + else if(vid.support.glshaderversion >= 120) + { + vertstrings_list[vertstrings_count++] = "#version 120\n"; + geomstrings_list[geomstrings_count++] = "#version 120\n"; + fragstrings_list[fragstrings_count++] = "#version 120\n"; + vertstrings_list[vertstrings_count++] = "#define GLSL120\n"; + geomstrings_list[geomstrings_count++] = "#define GLSL120\n"; + fragstrings_list[fragstrings_count++] = "#define GLSL120\n"; + } + // GLES also adds several things from GLSL120 + switch(vid.renderpath) + { + case RENDERPATH_GLES2: + vertstrings_list[vertstrings_count++] = "#define GLES\n"; + geomstrings_list[geomstrings_count++] = "#define GLES\n"; + fragstrings_list[fragstrings_count++] = "#define GLES\n"; + break; + default: + break; + } // the first pretext is which type of shader to compile as // (later these will all be bound together as a program object) diff --git a/shader_glsl.h b/shader_glsl.h index 90d5d770..f9be074e 100644 --- a/shader_glsl.h +++ b/shader_glsl.h @@ -37,6 +37,9 @@ "# endif\n", "#endif\n", "\n", +"#if defined(GLSL120) || defined(GLSL130) || defined(GLSL140) || defined(GLES)\n" +"invariant gl_Position; // fix for lighting polygons not matching base surface\n", +"# endif\n", "#if defined(GLSL130) || defined(GLSL140)\n", "precision highp float;\n", "# ifdef VERTEX_SHADER\n", -- 2.39.2