From 8ff71aeb156161bb11bb7bda713fccba027c68a9 Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 3 Nov 2024 23:58:28 +0100 Subject: [PATCH] webgl: Fix precision issues with default shaders --- .../src/glstuff/glGraphicsStateGuardian_src.cxx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index 51e3b80f7b..1b3326a78c 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -189,16 +189,22 @@ static const string default_vshader = "in vec4 p3d_MultiTexCoord0;\n" "out vec3 texcoord;\n" "out vec4 color;\n" + "uniform mat4 p3d_ModelViewProjectionMatrix;\n" #else "#version 100\n" "precision mediump float;\n" "attribute vec4 p3d_Vertex;\n" "attribute vec4 p3d_Color;\n" "attribute vec4 p3d_MultiTexCoord0;\n" - "varying vec3 texcoord;\n" "varying lowp vec4 color;\n" -#endif + "#ifdef GL_FRAGMENT_PRECISION_HIGH\n" + "varying highp vec3 texcoord;\n" + "uniform highp mat4 p3d_ModelViewProjectionMatrix;\n" + "#else\n" + "varying mediump vec3 texcoord;\n" "uniform mat4 p3d_ModelViewProjectionMatrix;\n" + "#endif\n" +#endif "uniform mat4 p3d_TextureMatrix;\n" "uniform vec4 p3d_ColorScale;\n" "void main(void) {\n" @@ -266,7 +272,11 @@ static const string default_fshader = #else "#version 100\n" "precision mediump float;\n" - "varying vec3 texcoord;\n" + "#ifdef GL_FRAGMENT_PRECISION_HIGH\n" + "varying highp vec3 texcoord;\n" + "#else\n" + "varying mediump vec3 texcoord;\n" + "#endif\n" "varying lowp vec4 color;\n" "uniform lowp sampler2D p3d_Texture0;\n" "uniform lowp vec4 p3d_TexAlphaOnly;\n"