From 292e91970442e2e16009ad1d07cbe38d2aff2e0a Mon Sep 17 00:00:00 2001 From: Salvador Cipolla Date: Tue, 26 May 2026 20:15:21 -0300 Subject: [PATCH 01/11] gles changes --- code/def_files/data/effects/batched-f.sdr | 7 ++- code/def_files/data/effects/batched-v.sdr | 5 ++ code/def_files/data/effects/bloom-comp-f.sdr | 7 ++- code/def_files/data/effects/blur-f.sdr | 8 ++- code/def_files/data/effects/brightpass-f.sdr | 8 ++- code/def_files/data/effects/copy-f.sdr | 11 +++- code/def_files/data/effects/decal-f.sdr | 23 +++++-- code/def_files/data/effects/decal-v.sdr | 6 ++ .../data/effects/default-material-f.sdr | 59 ++++++++++++++++++ .../data/effects/default-material-v.sdr | 43 +++++++++++++ .../data/effects/default-material.frag | 44 ++++++++++++++ .../effects/default-material.frag.spv.glsl | 60 +++++++++++++++++++ .../data/effects/default-material.vert | 44 ++++++++++++++ .../effects/default-material.vert.spv.glsl | 44 ++++++++++++++ .../data/effects/deferred-clear-f.sdr | 19 ++++-- code/def_files/data/effects/deferred-f.sdr | 34 ++++++++--- code/def_files/data/effects/deferred-v.sdr | 7 +++ .../data/effects/effect-distort-f.sdr | 16 ++++- .../data/effects/effect-distort-v.sdr | 7 +++ code/def_files/data/effects/effect-f.sdr | 14 ++++- code/def_files/data/effects/effect-g.sdr | 8 +++ code/def_files/data/effects/effect-v.sdr | 7 +++ .../data/effects/envmap-sphere-warp-f.sdr | 8 ++- code/def_files/data/effects/fog-f.sdr | 11 +++- code/def_files/data/effects/fxaa-f.sdr | 18 +++++- code/def_files/data/effects/fxaa-v.sdr | 8 +++ code/def_files/data/effects/fxaapre-f.sdr | 8 ++- code/def_files/data/effects/irrmap-f.sdr | 18 ++++-- code/def_files/data/effects/lighting.sdr | 6 +- code/def_files/data/effects/ls-f.sdr | 7 ++- code/def_files/data/effects/main-f.sdr | 28 +++++++-- code/def_files/data/effects/main-g.sdr | 41 +++++++++++-- code/def_files/data/effects/main-v.sdr | 38 +++++++++--- code/def_files/data/effects/msaa-f.sdr | 20 ++++--- code/def_files/data/effects/nanovg-f.sdr | 6 ++ code/def_files/data/effects/nanovg-v.sdr | 6 ++ code/def_files/data/effects/normals.sdr | 2 +- code/def_files/data/effects/passthrough-f.sdr | 7 ++- code/def_files/data/effects/post-f.sdr | 9 ++- code/def_files/data/effects/rocketui-f.sdr | 8 ++- code/def_files/data/effects/rocketui-v.sdr | 6 ++ .../data/effects/shield-impact-f.sdr | 12 +++- .../data/effects/shield-impact-v.sdr | 6 ++ code/def_files/data/effects/smaa-blend-f.sdr | 8 ++- code/def_files/data/effects/smaa-blend-v.sdr | 6 ++ code/def_files/data/effects/smaa-edge-f.sdr | 8 ++- code/def_files/data/effects/smaa-edge-v.sdr | 6 ++ .../data/effects/smaa-neighbour-f.sdr | 8 ++- .../data/effects/smaa-neighbour-v.sdr | 6 ++ code/def_files/data/effects/tonemapping-f.sdr | 8 ++- code/def_files/data/effects/video-f.sdr | 9 ++- code/def_files/data/effects/volumetric-f.sdr | 8 ++- 52 files changed, 744 insertions(+), 77 deletions(-) create mode 100644 code/def_files/data/effects/default-material-f.sdr create mode 100644 code/def_files/data/effects/default-material-v.sdr create mode 100644 code/def_files/data/effects/default-material.frag create mode 100644 code/def_files/data/effects/default-material.frag.spv.glsl create mode 100644 code/def_files/data/effects/default-material.vert create mode 100644 code/def_files/data/effects/default-material.vert.spv.glsl diff --git a/code/def_files/data/effects/batched-f.sdr b/code/def_files/data/effects/batched-f.sdr index 82239181efa..1690e68b3ee 100644 --- a/code/def_files/data/effects/batched-f.sdr +++ b/code/def_files/data/effects/batched-f.sdr @@ -1,10 +1,15 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2DArray; +#endif #include "gamma.sdr" in vec4 fragTexCoord; in vec4 fragColor; -out vec4 fragOut0; +layout(location=0) out vec4 fragOut0; uniform sampler2DArray baseMap; diff --git a/code/def_files/data/effects/batched-v.sdr b/code/def_files/data/effects/batched-v.sdr index 499ed2a6a0f..9a9c9b4bf27 100644 --- a/code/def_files/data/effects/batched-v.sdr +++ b/code/def_files/data/effects/batched-v.sdr @@ -1,3 +1,8 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +#endif + in vec4 vertPosition; in vec4 vertTexCoord; in vec4 vertColor; diff --git a/code/def_files/data/effects/bloom-comp-f.sdr b/code/def_files/data/effects/bloom-comp-f.sdr index bc502b31313..74d85c2cc2b 100644 --- a/code/def_files/data/effects/bloom-comp-f.sdr +++ b/code/def_files/data/effects/bloom-comp-f.sdr @@ -1,7 +1,12 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +#endif in vec4 fragTexCoord; -out vec4 fragOut0; +layout(location=0) out vec4 fragOut0; uniform sampler2D bloomed; diff --git a/code/def_files/data/effects/blur-f.sdr b/code/def_files/data/effects/blur-f.sdr index b170964a627..7758227f9de 100644 --- a/code/def_files/data/effects/blur-f.sdr +++ b/code/def_files/data/effects/blur-f.sdr @@ -1,4 +1,10 @@ -out vec4 fragOut0; +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +#endif + +layout (location=0) out vec4 fragOut0; in vec4 fragTexCoord; diff --git a/code/def_files/data/effects/brightpass-f.sdr b/code/def_files/data/effects/brightpass-f.sdr index d92f74e5f9f..6ee339f4739 100644 --- a/code/def_files/data/effects/brightpass-f.sdr +++ b/code/def_files/data/effects/brightpass-f.sdr @@ -1,5 +1,11 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +#endif + in vec4 fragTexCoord; -out vec4 fragOut0; +layout(location=0) out vec4 fragOut0; uniform sampler2D tex; const float Luminance = 0.08; const float fMiddleGray = 0.2; diff --git a/code/def_files/data/effects/copy-f.sdr b/code/def_files/data/effects/copy-f.sdr index 6c0b8d74781..c8dc600f395 100644 --- a/code/def_files/data/effects/copy-f.sdr +++ b/code/def_files/data/effects/copy-f.sdr @@ -1,5 +1,12 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +#endif + in vec4 fragTexCoord; -out vec4 fragOut0; +layout(location=0) out vec4 fragOut0; #ifdef COPY_ARRAY uniform sampler2DArray tex; @@ -10,7 +17,7 @@ uniform sampler2D tex; void main() { #ifdef COPY_ARRAY - fragOut0 = texture(tex, vec3(fragTexCoord.xy, 0)); + fragOut0 = texture(tex, vec3(fragTexCoord.xy, 0.0)); #else fragOut0 = texture(tex, fragTexCoord.xy); #endif diff --git a/code/def_files/data/effects/decal-f.sdr b/code/def_files/data/effects/decal-f.sdr index 138caae0ec5..9a44cc60e0e 100644 --- a/code/def_files/data/effects/decal-f.sdr +++ b/code/def_files/data/effects/decal-f.sdr @@ -1,3 +1,9 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +#endif // NOTE: The technique and some of this code is based on this tutorial: // http://martindevans.me/game-development/2015/02/27/Drawing-Stuff-On-Other-Stuff-With-Deferred-Screenspace-Decals/ @@ -6,9 +12,9 @@ #include "normals.sdr" #include "gamma.sdr" -out vec4 fragOut0; // Diffuse buffer -out vec4 fragOut1; // Normal buffer -out vec4 fragOut2; // Emissive buffer +layout (location=0) out vec4 fragOut0; // Diffuse buffer -> COLOR_ATTACHMENT0 +layout (location=2) out vec4 fragOut1; // Normal buffer -> COLOR_ATTACHMENT2 +layout (location=4) out vec4 fragOut2; // Emissive buffer -> COLOR_ATTACHMENT4 flat in mat4 invModelMatrix; flat in vec3 decalDirection; @@ -16,12 +22,21 @@ flat in float normal_angle_cutoff; flat in float angle_fade_start; flat in float alpha_scale; +#ifdef GL_ES +uniform highp sampler2D gDepthBuffer; +uniform highp sampler2D gNormalBuffer; + +uniform highp sampler2DArray diffuseMap; +uniform highp sampler2DArray glowMap; +uniform highp sampler2DArray normalMap; +#else uniform sampler2D gDepthBuffer; uniform sampler2D gNormalBuffer; uniform sampler2DArray diffuseMap; uniform sampler2DArray glowMap; uniform sampler2DArray normalMap; +#endif layout (std140) uniform decalGlobalData { mat4 viewMatrix; @@ -82,7 +97,7 @@ vec3 getPixelNormal(vec3 frag_position, vec2 tex_coord, inout float alpha, out v } // Make a smooth alpha transition leading up to an edge - alpha = alpha * (1 - smoothstep(angle_fade_start, normal_angle_cutoff, angle)); + alpha = alpha * (1.0 - smoothstep(angle_fade_start, normal_angle_cutoff, angle)); return normal; } diff --git a/code/def_files/data/effects/decal-v.sdr b/code/def_files/data/effects/decal-v.sdr index bd3511e0c7e..61b82cfe4b7 100644 --- a/code/def_files/data/effects/decal-v.sdr +++ b/code/def_files/data/effects/decal-v.sdr @@ -1,3 +1,9 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +#endif in vec4 vertPosition; in mat4 vertModelMatrix; diff --git a/code/def_files/data/effects/default-material-f.sdr b/code/def_files/data/effects/default-material-f.sdr new file mode 100644 index 00000000000..a9eb480f9c5 --- /dev/null +++ b/code/def_files/data/effects/default-material-f.sdr @@ -0,0 +1,59 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +#endif + +layout(std140) uniform genericData +{ + mat4 modelMatrix; + vec4 color; + vec4 clipEquation; + int baseMapIndex; + int alphaTexture; + int noTexturing; + int srgb; + float intensity; + float alphaThreshold; + uint clipEnabled; +} _39; + +uniform sampler2DArray baseMap; +in highp float vClipDist; +in vec4 fragTexCoord; +in vec4 fragColor; +layout (location=0) out vec4 fragOut0; + +void main() +{ + if (_39.clipEnabled != 0u && vClipDist < 0.0) { + discard; + } + vec4 _48 = texture(baseMap, vec3(fragTexCoord.xy, float(_39.baseMapIndex))); + if (_39.alphaThreshold > _48.w) + { + discard; + } + bool _66 = _39.srgb == 1; + vec3 _146; + if (_66) + { + _146 = pow(_48.xyz, vec3(2.2000000476837158203125)); + } + else + { + _146 = _48.xyz; + } + vec4 _148; + if (_66) + { + _148 = vec4(pow(fragColor.xyz, vec3(2.2000000476837158203125)), fragColor.w); + } + else + { + _148 = fragColor; + } + fragOut0 = mix(mix(vec4(_146.x, _146.y, _146.z, _48.w) * _148, vec4(_148.xyz, _146.x * _148.w), vec4(float(_39.alphaTexture))), _148, vec4(float(_39.noTexturing))) * _39.intensity; +} + diff --git a/code/def_files/data/effects/default-material-v.sdr b/code/def_files/data/effects/default-material-v.sdr new file mode 100644 index 00000000000..ebedb5900d3 --- /dev/null +++ b/code/def_files/data/effects/default-material-v.sdr @@ -0,0 +1,43 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +#endif + +layout(std140) uniform genericData +{ + mat4 modelMatrix; + vec4 color; + vec4 clipEquation; + int baseMapIndex; + int alphaTexture; + int noTexturing; + int srgb; + float intensity; + float alphaThreshold; + uint clipEnabled; +} _22; + +layout(std140) uniform matrixData +{ + mat4 modelViewMatrix; + mat4 projMatrix; +} _36; + +out vec4 fragTexCoord; +in vec4 vertTexCoord; +out vec4 fragColor; +in vec4 vertColor; +in vec4 vertPosition; +out float vClipDist; + +void main() +{ + fragTexCoord = vertTexCoord; + fragColor = vertColor * _22.color; + gl_Position = (_36.projMatrix * _36.modelViewMatrix) * vertPosition; + float d = dot(_22.clipEquation, _22.modelMatrix * vertPosition); + vClipDist = (_22.clipEnabled != 0u) ? d : 1.0; +} + diff --git a/code/def_files/data/effects/default-material.frag b/code/def_files/data/effects/default-material.frag new file mode 100644 index 00000000000..1966a11331a --- /dev/null +++ b/code/def_files/data/effects/default-material.frag @@ -0,0 +1,44 @@ +#version 320 es +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +#endif + +#include "gamma.sdr" + +layout (binding = 0) in vec4 fragTexCoord; +layout (binding = 1) in vec4 fragColor; + +layout (location = 0) out vec4 fragOut0; + +layout (std140) uniform genericData { + mat4 modelMatrix; + vec4 color; + vec4 clipEquation; + int baseMapIndex; + int alphaTexture; + int noTexturing; + int srgb; + float intensity; + float alphaThreshold; + uint clipEnabled; +}; + +in float vClipDist; + +layout(binding = 2) uniform sampler2DArray baseMap; + +void main() +{ + if (clipEnabled != uint(0) && vClipDist < 0.0) { + discard; + } + + vec4 baseColor = texture(baseMap, vec3(fragTexCoord.xy, float(baseMapIndex))); + if(alphaThreshold > baseColor.a) discard; + baseColor.rgb = (srgb == 1) ? srgb_to_linear(baseColor.rgb) : baseColor.rgb; + vec4 blendColor = (srgb == 1) ? vec4(srgb_to_linear(fragColor.rgb), fragColor.a) : fragColor; + fragOut0 = mix(mix(baseColor * blendColor, vec4(blendColor.rgb, baseColor.r * blendColor.a), float(alphaTexture)), blendColor, float(noTexturing)) * intensity; +} diff --git a/code/def_files/data/effects/default-material.frag.spv.glsl b/code/def_files/data/effects/default-material.frag.spv.glsl new file mode 100644 index 00000000000..aecc64db179 --- /dev/null +++ b/code/def_files/data/effects/default-material.frag.spv.glsl @@ -0,0 +1,60 @@ +#version 320 es +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +#endif + +layout(std140) uniform genericData +{ + mat4 modelMatrix; + vec4 color; + vec4 clipEquation; + int baseMapIndex; + int alphaTexture; + int noTexturing; + int srgb; + float intensity; + float alphaThreshold; + uint clipEnabled; +} _39; + +uniform sampler2DArray baseMap; +in highp float vClipDist; +in vec4 fragTexCoord; +in vec4 fragColor; +layout (location=0) out vec4 fragOut0; + +void main() +{ + if (_39.clipEnabled != 0u && vClipDist < 0.0) { + discard; + } + vec4 _48 = texture(baseMap, vec3(fragTexCoord.xy, float(_39.baseMapIndex))); + if (_39.alphaThreshold > _48.w) + { + discard; + } + bool _66 = _39.srgb == 1; + vec3 _146; + if (_66) + { + _146 = pow(_48.xyz, vec3(2.2000000476837158203125)); + } + else + { + _146 = _48.xyz; + } + vec4 _148; + if (_66) + { + _148 = vec4(pow(fragColor.xyz, vec3(2.2000000476837158203125)), fragColor.w); + } + else + { + _148 = fragColor; + } + fragOut0 = mix(mix(vec4(_146.x, _146.y, _146.z, _48.w) * _148, vec4(_148.xyz, _146.x * _148.w), vec4(float(_39.alphaTexture))), _148, vec4(float(_39.noTexturing))) * _39.intensity; +} + diff --git a/code/def_files/data/effects/default-material.vert b/code/def_files/data/effects/default-material.vert new file mode 100644 index 00000000000..a861459e2d3 --- /dev/null +++ b/code/def_files/data/effects/default-material.vert @@ -0,0 +1,44 @@ +#version 320 es +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +#endif + +layout (location = 0) in vec4 vertPosition; +layout (location = 1) in vec4 vertColor; +layout (location = 2) in vec4 vertTexCoord; + +layout (location = 0) out vec4 fragTexCoord; +layout (location = 1) out vec4 fragColor; + +layout (binding = 0, std140) uniform matrixData { + mat4 modelViewMatrix; + mat4 projMatrix; +}; + +layout (binding = 1, std140) uniform genericData { + mat4 modelMatrix; + vec4 color; + vec4 clipEquation; + int baseMapIndex; + int alphaTexture; + int noTexturing; + int srgb; + float intensity; + float alphaThreshold; + uint clipEnabled; +}; + +out float vClipDist; + +void main() +{ + fragTexCoord = vertTexCoord; + fragColor = vertColor * color; + gl_Position = projMatrix * modelViewMatrix * vertPosition; + + float d = dot(clipEquation, modelMatrix * vertPosition); + vClipDist = (clipEnabled != uint(0)) ? d : 1.0; +} diff --git a/code/def_files/data/effects/default-material.vert.spv.glsl b/code/def_files/data/effects/default-material.vert.spv.glsl new file mode 100644 index 00000000000..42f0842200a --- /dev/null +++ b/code/def_files/data/effects/default-material.vert.spv.glsl @@ -0,0 +1,44 @@ +#version 320 es +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +#endif + +layout(std140) uniform genericData +{ + mat4 modelMatrix; + vec4 color; + vec4 clipEquation; + int baseMapIndex; + int alphaTexture; + int noTexturing; + int srgb; + float intensity; + float alphaThreshold; + uint clipEnabled; +} _22; + +layout(std140) uniform matrixData +{ + mat4 modelViewMatrix; + mat4 projMatrix; +} _36; + +out vec4 fragTexCoord; +in vec4 vertTexCoord; +out vec4 fragColor; +in vec4 vertColor; +in vec4 vertPosition; +out float vClipDist; + +void main() +{ + fragTexCoord = vertTexCoord; + fragColor = vertColor * _22.color; + gl_Position = (_36.projMatrix * _36.modelViewMatrix) * vertPosition; + float d = dot(_22.clipEquation, _22.modelMatrix * vertPosition); + vClipDist = (_22.clipEnabled != 0u) ? d : 1.0; +} + diff --git a/code/def_files/data/effects/deferred-clear-f.sdr b/code/def_files/data/effects/deferred-clear-f.sdr index 4d49695ef90..79e8c06cc5f 100644 --- a/code/def_files/data/effects/deferred-clear-f.sdr +++ b/code/def_files/data/effects/deferred-clear-f.sdr @@ -1,9 +1,16 @@ -out vec4 fragOut0; -out vec4 fragOut1; -out vec4 fragOut2; -out vec4 fragOut3; -out vec4 fragOut4; -out vec4 fragOut5; +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +#endif + +layout (location=0) out vec4 fragOut0; +layout (location=1) out vec4 fragOut1; +layout (location=2) out vec4 fragOut2; +layout (location=3) out vec4 fragOut3; +layout (location=4) out vec4 fragOut4; +layout (location=5) out vec4 fragOut5; void main() { fragOut0 = vec4(0.0, 0.0, 0.0, 1.0); // color diff --git a/code/def_files/data/effects/deferred-f.sdr b/code/def_files/data/effects/deferred-f.sdr index 748432a009b..8da2612d3bd 100644 --- a/code/def_files/data/effects/deferred-f.sdr +++ b/code/def_files/data/effects/deferred-f.sdr @@ -1,10 +1,23 @@ //? #version 150 +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +precision highp samplerCube; +#endif + #include "lighting.sdr" //! #include "lighting.sdr" #include "gamma.sdr" //! #include "gamma.sdr" #include "shadows.sdr" //! #include "shadows.sdr" #include "z-compress.sdr" //! #include "z-compress.sdr" -out vec4 fragOut0; +layout(location = 0) out vec4 fragOut0; +layout(location = 1) out vec4 fragOut1; +layout(location = 2) out vec4 fragOut2; +layout(location = 3) out vec4 fragOut3; +layout(location = 4) out vec4 fragOut4; +layout(location = 5) out vec4 fragOut5; uniform sampler2D ColorBuffer; uniform sampler2D NormalBuffer; @@ -93,7 +106,7 @@ void GetLightInfo(vec3 position, in float alpha, in vec3 reflectDir, out vec3 li lightDirOut = ExpandLightSize(lightDirOut, reflectDir); dist = length(lightDirOut); // Energy conservation term - float alpha_adjust = clamp(alpha + (sourceRadius/(2*dist)), 0.0, 1.0); + float alpha_adjust = clamp(alpha + (sourceRadius/(2.0*dist)), 0.0, 1.0); area_normalisation = alpha/alpha_adjust; area_normalisation *= area_normalisation; //end chunk @@ -135,7 +148,7 @@ void GetLightInfo(vec3 position, in float alpha, in vec3 reflectDir, out vec3 li lightDirOut = ExpandLightSize(lightDirOut, reflectDir); float dist = length(lightDirOut); // Energy conservation term - float alpha_adjust = min(alpha + (sourceRadius/(2*dist)), 1.0); + float alpha_adjust = min(alpha + (sourceRadius/(2.0*dist)), 1.0); area_normalisation = alpha/alpha_adjust; // don't need to square as it's a line rather than a sphere. //end chunk @@ -181,11 +194,11 @@ void ComputeEnvLight(float alpha, float ao, vec3 light_dir, vec3 eyeDir, vec3 no // so let s = (2/alpha^2 - 2) // 1/2 log(s + 1) = 1/2 log(2/alpha^2 -1) - const float ENV_REZ = 512; // Ideally this would be #define'd and shader recompiled with envmap rez changes - const float REZ_BIAS = log2(ENV_REZ * sqrt(3)); + const float ENV_REZ = 512.0; // Ideally this would be #define'd and shader recompiled with envmap rez changes + const float REZ_BIAS = log2(ENV_REZ * sqrt(3.0)); float alphaSqr = alpha * alpha; - float rough_bias = 0.5 * log2(2/alphaSqr - 1); + float rough_bias = 0.5 * log2(2.0/alphaSqr - 1.0); float mip_bias = REZ_BIAS - rough_bias; // Sample light, using mip bias to blur it. @@ -203,7 +216,7 @@ void ComputeEnvLight(float alpha, float ao, vec3 light_dir, vec3 eyeDir, vec3 no // Pseudo-IBL, so use k_IBL float k = alpha * alpha/ 2.0f; - float NdotL = max(dot(light_dir, normal),0); + float NdotL = max(dot(light_dir, normal),0.0); float g1vNL = GeometrySchlickGGX(NdotL, k); vec3 specEnvLighting = specEnvColour.rgb * fresnel * g1vNL; @@ -273,6 +286,11 @@ void main() float NdotL = clamp(dot(normal, lightDir), 0.0, 1.0); fragmentColor.rgb = computeLighting(specColor.rgb, diffColor, lightDir, normal.xyz, halfVec, eyeDir, roughness, fresnel, NdotL).rgb * diffuseLightColor * attenuation * area_normalisation; } + + #ifdef GL_ES + fragOut5 = max(fragmentColor, vec4(0.0)); + #else + fragOut0 = max(fragmentColor, vec4(0.0)); + #endif - fragOut0 = max(fragmentColor, vec4(0.0)); } diff --git a/code/def_files/data/effects/deferred-v.sdr b/code/def_files/data/effects/deferred-v.sdr index f1633569875..dac952b3713 100644 --- a/code/def_files/data/effects/deferred-v.sdr +++ b/code/def_files/data/effects/deferred-v.sdr @@ -1,3 +1,10 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +precision highp samplerCube; +#endif #include "lighting.sdr" diff --git a/code/def_files/data/effects/effect-distort-f.sdr b/code/def_files/data/effects/effect-distort-f.sdr index dc030e63067..fb4ccecf7fa 100644 --- a/code/def_files/data/effects/effect-distort-f.sdr +++ b/code/def_files/data/effects/effect-distort-f.sdr @@ -1,13 +1,27 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +#endif + in vec4 fragTexCoord; in vec4 fragColor; in float fragOffset; -out vec4 fragOut0; +layout(location=0) out vec4 fragOut0; +#ifdef GL_ES +uniform highp sampler2DArray baseMap; +uniform highp sampler2D depthMap; +uniform highp sampler2D distMap; +uniform highp sampler2D frameBuffer; +#else uniform sampler2DArray baseMap; uniform sampler2D depthMap; uniform sampler2D distMap; uniform sampler2D frameBuffer; +#endif layout (std140) uniform genericData { float window_width; diff --git a/code/def_files/data/effects/effect-distort-v.sdr b/code/def_files/data/effects/effect-distort-v.sdr index 02c4790b8ab..9127a1c1f2c 100644 --- a/code/def_files/data/effects/effect-distort-v.sdr +++ b/code/def_files/data/effects/effect-distort-v.sdr @@ -1,3 +1,10 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +#endif + in vec4 vertPosition; in vec4 vertTexCoord; in vec4 vertColor; diff --git a/code/def_files/data/effects/effect-f.sdr b/code/def_files/data/effects/effect-f.sdr index 40ac90bce92..b201009f51e 100644 --- a/code/def_files/data/effects/effect-f.sdr +++ b/code/def_files/data/effects/effect-f.sdr @@ -1,3 +1,10 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +precision highp samplerCube; +#endif #include "gamma.sdr" #include "z-compress.sdr" @@ -7,10 +14,15 @@ in vec4 fragPosition; in vec4 fragTexCoord; in vec4 fragColor; -out vec4 fragOut0; +layout (location=0) out vec4 fragOut0; +#ifdef GL_ES +uniform highp sampler2DArray baseMap; +uniform highp sampler2D depthMap; +#else uniform sampler2DArray baseMap; uniform sampler2D depthMap; +#endif layout (std140) uniform genericData { float window_width; diff --git a/code/def_files/data/effects/effect-g.sdr b/code/def_files/data/effects/effect-g.sdr index d1cb2311291..b1a2f34c02f 100644 --- a/code/def_files/data/effects/effect-g.sdr +++ b/code/def_files/data/effects/effect-g.sdr @@ -1,3 +1,11 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +precision highp samplerCube; +#endif + layout (points) in; layout (triangle_strip, max_vertices = 4) out; diff --git a/code/def_files/data/effects/effect-v.sdr b/code/def_files/data/effects/effect-v.sdr index 3a86333b637..ee7b90166f5 100644 --- a/code/def_files/data/effects/effect-v.sdr +++ b/code/def_files/data/effects/effect-v.sdr @@ -1,3 +1,10 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +precision highp samplerCube; +#endif in vec4 vertPosition; in vec4 vertTexCoord; diff --git a/code/def_files/data/effects/envmap-sphere-warp-f.sdr b/code/def_files/data/effects/envmap-sphere-warp-f.sdr index ab2b4071618..55d845a95bd 100644 --- a/code/def_files/data/effects/envmap-sphere-warp-f.sdr +++ b/code/def_files/data/effects/envmap-sphere-warp-f.sdr @@ -1,9 +1,15 @@ #define M_PI 3.1415926535897932384626433832795 +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp samplerCube; +#endif + uniform samplerCube envmap; in vec4 fragTexCoord; -out vec4 fragOut0; +layout(location=0) out vec4 fragOut0; layout (location = 0) out vec4 outColor; diff --git a/code/def_files/data/effects/fog-f.sdr b/code/def_files/data/effects/fog-f.sdr index ca14335dea8..2a0def98330 100644 --- a/code/def_files/data/effects/fog-f.sdr +++ b/code/def_files/data/effects/fog-f.sdr @@ -1,9 +1,14 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +#endif #include "gamma.sdr" in vec4 fragTexCoord; -out vec4 fragOut0; +layout(location=0) out vec4 fragOut0; uniform sampler2D tex; uniform sampler2D depth_tex; @@ -24,14 +29,14 @@ void main() // If the scene is in fog then we change the color we operate on based on the depth of the pixel float depth_val = texture(depth_tex, fragTexCoord.xy).x; // Transform depth value from [0, 1] to [-1, 1] - float depth_normalized = 2 * depth_val - 1; + float depth_normalized = 2.0 * depth_val - 1.0; // Now we compute the depth value in projection space using the clipping plane information float view_depth = 2.0 * zNear * zFar / (zFar + zNear - depth_normalized * (zFar - zNear)); if (isinf(view_depth)) { fragOut0.rgb = color_in.rgb; } else { - float fog_dist = clamp(1 - pow(fog_density, view_depth - fog_start) , 0.0, 1.0); + float fog_dist = clamp(1.0 - pow(fog_density, view_depth - fog_start) , 0.0, 1.0); vec3 finalFogColor = srgb_to_linear(fog_color); fragOut0.rgb = mix(color_in.rgb, finalFogColor, fog_dist); diff --git a/code/def_files/data/effects/fxaa-f.sdr b/code/def_files/data/effects/fxaa-f.sdr index ae2b28e2ec6..ce14861e9a5 100644 --- a/code/def_files/data/effects/fxaa-f.sdr +++ b/code/def_files/data/effects/fxaa-f.sdr @@ -1,8 +1,20 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +precision highp samplerCube; +#endif + #define FXAA_EARLY_EXIT 1 #define FXAA_DISCARD 1 #define FXAA_FAST_PIXEL_OFFSET 1 // With OpenGL 3.2 we can always do this #ifndef FXAA_GATHER4_ALPHA + #ifdef GL_EXT_gpu_shader5 + #extension GL_EXT_gpu_shader5 : enable + #define FXAA_GATHER4_ALPHA 1 + #endif #ifdef GL_ARB_gpu_shader5 #extension GL_ARB_gpu_shader5 : enable #define FXAA_GATHER4_ALPHA 1 @@ -489,8 +501,12 @@ FxaaFloat4 FxaaPixelShader( } uniform sampler2D tex0; in vec2 v_rcpFrame; +#ifdef GL_ES +in vec2 v_pos; +#else noperspective in vec2 v_pos; -out vec4 fragOut0; +#endif +layout(location=0)out vec4 fragOut0; void main() { fragOut0 = FxaaPixelShader(v_pos, tex0, v_rcpFrame, FXAA_QUALITY_SUBPIX, FXAA_QUALITY_EDGE_THRESHOLD, FXAA_QUALITY_EDGE_THRESHOLD_MIN); } diff --git a/code/def_files/data/effects/fxaa-v.sdr b/code/def_files/data/effects/fxaa-v.sdr index 16aa5cc43e3..d5f31260cd9 100644 --- a/code/def_files/data/effects/fxaa-v.sdr +++ b/code/def_files/data/effects/fxaa-v.sdr @@ -1,8 +1,16 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +#endif in vec4 vertPosition; out vec2 v_rcpFrame; +#ifdef GL_ES +out vec2 v_pos; +#else noperspective out vec2 v_pos; +#endif layout (std140) uniform genericData { float rt_w; diff --git a/code/def_files/data/effects/fxaapre-f.sdr b/code/def_files/data/effects/fxaapre-f.sdr index 5756a847433..bbf4931dd21 100644 --- a/code/def_files/data/effects/fxaapre-f.sdr +++ b/code/def_files/data/effects/fxaapre-f.sdr @@ -1,5 +1,11 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +#endif + in vec4 fragTexCoord; -out vec4 fragOut0; +layout(location=0) out vec4 fragOut0; uniform sampler2D tex; void main() { vec4 color = texture(tex, fragTexCoord.xy); diff --git a/code/def_files/data/effects/irrmap-f.sdr b/code/def_files/data/effects/irrmap-f.sdr index 4400ff1f0f6..e74c9c99017 100644 --- a/code/def_files/data/effects/irrmap-f.sdr +++ b/code/def_files/data/effects/irrmap-f.sdr @@ -1,5 +1,13 @@ //!#version 150 -#include "gamma.sdr" //! #include "gamma.sdr" +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +precision highp samplerCube; +#endif + +#include "gamma.sdr" #define PI 3.1415926535897932384626433832795 uniform samplerCube envmap; @@ -9,7 +17,7 @@ layout (std140) uniform genericData { in vec4 fragTexCoord; -out vec4 fragOut0; +layout(location=0) out vec4 fragOut0; // Iteratively optimised points to give low discrepancy distribution on arbitrary hemisphere. const vec3 points[128] = vec3[128]( @@ -144,8 +152,8 @@ vec3( 0.7305, 0.6698, 0.1333) ); void main() { - float xpos = 2 * gl_FragCoord.x/16 - 1; // remap to (-1, 1) - float ypos = 2 * gl_FragCoord.y/16 - 1; + float xpos = 2.0 * gl_FragCoord.x/16.0 - 1.0; // remap to (-1, 1) + float ypos = 2.0 * gl_FragCoord.y/16.0 - 1.0; vec3 fragDir; vec4 fragCol = vec4(0.0); @@ -181,5 +189,5 @@ void main() { vec3 sampDir = points[i] + (aPdotD - PdotD) * fragDir; fragCol += aPdotD * vec4(srgb_to_linear(texture(envmap, sampDir)).rgb, 1.0); } - fragOut0 = linear_to_srgb(PI * fragCol * (1.0/128)); + fragOut0 = linear_to_srgb(PI * fragCol * (1.0/128.0)); } \ No newline at end of file diff --git a/code/def_files/data/effects/lighting.sdr b/code/def_files/data/effects/lighting.sdr index 799617b52eb..00ae3fb2fa0 100644 --- a/code/def_files/data/effects/lighting.sdr +++ b/code/def_files/data/effects/lighting.sdr @@ -8,7 +8,7 @@ const int LT_AMBIENT = 4; // Directionless ambient light const float SPEC_FACTOR_NO_SPEC_MAP = 0.1; const float GLOW_MAP_INTENSITY = 1.5; const float GLOW_MAP_SRGB_MULTIPLIER = 3.0; -const float PI = 3.14159f; +const float PI = 3.14159265359; vec3 FresnelSchlick(vec3 halfVec, vec3 view, vec3 specColor) @@ -57,7 +57,7 @@ vec3 ComputeGGX(vec3 specColor, vec3 diffColor, vec3 light, vec3 normal, vec3 ha - vec3 specular = distribution * fresnel * geometry / (4*dotNV*dotNL + 0.0001); + vec3 specular = distribution * fresnel * geometry / (4.0*dotNV*dotNL + 0.0001); // Diffuse term - Lambertian, kD represents energy lost to specular reflection. vec3 kD = vec3(1.0)-fresnel; @@ -70,7 +70,7 @@ vec3 ComputeGGX(vec3 specColor, vec3 diffColor, vec3 light, vec3 normal, vec3 ha vec3 computeLighting(vec3 specColor, vec3 diffColor, vec3 light, vec3 normal, vec3 halfVec, vec3 view, float roughness, float fresnelFactor, float dotNL) { #ifdef FLAG_LIGHT_MODEL_BLINN_PHONG - return SpecularBlinnPhong(specColor, light, normal, halfVec, 32, fresnelFactor, dotNL); + return SpecularBlinnPhong(specColor, light, normal, halfVec, 32.0, fresnelFactor, dotNL); #else return ComputeGGX(specColor, diffColor, light, normal, halfVec, view, roughness, fresnelFactor, dotNL); #endif diff --git a/code/def_files/data/effects/ls-f.sdr b/code/def_files/data/effects/ls-f.sdr index 037d47d71e1..46febdc91f1 100644 --- a/code/def_files/data/effects/ls-f.sdr +++ b/code/def_files/data/effects/ls-f.sdr @@ -1,7 +1,12 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +#endif in vec4 fragTexCoord; -out vec4 fragOut0; +layout(location=0) out vec4 fragOut0; uniform sampler2D scene; uniform sampler2D cockpit; diff --git a/code/def_files/data/effects/main-f.sdr b/code/def_files/data/effects/main-f.sdr index dcf487585ba..1c5912802df 100644 --- a/code/def_files/data/effects/main-f.sdr +++ b/code/def_files/data/effects/main-f.sdr @@ -1,4 +1,12 @@ //? #version 150 +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +precision highp samplerCube; +#endif + #include "shadows.sdr" //! #include "shadows.sdr" #include "lighting.sdr" //! #include "lighting.sdr" #include "gamma.sdr" //! #include "gamma.sdr" @@ -110,6 +118,10 @@ in VertexOutput { vec4 shadowUV[4]; vec4 shadowPos; #prereplace ENDIF_FLAG_COMPILED MODEL_SDR_FLAG_SHADOWS + +#ifdef GL_ES + float vClipDist; +#endif } vertIn; #prereplace IF_FLAG_COMPILED MODEL_SDR_FLAG_DIFFUSE @@ -138,10 +150,10 @@ uniform sampler2DArray shadow_map; out vec4 fragOut0; #ifndef MODEL_SDR_FLAG_SHADOW_MAP -out vec4 fragOut1; -out vec4 fragOut2; -out vec4 fragOut3; -out vec4 fragOut4; +layout(location=1)out vec4 fragOut1; +layout(location=2)out vec4 fragOut2; +layout(location=3)out vec4 fragOut3; +layout(location=4)out vec4 fragOut4; #endif vec3 FresnelLazarovEnv(vec3 specColor, vec3 view, vec3 normal, float gloss) @@ -203,6 +215,10 @@ vec3 CalculateLighting(vec3 normal, vec3 diffuseMaterial, vec3 specularMaterial, void main() { + #ifdef GL_ES + if (vertIn.vClipDist < 0.0) discard; + #endif + #ifdef MODEL_SDR_FLAG_SHADOW_MAP // need depth and depth squared for variance shadow maps fragOut0 = vec4(vertIn.position.z, vertIn.position.z * vertIn.position.z * VARIANCE_SHADOW_SCALE_INV, 0.0, 1.0); @@ -418,11 +434,11 @@ void main() #prereplace IF_NOT_FLAG MODEL_SDR_FLAG_LIGHT #prereplace IF_FLAG MODEL_SDR_FLAG_SPEC baseColor.rgb += pow(1.0 - clamp(dot(eyeDir, normal), 0.0, 1.0), 5.0 * clamp(glossData, 0.01, 1.0)) * specColor.rgb; - glossData = 0; + glossData = 0.0f; #prereplace ENDIF_FLAG //MODEL_SDR_FLAG_SPEC // If there is no lighting then we copy the color data so far into the emissive. emissiveColor.rgb += baseColor.rgb; - aoFactors.x = 0; + aoFactors.x = 0.0f; #prereplace ENDIF_FLAG //MODEL_SDR_FLAG_LIGHT #prereplace ENDIF_FLAG //MODEL_SDR_FLAG_DEFERRED diff --git a/code/def_files/data/effects/main-g.sdr b/code/def_files/data/effects/main-g.sdr index 24db6200630..ae091ca3b90 100644 --- a/code/def_files/data/effects/main-g.sdr +++ b/code/def_files/data/effects/main-g.sdr @@ -1,4 +1,13 @@ +#ifdef GL_ES +#extension GL_EXT_gpu_shader5: enable +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +precision highp samplerCube; +#else #extension GL_ARB_gpu_shader5: enable +#endif #conditional_include +"LARGE_SHADER" "main_large.sdr" #conditional_include -"LARGE_SHADER" "main_small.sdr" @@ -13,7 +22,7 @@ layout (triangle_strip, max_vertices = 3) out; #endif #ifdef MODEL_SDR_FLAG_SHADOW_MAP - #ifdef GL_ARB_gpu_shader5 + #if defined(GL_ARB_gpu_shader5) || defined(GL_EXT_gpu_shader5) layout(invocations = 4) in; #endif #endif @@ -109,7 +118,7 @@ in VertexOutput { #prereplace ENDIF_FLAG_COMPILED MODEL_SDR_FLAG_FOG #ifdef MODEL_SDR_FLAG_SHADOW_MAP - #if !defined(GL_ARB_gpu_shader5) + #if !defined(GL_ARB_gpu_shader5) && !defined(GL_EXT_gpu_shader5) float instance; #endif float clipModel; @@ -123,6 +132,9 @@ in VertexOutput { vec4 shadowUV[4]; vec4 shadowPos; #prereplace ENDIF_FLAG_COMPILED MODEL_SDR_FLAG_SHADOWS +#ifdef GL_ES + float vClipDist; +#endif } vertIn[]; out VertexOutput { @@ -140,12 +152,16 @@ out VertexOutput { vec4 shadowUV[4]; vec4 shadowPos; #prereplace ENDIF_FLAG_COMPILED MODEL_SDR_FLAG_SHADOWS + +#ifdef GL_ES + float vClipDist; +#endif } vertOut; #ifdef MODEL_SDR_FLAG_SHADOW_MAP void main(void) { - #ifdef GL_ARB_gpu_shader5 + #if defined(GL_ARB_gpu_shader5) || defined(GL_EXT_gpu_shader5) int instanceID = gl_InvocationID; #else int instanceID = int(vertIn[0].instance); @@ -189,7 +205,11 @@ out VertexOutput { #prereplace ENDIF_FLAG //MODEL_SDR_FLAG_SHADOWS if (use_clip_plane) { - gl_ClipDistance[0] = gl_in[vert].gl_ClipDistance[0]; + #ifdef GL_ES + vertOut.vClipDist = vertIn[vert].vClipDist; + #else + gl_ClipDistance[0] = gl_in[vert].gl_ClipDistance[0]; + #endif } EmitVertex(); } @@ -243,8 +263,19 @@ out VertexOutput { #prereplace ENDIF_FLAG //MODEL_SDR_FLAG_SHADOWS if (use_clip_plane) { - gl_ClipDistance[0] = gl_in[vert].gl_ClipDistance[0]; + #ifdef GL_ES + vertOut.vClipDist = vertIn[vert].vClipDist; + #else + gl_ClipDistance[0] = gl_in[vert].gl_ClipDistance[0]; + #endif + } else { + #ifdef GL_ES + vertOut.vClipDist = 1.0; + #else + gl_ClipDistance[0] = 1.0; + #endif } + EmitVertex(); } diff --git a/code/def_files/data/effects/main-v.sdr b/code/def_files/data/effects/main-v.sdr index 2033c944165..63b435f991f 100644 --- a/code/def_files/data/effects/main-v.sdr +++ b/code/def_files/data/effects/main-v.sdr @@ -1,5 +1,15 @@ //? #version 150 +#ifdef GL_ES +#extension GL_EXT_gpu_shader5: enable +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +precision highp samplerCube; +precision highp samplerBuffer; +#else #extension GL_ARB_gpu_shader5: enable +#endif #include "shadows.sdr" @@ -108,7 +118,7 @@ out VertexOutput { #prereplace ENDIF_FLAG_COMPILED MODEL_SDR_FLAG_FOG #ifdef MODEL_SDR_FLAG_SHADOW_MAP - #if !defined(GL_ARB_gpu_shader5) + #if !defined(GL_ARB_gpu_shader5) && !defined(GL_EXT_gpu_shader5) float instance; #endif // This flag is needed to let the geometry shader know that it doesn't need to apply the @@ -124,6 +134,10 @@ out VertexOutput { vec4 shadowUV[4]; vec4 shadowPos; #prereplace ENDIF_FLAG_COMPILED MODEL_SDR_FLAG_SHADOWS + +#ifdef GL_ES + float vClipDist; +#endif } vertOut; #define TEXELS_PER_MATRIX 4 @@ -164,7 +178,7 @@ void main() position = modelViewMatrix * orient * vertex; #ifdef MODEL_SDR_FLAG_SHADOW_MAP gl_Position = position; - #if !defined(GL_ARB_gpu_shader5) + #if !defined(GL_ARB_gpu_shader5) && !defined(GL_EXT_gpu_shader5) #ifdef APPLE vertOut.instance = float(gl_InstanceIDARB); #else @@ -202,11 +216,21 @@ void main() #endif #prereplace ENDIF_FLAG //MODEL_SDR_FLAG_TRANSFORM - if(use_clip_plane) { - gl_ClipDistance[0] = dot(clip_equation, modelMatrix * orient * vertex); - } else { - gl_ClipDistance[0] = 1.0; - } + #ifdef GL_ES + if (use_clip_plane) { + vertOut.vClipDist = dot(clip_equation, modelMatrix * orient * vertex); + } else { + vertOut.vClipDist = 1.0; + } + #else + if (use_clip_plane) { + gl_ClipDistance[0] = dot(clip_equation, modelMatrix * orient * vertex); + } else { + gl_ClipDistance[0] = 1.0; + } + #endif + + #ifndef MODEL_SDR_FLAG_SHADOW_MAP vertOut.position = position; diff --git a/code/def_files/data/effects/msaa-f.sdr b/code/def_files/data/effects/msaa-f.sdr index 521834f6798..33a4f0ca629 100644 --- a/code/def_files/data/effects/msaa-f.sdr +++ b/code/def_files/data/effects/msaa-f.sdr @@ -1,12 +1,18 @@ -#include "z-compress.sdr" +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +precision highp sampler2DMS; +#endif in vec4 fragTexCoord; -out vec4 fragOut0; -out vec4 fragOut1; -out vec4 fragOut2; -out vec4 fragOut3; -out vec4 fragOut4; -out vec4 fragOut5; +layout(location=0)out vec4 fragOut0; +layout(location=1)out vec4 fragOut1; +layout(location=2)out vec4 fragOut2; +layout(location=3)out vec4 fragOut3; +layout(location=4)out vec4 fragOut4; +layout(location=5)out vec4 fragOut5; uniform sampler2DMS texColor; uniform sampler2DMS texPos; diff --git a/code/def_files/data/effects/nanovg-f.sdr b/code/def_files/data/effects/nanovg-f.sdr index 9433077661b..8bc33c58013 100644 --- a/code/def_files/data/effects/nanovg-f.sdr +++ b/code/def_files/data/effects/nanovg-f.sdr @@ -1,3 +1,9 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +#endif // Enabled at all times but the define is kept here in case this should be configurable in the future #define EDGE_AA diff --git a/code/def_files/data/effects/nanovg-v.sdr b/code/def_files/data/effects/nanovg-v.sdr index 48b5cbb9a0e..a1f619e5e13 100644 --- a/code/def_files/data/effects/nanovg-v.sdr +++ b/code/def_files/data/effects/nanovg-v.sdr @@ -1,3 +1,9 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +#endif layout(std140) uniform NanoVGUniformData { mat3 scissorMat; diff --git a/code/def_files/data/effects/normals.sdr b/code/def_files/data/effects/normals.sdr index 8123bd13747..185dc5cbff2 100644 --- a/code/def_files/data/effects/normals.sdr +++ b/code/def_files/data/effects/normals.sdr @@ -7,6 +7,6 @@ vec3 unpackNormal(vec2 normal_sample) { vec3 normal; normal.xy = normal_sample * 2.0 - 1.0; - normal.z = sqrt(1 - normal_sample.x * normal_sample.x - normal_sample.y * normal_sample.y); + normal.z = sqrt(1.0 - normal_sample.x * normal_sample.x - normal_sample.y * normal_sample.y); return normal; } diff --git a/code/def_files/data/effects/passthrough-f.sdr b/code/def_files/data/effects/passthrough-f.sdr index 6e3134e068e..3b06379b9bd 100644 --- a/code/def_files/data/effects/passthrough-f.sdr +++ b/code/def_files/data/effects/passthrough-f.sdr @@ -1,9 +1,14 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +#endif #include "gamma.sdr" in vec4 fragTexCoord; in vec4 fragColor; -out vec4 fragOut0; +layout(location=0) out vec4 fragOut0; uniform sampler2D baseMap; diff --git a/code/def_files/data/effects/post-f.sdr b/code/def_files/data/effects/post-f.sdr index 08eafe5899e..cb1b1bbaad7 100644 --- a/code/def_files/data/effects/post-f.sdr +++ b/code/def_files/data/effects/post-f.sdr @@ -1,6 +1,13 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +#endif + in vec4 fragTexCoord; -out vec4 fragOut0; +layout(location=0) out vec4 fragOut0; uniform sampler2D tex; uniform sampler2D depth_tex; diff --git a/code/def_files/data/effects/rocketui-f.sdr b/code/def_files/data/effects/rocketui-f.sdr index bffff254716..3c46341a0c3 100644 --- a/code/def_files/data/effects/rocketui-f.sdr +++ b/code/def_files/data/effects/rocketui-f.sdr @@ -1,9 +1,15 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +#endif in vec2 fragTexCoord; in vec4 fragColor; in vec2 fragScreenPosition; -out vec4 fragOut0; +layout(location=0) out vec4 fragOut0; uniform sampler2DArray baseMap; diff --git a/code/def_files/data/effects/rocketui-v.sdr b/code/def_files/data/effects/rocketui-v.sdr index dd62c939226..d6e46f192ec 100644 --- a/code/def_files/data/effects/rocketui-v.sdr +++ b/code/def_files/data/effects/rocketui-v.sdr @@ -1,3 +1,9 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +#endif in vec2 vertPosition; in vec4 vertColor; diff --git a/code/def_files/data/effects/shield-impact-f.sdr b/code/def_files/data/effects/shield-impact-f.sdr index d5214d18f62..f22b0e000cd 100644 --- a/code/def_files/data/effects/shield-impact-f.sdr +++ b/code/def_files/data/effects/shield-impact-f.sdr @@ -1,3 +1,9 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +#endif #include "gamma.sdr" @@ -6,9 +12,13 @@ const float EMISSIVE_GAIN = 2.0; in vec4 fragImpactUV; in float fragNormOffset; -out vec4 fragOut0; +layout (location=0) out vec4 fragOut0; +#ifdef GL_ES +uniform highp sampler2DArray shieldMap; +#else uniform sampler2DArray shieldMap; +#endif layout (std140) uniform genericData { mat4 shieldModelViewMatrix; diff --git a/code/def_files/data/effects/shield-impact-v.sdr b/code/def_files/data/effects/shield-impact-v.sdr index a1260a63389..8cf6cb41957 100644 --- a/code/def_files/data/effects/shield-impact-v.sdr +++ b/code/def_files/data/effects/shield-impact-v.sdr @@ -1,3 +1,9 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +#endif in vec4 vertPosition; in vec3 vertNormal; diff --git a/code/def_files/data/effects/smaa-blend-f.sdr b/code/def_files/data/effects/smaa-blend-f.sdr index 1bd725fd8ba..b19b49f7006 100644 --- a/code/def_files/data/effects/smaa-blend-f.sdr +++ b/code/def_files/data/effects/smaa-blend-f.sdr @@ -1,3 +1,9 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +#endif layout (std140) uniform genericData { vec2 smaa_rt_metrics; @@ -14,7 +20,7 @@ in vec2 fragTexCoord; in vec2 fragPixcoord; in vec4 fragOffset[3]; -out vec4 fragOut0; +layout(location=0) out vec4 fragOut0; uniform sampler2D edgesTex; uniform sampler2D areaTex; diff --git a/code/def_files/data/effects/smaa-blend-v.sdr b/code/def_files/data/effects/smaa-blend-v.sdr index f4cc787c6a5..ba939b391e7 100644 --- a/code/def_files/data/effects/smaa-blend-v.sdr +++ b/code/def_files/data/effects/smaa-blend-v.sdr @@ -1,3 +1,9 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +#endif layout (std140) uniform genericData { vec2 smaa_rt_metrics; diff --git a/code/def_files/data/effects/smaa-edge-f.sdr b/code/def_files/data/effects/smaa-edge-f.sdr index 367c8501960..e77c0541feb 100644 --- a/code/def_files/data/effects/smaa-edge-f.sdr +++ b/code/def_files/data/effects/smaa-edge-f.sdr @@ -1,3 +1,9 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +#endif layout (std140) uniform genericData { vec2 smaa_rt_metrics; @@ -13,7 +19,7 @@ layout (std140) uniform genericData { in vec2 fragTexCoord; in vec4 fragOffset[3]; -out vec4 fragOut0; +layout(location=0) out vec4 fragOut0; uniform sampler2D colorTex; diff --git a/code/def_files/data/effects/smaa-edge-v.sdr b/code/def_files/data/effects/smaa-edge-v.sdr index 8a5e93d4492..7055ee7b1b4 100644 --- a/code/def_files/data/effects/smaa-edge-v.sdr +++ b/code/def_files/data/effects/smaa-edge-v.sdr @@ -1,3 +1,9 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +#endif layout (std140) uniform genericData { vec2 smaa_rt_metrics; diff --git a/code/def_files/data/effects/smaa-neighbour-f.sdr b/code/def_files/data/effects/smaa-neighbour-f.sdr index dc3d76ae701..c5e7d0725a5 100644 --- a/code/def_files/data/effects/smaa-neighbour-f.sdr +++ b/code/def_files/data/effects/smaa-neighbour-f.sdr @@ -1,3 +1,9 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +#endif layout (std140) uniform genericData { vec2 smaa_rt_metrics; @@ -13,7 +19,7 @@ layout (std140) uniform genericData { in vec2 fragTexCoord; in vec4 fragOffset; -out vec4 fragOut0; +layout(location=0) out vec4 fragOut0; uniform sampler2D colorTex; uniform sampler2D blendTex; diff --git a/code/def_files/data/effects/smaa-neighbour-v.sdr b/code/def_files/data/effects/smaa-neighbour-v.sdr index fa1601cdba7..d4773f2cc58 100644 --- a/code/def_files/data/effects/smaa-neighbour-v.sdr +++ b/code/def_files/data/effects/smaa-neighbour-v.sdr @@ -1,3 +1,9 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +#endif layout (std140) uniform genericData { vec2 smaa_rt_metrics; diff --git a/code/def_files/data/effects/tonemapping-f.sdr b/code/def_files/data/effects/tonemapping-f.sdr index 8011d0cdfe9..b89314687d8 100644 --- a/code/def_files/data/effects/tonemapping-f.sdr +++ b/code/def_files/data/effects/tonemapping-f.sdr @@ -1,8 +1,14 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +#endif #include "gamma.sdr" in vec4 fragTexCoord; -out vec4 fragOut0; +layout(location=0) out vec4 fragOut0; uniform sampler2D tex; layout (std140) uniform genericData { diff --git a/code/def_files/data/effects/video-f.sdr b/code/def_files/data/effects/video-f.sdr index 4e4fab88952..eda8fd60ef9 100644 --- a/code/def_files/data/effects/video-f.sdr +++ b/code/def_files/data/effects/video-f.sdr @@ -1,5 +1,12 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +#endif + in vec4 fragTexCoord; -out vec4 fragOut0; +layout(location=0) out vec4 fragOut0; uniform sampler2DArray ytex; uniform sampler2DArray utex; uniform sampler2DArray vtex; diff --git a/code/def_files/data/effects/volumetric-f.sdr b/code/def_files/data/effects/volumetric-f.sdr index d511fea68a9..cda47c7c075 100644 --- a/code/def_files/data/effects/volumetric-f.sdr +++ b/code/def_files/data/effects/volumetric-f.sdr @@ -1,7 +1,13 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +#endif in vec4 fragTexCoord; -out vec4 fragOut0; +layout(location=0) out vec4 fragOut0; layout (binding = 0) uniform sampler2D composite; layout (binding = 1) uniform sampler2D emissive; From 495d0266d12e4d3f306c6e8de812cd99a41d7846 Mon Sep 17 00:00:00 2001 From: Salvador Cipolla Date: Tue, 26 May 2026 20:31:37 -0300 Subject: [PATCH 02/11] fix fxaa gles --- code/def_files/data/effects/fxaa-f.sdr | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/code/def_files/data/effects/fxaa-f.sdr b/code/def_files/data/effects/fxaa-f.sdr index ce14861e9a5..52b5b27abe3 100644 --- a/code/def_files/data/effects/fxaa-f.sdr +++ b/code/def_files/data/effects/fxaa-f.sdr @@ -11,17 +11,15 @@ precision highp samplerCube; #define FXAA_FAST_PIXEL_OFFSET 1 // With OpenGL 3.2 we can always do this #ifndef FXAA_GATHER4_ALPHA - #ifdef GL_EXT_gpu_shader5 - #extension GL_EXT_gpu_shader5 : enable - #define FXAA_GATHER4_ALPHA 1 - #endif - #ifdef GL_ARB_gpu_shader5 - #extension GL_ARB_gpu_shader5 : enable - #define FXAA_GATHER4_ALPHA 1 - #endif - #ifdef GL_NV_gpu_shader5 - #extension GL_NV_gpu_shader5 : enable - #define FXAA_GATHER4_ALPHA 1 + #ifndef GL_ES + #ifdef GL_ARB_gpu_shader5 + #extension GL_ARB_gpu_shader5 : enable + #define FXAA_GATHER4_ALPHA 1 + #endif + #ifdef GL_NV_gpu_shader5 + #extension GL_NV_gpu_shader5 : enable + #define FXAA_GATHER4_ALPHA 1 + #endif #endif #ifndef FXAA_GATHER4_ALPHA #define FXAA_GATHER4_ALPHA 0 From cad4cdcbb048681150d624d93a68bab39b25485c Mon Sep 17 00:00:00 2001 From: Salvador Cipolla Date: Tue, 26 May 2026 20:44:08 -0300 Subject: [PATCH 03/11] re-add removed include by accident --- code/def_files/data/effects/msaa-f.sdr | 1 + 1 file changed, 1 insertion(+) diff --git a/code/def_files/data/effects/msaa-f.sdr b/code/def_files/data/effects/msaa-f.sdr index 33a4f0ca629..9fabdd794a9 100644 --- a/code/def_files/data/effects/msaa-f.sdr +++ b/code/def_files/data/effects/msaa-f.sdr @@ -1,3 +1,4 @@ +#include "z-compress.sdr" #ifdef GL_ES precision highp float; precision highp int; From e752cdd7bcf727da3efed2c557179aa7e4c0c0d3 Mon Sep 17 00:00:00 2001 From: Salvador Cipolla Date: Wed, 27 May 2026 19:17:36 -0300 Subject: [PATCH 04/11] add missing location to frag0 --- code/def_files/data/effects/main-f.sdr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/def_files/data/effects/main-f.sdr b/code/def_files/data/effects/main-f.sdr index 1c5912802df..f582a1c7001 100644 --- a/code/def_files/data/effects/main-f.sdr +++ b/code/def_files/data/effects/main-f.sdr @@ -147,7 +147,7 @@ uniform sampler2DArray sMiscmap; uniform sampler2DArray shadow_map; #prereplace ENDIF_FLAG_COMPILED MODEL_SDR_FLAG_SHADOWS -out vec4 fragOut0; +layout(location=0)out vec4 fragOut0; #ifndef MODEL_SDR_FLAG_SHADOW_MAP layout(location=1)out vec4 fragOut1; From c4f16002bcb8bbaba1c41811da0e6eb60844366e Mon Sep 17 00:00:00 2001 From: Salvador Cipolla Date: Wed, 27 May 2026 19:20:05 -0300 Subject: [PATCH 05/11] add gles default-material --- .../data/effects/default-material-f.sdr | 59 ------------------- .../data/effects/default-material-v.sdr | 43 -------------- .../data/effects/default-material.frag | 44 -------------- .../data/effects/default-material.vert | 44 -------------- code/graphics/opengl/gropenglshader.cpp | 9 ++- .../default-material.frag.spv.gles.glsl} | 2 - .../default-material.vert.spv.gles.glsl} | 2 - code/shaders.cmake | 22 +++++++ 8 files changed, 29 insertions(+), 196 deletions(-) delete mode 100644 code/def_files/data/effects/default-material-f.sdr delete mode 100644 code/def_files/data/effects/default-material-v.sdr delete mode 100644 code/def_files/data/effects/default-material.frag delete mode 100644 code/def_files/data/effects/default-material.vert rename code/{def_files/data/effects/default-material.frag.spv.glsl => graphics/shaders/compiled/default-material.frag.spv.gles.glsl} (98%) rename code/{def_files/data/effects/default-material.vert.spv.glsl => graphics/shaders/compiled/default-material.vert.spv.gles.glsl} (97%) diff --git a/code/def_files/data/effects/default-material-f.sdr b/code/def_files/data/effects/default-material-f.sdr deleted file mode 100644 index a9eb480f9c5..00000000000 --- a/code/def_files/data/effects/default-material-f.sdr +++ /dev/null @@ -1,59 +0,0 @@ -#ifdef GL_ES -precision highp float; -precision highp int; -precision highp sampler2D; -precision highp sampler2DArray; -#endif - -layout(std140) uniform genericData -{ - mat4 modelMatrix; - vec4 color; - vec4 clipEquation; - int baseMapIndex; - int alphaTexture; - int noTexturing; - int srgb; - float intensity; - float alphaThreshold; - uint clipEnabled; -} _39; - -uniform sampler2DArray baseMap; -in highp float vClipDist; -in vec4 fragTexCoord; -in vec4 fragColor; -layout (location=0) out vec4 fragOut0; - -void main() -{ - if (_39.clipEnabled != 0u && vClipDist < 0.0) { - discard; - } - vec4 _48 = texture(baseMap, vec3(fragTexCoord.xy, float(_39.baseMapIndex))); - if (_39.alphaThreshold > _48.w) - { - discard; - } - bool _66 = _39.srgb == 1; - vec3 _146; - if (_66) - { - _146 = pow(_48.xyz, vec3(2.2000000476837158203125)); - } - else - { - _146 = _48.xyz; - } - vec4 _148; - if (_66) - { - _148 = vec4(pow(fragColor.xyz, vec3(2.2000000476837158203125)), fragColor.w); - } - else - { - _148 = fragColor; - } - fragOut0 = mix(mix(vec4(_146.x, _146.y, _146.z, _48.w) * _148, vec4(_148.xyz, _146.x * _148.w), vec4(float(_39.alphaTexture))), _148, vec4(float(_39.noTexturing))) * _39.intensity; -} - diff --git a/code/def_files/data/effects/default-material-v.sdr b/code/def_files/data/effects/default-material-v.sdr deleted file mode 100644 index ebedb5900d3..00000000000 --- a/code/def_files/data/effects/default-material-v.sdr +++ /dev/null @@ -1,43 +0,0 @@ -#ifdef GL_ES -precision highp float; -precision highp int; -precision highp sampler2D; -precision highp sampler2DArray; -#endif - -layout(std140) uniform genericData -{ - mat4 modelMatrix; - vec4 color; - vec4 clipEquation; - int baseMapIndex; - int alphaTexture; - int noTexturing; - int srgb; - float intensity; - float alphaThreshold; - uint clipEnabled; -} _22; - -layout(std140) uniform matrixData -{ - mat4 modelViewMatrix; - mat4 projMatrix; -} _36; - -out vec4 fragTexCoord; -in vec4 vertTexCoord; -out vec4 fragColor; -in vec4 vertColor; -in vec4 vertPosition; -out float vClipDist; - -void main() -{ - fragTexCoord = vertTexCoord; - fragColor = vertColor * _22.color; - gl_Position = (_36.projMatrix * _36.modelViewMatrix) * vertPosition; - float d = dot(_22.clipEquation, _22.modelMatrix * vertPosition); - vClipDist = (_22.clipEnabled != 0u) ? d : 1.0; -} - diff --git a/code/def_files/data/effects/default-material.frag b/code/def_files/data/effects/default-material.frag deleted file mode 100644 index 1966a11331a..00000000000 --- a/code/def_files/data/effects/default-material.frag +++ /dev/null @@ -1,44 +0,0 @@ -#version 320 es -#ifdef GL_ES -precision highp float; -precision highp int; -precision highp sampler2D; -precision highp sampler2DArray; -#endif - -#include "gamma.sdr" - -layout (binding = 0) in vec4 fragTexCoord; -layout (binding = 1) in vec4 fragColor; - -layout (location = 0) out vec4 fragOut0; - -layout (std140) uniform genericData { - mat4 modelMatrix; - vec4 color; - vec4 clipEquation; - int baseMapIndex; - int alphaTexture; - int noTexturing; - int srgb; - float intensity; - float alphaThreshold; - uint clipEnabled; -}; - -in float vClipDist; - -layout(binding = 2) uniform sampler2DArray baseMap; - -void main() -{ - if (clipEnabled != uint(0) && vClipDist < 0.0) { - discard; - } - - vec4 baseColor = texture(baseMap, vec3(fragTexCoord.xy, float(baseMapIndex))); - if(alphaThreshold > baseColor.a) discard; - baseColor.rgb = (srgb == 1) ? srgb_to_linear(baseColor.rgb) : baseColor.rgb; - vec4 blendColor = (srgb == 1) ? vec4(srgb_to_linear(fragColor.rgb), fragColor.a) : fragColor; - fragOut0 = mix(mix(baseColor * blendColor, vec4(blendColor.rgb, baseColor.r * blendColor.a), float(alphaTexture)), blendColor, float(noTexturing)) * intensity; -} diff --git a/code/def_files/data/effects/default-material.vert b/code/def_files/data/effects/default-material.vert deleted file mode 100644 index a861459e2d3..00000000000 --- a/code/def_files/data/effects/default-material.vert +++ /dev/null @@ -1,44 +0,0 @@ -#version 320 es -#ifdef GL_ES -precision highp float; -precision highp int; -precision highp sampler2D; -precision highp sampler2DArray; -#endif - -layout (location = 0) in vec4 vertPosition; -layout (location = 1) in vec4 vertColor; -layout (location = 2) in vec4 vertTexCoord; - -layout (location = 0) out vec4 fragTexCoord; -layout (location = 1) out vec4 fragColor; - -layout (binding = 0, std140) uniform matrixData { - mat4 modelViewMatrix; - mat4 projMatrix; -}; - -layout (binding = 1, std140) uniform genericData { - mat4 modelMatrix; - vec4 color; - vec4 clipEquation; - int baseMapIndex; - int alphaTexture; - int noTexturing; - int srgb; - float intensity; - float alphaThreshold; - uint clipEnabled; -}; - -out float vClipDist; - -void main() -{ - fragTexCoord = vertTexCoord; - fragColor = vertColor * color; - gl_Position = projMatrix * modelViewMatrix * vertPosition; - - float d = dot(clipEquation, modelMatrix * vertPosition); - vClipDist = (clipEnabled != uint(0)) ? d : 1.0; -} diff --git a/code/graphics/opengl/gropenglshader.cpp b/code/graphics/opengl/gropenglshader.cpp index 6baeb10bb6d..57f628f809d 100644 --- a/code/graphics/opengl/gropenglshader.cpp +++ b/code/graphics/opengl/gropenglshader.cpp @@ -137,8 +137,13 @@ static opengl_shader_type_t GL_shader_types[] = { { SDR_TYPE_BATCHED_BITMAP, "batched-v.sdr", "batched-f.sdr", nullptr, { opengl_vert_attrib::POSITION, opengl_vert_attrib::TEXCOORD, opengl_vert_attrib::COLOR }, "Batched bitmaps", false }, - { SDR_TYPE_DEFAULT_MATERIAL, "default-material.vert.spv.glsl", "default-material.frag.spv.glsl", nullptr, - { opengl_vert_attrib::POSITION, opengl_vert_attrib::TEXCOORD, opengl_vert_attrib::COLOR }, "Default material", true }, +#ifdef USE_OPENGL_ES + { SDR_TYPE_DEFAULT_MATERIAL, "default-material.vert.spv.gles.glsl", "default-material.frag.spv.gles.glsl", nullptr, + { opengl_vert_attrib::POSITION, opengl_vert_attrib::TEXCOORD, opengl_vert_attrib::COLOR }, "Default material", true }, +#else + { SDR_TYPE_DEFAULT_MATERIAL, "default-material.vert.spv.glsl", "default-material.frag.spv.glsl", nullptr, + { opengl_vert_attrib::POSITION, opengl_vert_attrib::TEXCOORD, opengl_vert_attrib::COLOR }, "Default material", true }, +#endif { SDR_TYPE_NANOVG, "nanovg-v.sdr", "nanovg-f.sdr", nullptr, { opengl_vert_attrib::POSITION, opengl_vert_attrib::TEXCOORD }, "NanoVG shader", false }, diff --git a/code/def_files/data/effects/default-material.frag.spv.glsl b/code/graphics/shaders/compiled/default-material.frag.spv.gles.glsl similarity index 98% rename from code/def_files/data/effects/default-material.frag.spv.glsl rename to code/graphics/shaders/compiled/default-material.frag.spv.gles.glsl index aecc64db179..a9a9b5c890e 100644 --- a/code/def_files/data/effects/default-material.frag.spv.glsl +++ b/code/graphics/shaders/compiled/default-material.frag.spv.gles.glsl @@ -1,10 +1,8 @@ #version 320 es -#ifdef GL_ES precision highp float; precision highp int; precision highp sampler2D; precision highp sampler2DArray; -#endif layout(std140) uniform genericData { diff --git a/code/def_files/data/effects/default-material.vert.spv.glsl b/code/graphics/shaders/compiled/default-material.vert.spv.gles.glsl similarity index 97% rename from code/def_files/data/effects/default-material.vert.spv.glsl rename to code/graphics/shaders/compiled/default-material.vert.spv.gles.glsl index 42f0842200a..b0cbd8e944b 100644 --- a/code/def_files/data/effects/default-material.vert.spv.glsl +++ b/code/graphics/shaders/compiled/default-material.vert.spv.gles.glsl @@ -1,10 +1,8 @@ #version 320 es -#ifdef GL_ES precision highp float; precision highp int; precision highp sampler2D; precision highp sampler2DArray; -#endif layout(std140) uniform genericData { diff --git a/code/shaders.cmake b/code/shaders.cmake index 4c7763a2e62..09a7946c3db 100644 --- a/code/shaders.cmake +++ b/code/shaders.cmake @@ -64,6 +64,17 @@ foreach (_shader ${SHADERS}) ) target_embed_files(code FILES "${_glslOutput}" RELATIVE_TO "${_shaderOutputDir}" PATH_TYPE_PREFIX "data/effects") + + #GLES default-material shaders + set(_glesGlslOutputs + "${CMAKE_CURRENT_SOURCE_DIR}/graphics/shaders/compiled/default-material.vert.spv.gles.glsl" + "${CMAKE_CURRENT_SOURCE_DIR}/graphics/shaders/compiled/default-material.frag.spv.gles.glsl" + ) + target_embed_files(code FILES ${_glesGlslOutputs} + RELATIVE_TO "${CMAKE_CURRENT_SOURCE_DIR}/graphics/shaders/compiled" + PATH_TYPE_PREFIX "data/effects") + target_sources(code PRIVATE ${_glesGlslOutputs}) + else() target_embed_files(code FILES "${_spirvFile}" RELATIVE_TO "${_shaderOutputDir}" PATH_TYPE_PREFIX "data/effects") @@ -73,6 +84,17 @@ foreach (_shader ${SHADERS}) list(APPEND _structHeaderList "${_structOutput}") target_embed_files(code FILES "${_glslOutput}" RELATIVE_TO "${_shaderOutputDir}" PATH_TYPE_PREFIX "data/effects") + + #GLES default-material shaders + set(_glesGlslOutputs + "${CMAKE_CURRENT_SOURCE_DIR}/graphics/shaders/compiled/default-material.vert.spv.gles.glsl" + "${CMAKE_CURRENT_SOURCE_DIR}/graphics/shaders/compiled/default-material.frag.spv.gles.glsl" + ) + target_embed_files(code FILES ${_glesGlslOutputs} + RELATIVE_TO "${CMAKE_CURRENT_SOURCE_DIR}/graphics/shaders/compiled" + PATH_TYPE_PREFIX "data/effects") + target_sources(code PRIVATE ${_glesGlslOutputs}) + endif() endforeach () From ae06d45b94cf31258f124d9e1a84ccf17bbc64a4 Mon Sep 17 00:00:00 2001 From: Salvador Cipolla Date: Sat, 30 May 2026 21:00:06 -0300 Subject: [PATCH 06/11] cleanup deferred-f.sdr --- code/def_files/data/effects/deferred-f.sdr | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/code/def_files/data/effects/deferred-f.sdr b/code/def_files/data/effects/deferred-f.sdr index 8da2612d3bd..b2dfb30922b 100644 --- a/code/def_files/data/effects/deferred-f.sdr +++ b/code/def_files/data/effects/deferred-f.sdr @@ -12,12 +12,11 @@ precision highp samplerCube; #include "shadows.sdr" //! #include "shadows.sdr" #include "z-compress.sdr" //! #include "z-compress.sdr" +#ifdef GL_ES layout(location = 0) out vec4 fragOut0; -layout(location = 1) out vec4 fragOut1; -layout(location = 2) out vec4 fragOut2; -layout(location = 3) out vec4 fragOut3; -layout(location = 4) out vec4 fragOut4; -layout(location = 5) out vec4 fragOut5; +#else +layout(location = 5) out vec4 fragOut0; +#endif uniform sampler2D ColorBuffer; uniform sampler2D NormalBuffer; @@ -287,10 +286,5 @@ void main() fragmentColor.rgb = computeLighting(specColor.rgb, diffColor, lightDir, normal.xyz, halfVec, eyeDir, roughness, fresnel, NdotL).rgb * diffuseLightColor * attenuation * area_normalisation; } - #ifdef GL_ES - fragOut5 = max(fragmentColor, vec4(0.0)); - #else - fragOut0 = max(fragmentColor, vec4(0.0)); - #endif - + fragOut0 = max(fragmentColor, vec4(0.0)); } From 28fba33cbde9b6c4c189989b0c2ce9bf048a32ac Mon Sep 17 00:00:00 2001 From: Salvador Cipolla Date: Sun, 31 May 2026 12:33:55 -0300 Subject: [PATCH 07/11] corrections and cleanup --- code/def_files/data/effects/decal-f.sdr | 17 +++++++--------- .../data/effects/deferred-clear-f.sdr | 1 + code/def_files/data/effects/deferred-f.sdr | 2 +- .../data/effects/effect-distort-f.sdr | 7 ------- code/def_files/data/effects/effect-f.sdr | 5 ----- code/def_files/data/effects/fxaa-f.sdr | 20 ++++++++++--------- .../data/effects/shield-impact-f.sdr | 4 ---- code/graphics/opengl/es_compatibility.h | 5 ----- code/graphics/opengl/gropenglshader.cpp | 7 ------- 9 files changed, 20 insertions(+), 48 deletions(-) diff --git a/code/def_files/data/effects/decal-f.sdr b/code/def_files/data/effects/decal-f.sdr index 9a44cc60e0e..7528f920160 100644 --- a/code/def_files/data/effects/decal-f.sdr +++ b/code/def_files/data/effects/decal-f.sdr @@ -12,9 +12,15 @@ precision highp sampler2DArray; #include "normals.sdr" #include "gamma.sdr" -layout (location=0) out vec4 fragOut0; // Diffuse buffer -> COLOR_ATTACHMENT0 + +layout (location=0) out vec4 fragOut0; // Diffuse buffer +#ifndef GL_ES +layout (location=1) out vec4 fragOut1; // Normal buffer +layout (location=2) out vec4 fragOut2; // Emissive buffer +#else layout (location=2) out vec4 fragOut1; // Normal buffer -> COLOR_ATTACHMENT2 layout (location=4) out vec4 fragOut2; // Emissive buffer -> COLOR_ATTACHMENT4 +#endif flat in mat4 invModelMatrix; flat in vec3 decalDirection; @@ -22,21 +28,12 @@ flat in float normal_angle_cutoff; flat in float angle_fade_start; flat in float alpha_scale; -#ifdef GL_ES -uniform highp sampler2D gDepthBuffer; -uniform highp sampler2D gNormalBuffer; - -uniform highp sampler2DArray diffuseMap; -uniform highp sampler2DArray glowMap; -uniform highp sampler2DArray normalMap; -#else uniform sampler2D gDepthBuffer; uniform sampler2D gNormalBuffer; uniform sampler2DArray diffuseMap; uniform sampler2DArray glowMap; uniform sampler2DArray normalMap; -#endif layout (std140) uniform decalGlobalData { mat4 viewMatrix; diff --git a/code/def_files/data/effects/deferred-clear-f.sdr b/code/def_files/data/effects/deferred-clear-f.sdr index 79e8c06cc5f..0f8fed7aa62 100644 --- a/code/def_files/data/effects/deferred-clear-f.sdr +++ b/code/def_files/data/effects/deferred-clear-f.sdr @@ -11,6 +11,7 @@ layout (location=2) out vec4 fragOut2; layout (location=3) out vec4 fragOut3; layout (location=4) out vec4 fragOut4; layout (location=5) out vec4 fragOut5; + void main() { fragOut0 = vec4(0.0, 0.0, 0.0, 1.0); // color diff --git a/code/def_files/data/effects/deferred-f.sdr b/code/def_files/data/effects/deferred-f.sdr index b2dfb30922b..d3333c5e2e8 100644 --- a/code/def_files/data/effects/deferred-f.sdr +++ b/code/def_files/data/effects/deferred-f.sdr @@ -12,7 +12,7 @@ precision highp samplerCube; #include "shadows.sdr" //! #include "shadows.sdr" #include "z-compress.sdr" //! #include "z-compress.sdr" -#ifdef GL_ES +#ifndef GL_ES layout(location = 0) out vec4 fragOut0; #else layout(location = 5) out vec4 fragOut0; diff --git a/code/def_files/data/effects/effect-distort-f.sdr b/code/def_files/data/effects/effect-distort-f.sdr index fb4ccecf7fa..61146f00ec9 100644 --- a/code/def_files/data/effects/effect-distort-f.sdr +++ b/code/def_files/data/effects/effect-distort-f.sdr @@ -11,17 +11,10 @@ in float fragOffset; layout(location=0) out vec4 fragOut0; -#ifdef GL_ES -uniform highp sampler2DArray baseMap; -uniform highp sampler2D depthMap; -uniform highp sampler2D distMap; -uniform highp sampler2D frameBuffer; -#else uniform sampler2DArray baseMap; uniform sampler2D depthMap; uniform sampler2D distMap; uniform sampler2D frameBuffer; -#endif layout (std140) uniform genericData { float window_width; diff --git a/code/def_files/data/effects/effect-f.sdr b/code/def_files/data/effects/effect-f.sdr index b201009f51e..061aaabe90e 100644 --- a/code/def_files/data/effects/effect-f.sdr +++ b/code/def_files/data/effects/effect-f.sdr @@ -16,13 +16,8 @@ in vec4 fragColor; layout (location=0) out vec4 fragOut0; -#ifdef GL_ES -uniform highp sampler2DArray baseMap; -uniform highp sampler2D depthMap; -#else uniform sampler2DArray baseMap; uniform sampler2D depthMap; -#endif layout (std140) uniform genericData { float window_width; diff --git a/code/def_files/data/effects/fxaa-f.sdr b/code/def_files/data/effects/fxaa-f.sdr index 52b5b27abe3..feaca8f6b4a 100644 --- a/code/def_files/data/effects/fxaa-f.sdr +++ b/code/def_files/data/effects/fxaa-f.sdr @@ -1,4 +1,8 @@ #ifdef GL_ES +#ifdef GL_EXT_gpu_shader5 + #extension GL_EXT_gpu_shader5 : enable + #define FXAA_GATHER4_ALPHA 1 +#endif precision highp float; precision highp int; precision highp sampler2D; @@ -11,15 +15,13 @@ precision highp samplerCube; #define FXAA_FAST_PIXEL_OFFSET 1 // With OpenGL 3.2 we can always do this #ifndef FXAA_GATHER4_ALPHA - #ifndef GL_ES - #ifdef GL_ARB_gpu_shader5 - #extension GL_ARB_gpu_shader5 : enable - #define FXAA_GATHER4_ALPHA 1 - #endif - #ifdef GL_NV_gpu_shader5 - #extension GL_NV_gpu_shader5 : enable - #define FXAA_GATHER4_ALPHA 1 - #endif + #ifdef GL_ARB_gpu_shader5 + #extension GL_ARB_gpu_shader5 : enable + #define FXAA_GATHER4_ALPHA 1 + #endif + #ifdef GL_NV_gpu_shader5 + #extension GL_NV_gpu_shader5 : enable + #define FXAA_GATHER4_ALPHA 1 #endif #ifndef FXAA_GATHER4_ALPHA #define FXAA_GATHER4_ALPHA 0 diff --git a/code/def_files/data/effects/shield-impact-f.sdr b/code/def_files/data/effects/shield-impact-f.sdr index f22b0e000cd..61eee8e24ab 100644 --- a/code/def_files/data/effects/shield-impact-f.sdr +++ b/code/def_files/data/effects/shield-impact-f.sdr @@ -14,11 +14,7 @@ in float fragNormOffset; layout (location=0) out vec4 fragOut0; -#ifdef GL_ES -uniform highp sampler2DArray shieldMap; -#else uniform sampler2DArray shieldMap; -#endif layout (std140) uniform genericData { mat4 shieldModelViewMatrix; diff --git a/code/graphics/opengl/es_compatibility.h b/code/graphics/opengl/es_compatibility.h index 17e0fb76f90..47ef2747765 100644 --- a/code/graphics/opengl/es_compatibility.h +++ b/code/graphics/opengl/es_compatibility.h @@ -324,11 +324,6 @@ inline void glDrawBuffer(GLenum buf) } } -// does not exist on ES, ES uses layout(location=) directly on shader -// Notes: -// -This function is not required to run. -#define glBindFragDataLocation(program, colorNumber, name) ((void)0) - // glPolygonMode() is not supported on ES, no wireframe, GL_FILL is default, GL_POINTS, and GL_LINES needs an alternative path // Notes: // -This function is not required to run. diff --git a/code/graphics/opengl/gropenglshader.cpp b/code/graphics/opengl/gropenglshader.cpp index 57f628f809d..2d82573c054 100644 --- a/code/graphics/opengl/gropenglshader.cpp +++ b/code/graphics/opengl/gropenglshader.cpp @@ -870,13 +870,6 @@ void opengl_compile_shader_actual(shader_type sdr, const uint &flags, opengl_sha glBindAttribLocation(program->getShaderHandle(), (GLint)i, GL_vertex_attrib_info[i].name.c_str()); } - // bind fragment data locations before we link the shader - glBindFragDataLocation(program->getShaderHandle(), 0, "fragOut0"); - glBindFragDataLocation(program->getShaderHandle(), 1, "fragOut1"); - glBindFragDataLocation(program->getShaderHandle(), 2, "fragOut2"); - glBindFragDataLocation(program->getShaderHandle(), 3, "fragOut3"); - glBindFragDataLocation(program->getShaderHandle(), 4, "fragOut4"); - if (do_shader_caching()) { // Enable shader caching glProgramParameteri(program->getShaderHandle(), GL_PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE); From 97ecb88a0739853bec3a6571afeb96a83b4c927e Mon Sep 17 00:00:00 2001 From: Salvador Cipolla Date: Sun, 31 May 2026 14:53:14 -0300 Subject: [PATCH 08/11] Correct ES warning --- code/graphics/opengl/es_compatibility.h | 1 + 1 file changed, 1 insertion(+) diff --git a/code/graphics/opengl/es_compatibility.h b/code/graphics/opengl/es_compatibility.h index 47ef2747765..c103bb2f08d 100644 --- a/code/graphics/opengl/es_compatibility.h +++ b/code/graphics/opengl/es_compatibility.h @@ -339,6 +339,7 @@ static inline void glQueryCounter(GLuint id, GLenum target) #else (void)id; #endif + (void)target; } // glGetCompressedTexImage not present on GLES and no equivalent From 419748371216ab2124397c529f6e58551e6ff93c Mon Sep 17 00:00:00 2001 From: Salvador Cipolla Date: Sun, 31 May 2026 15:29:46 -0300 Subject: [PATCH 09/11] fix main-f --- code/def_files/data/effects/main-f.sdr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/def_files/data/effects/main-f.sdr b/code/def_files/data/effects/main-f.sdr index 94cd93b1673..6603a1c382a 100644 --- a/code/def_files/data/effects/main-f.sdr +++ b/code/def_files/data/effects/main-f.sdr @@ -392,7 +392,7 @@ void main() #prereplace ENDIF_FLAG //MODEL_SDR_FLAG_DIFFUSE // This code will only be used by the forward renderer so we apply the fog effect to both the emissive and the base // color. - float fogDensityFinal = clamp(1 - pow(fogDensity, vertIn.fogDist) , 0.0, 1.0); + float fogDensityFinal = clamp(1.0 - pow(fogDensity, vertIn.fogDist) , 0.0, 1.0); baseColor.rgb = mix(emissiveColor.rgb + baseColor.rgb, finalFogColor, fogDensityFinal); emissiveColor.rgb = vec3(0.0); // Zero the emissive color since it has already been added by the previous line specColor.rgb *= fogDensityFinal; From 1771a58cd3dcbde0c44159dc38b5852cff34069b Mon Sep 17 00:00:00 2001 From: Salvador Cipolla Date: Wed, 3 Jun 2026 22:32:21 -0300 Subject: [PATCH 10/11] Delete envmap outColor --- code/def_files/data/effects/envmap-sphere-warp-f.sdr | 2 -- 1 file changed, 2 deletions(-) diff --git a/code/def_files/data/effects/envmap-sphere-warp-f.sdr b/code/def_files/data/effects/envmap-sphere-warp-f.sdr index 55d845a95bd..c24de4e1f3f 100644 --- a/code/def_files/data/effects/envmap-sphere-warp-f.sdr +++ b/code/def_files/data/effects/envmap-sphere-warp-f.sdr @@ -11,8 +11,6 @@ in vec4 fragTexCoord; layout(location=0) out vec4 fragOut0; -layout (location = 0) out vec4 outColor; - void main() { const float theta = -fragTexCoord.x * (2.0 * M_PI); const float phi = fragTexCoord.y * (M_PI) - (0.5 * M_PI); From 58769dd7040bed57f7d2fb55ed13da7f5c450a5f Mon Sep 17 00:00:00 2001 From: Salvador Cipolla Date: Wed, 17 Jun 2026 19:48:26 -0300 Subject: [PATCH 11/11] HW cull distance in GLES if supported --- code/def_files/data/effects/main-f.sdr | 7 ++++++- code/def_files/data/effects/main-g.sdr | 21 ++++++++++++------- code/def_files/data/effects/main-v.sdr | 18 +++++++++------- code/graphics/opengl/gropengl.cpp | 3 ++- .../default-material.frag.spv.gles.glsl | 10 ++++++++- .../default-material.vert.spv.gles.glsl | 12 ++++++++++- 6 files changed, 53 insertions(+), 18 deletions(-) diff --git a/code/def_files/data/effects/main-f.sdr b/code/def_files/data/effects/main-f.sdr index 6603a1c382a..1bb47af3ae6 100644 --- a/code/def_files/data/effects/main-f.sdr +++ b/code/def_files/data/effects/main-f.sdr @@ -1,5 +1,6 @@ //? #version 150 #ifdef GL_ES +#extension GL_EXT_clip_cull_distance: enable precision highp float; precision highp int; precision highp sampler2D; @@ -7,6 +8,10 @@ precision highp sampler2DArray; precision highp samplerCube; #endif +#if !defined(GL_ES) || defined(GL_EXT_clip_cull_distance) +#define USE_HW_CLIP_DISTANCE +#endif + #include "shadows.sdr" //! #include "shadows.sdr" #include "lighting.sdr" //! #include "lighting.sdr" #include "gamma.sdr" //! #include "gamma.sdr" @@ -215,7 +220,7 @@ vec3 CalculateLighting(vec3 normal, vec3 diffuseMaterial, vec3 specularMaterial, void main() { - #ifdef GL_ES + #ifndef USE_HW_CLIP_DISTANCE if (vertIn.vClipDist < 0.0) discard; #endif diff --git a/code/def_files/data/effects/main-g.sdr b/code/def_files/data/effects/main-g.sdr index 35b864accb4..f613ea1948d 100644 --- a/code/def_files/data/effects/main-g.sdr +++ b/code/def_files/data/effects/main-g.sdr @@ -1,5 +1,6 @@ #ifdef GL_ES #extension GL_EXT_gpu_shader5: enable +#extension GL_EXT_clip_cull_distance: enable precision highp float; precision highp int; precision highp sampler2D; @@ -9,6 +10,10 @@ precision highp samplerCube; #extension GL_ARB_gpu_shader5: enable #endif +#if !defined(GL_ES) || defined(GL_EXT_clip_cull_distance) +#define USE_HW_CLIP_DISTANCE +#endif + #conditional_include +"LARGE_SHADER" "main_large.sdr" #conditional_include -"LARGE_SHADER" "main_small.sdr" @@ -132,7 +137,7 @@ in VertexOutput { vec4 shadowUV[4]; vec4 shadowPos; #prereplace ENDIF_FLAG_COMPILED MODEL_SDR_FLAG_SHADOWS -#ifdef GL_ES +#ifndef USE_HW_CLIP_DISTANCE float vClipDist; #endif } vertIn[]; @@ -153,7 +158,7 @@ out VertexOutput { vec4 shadowPos; #prereplace ENDIF_FLAG_COMPILED MODEL_SDR_FLAG_SHADOWS -#ifdef GL_ES +#ifndef USE_HW_CLIP_DISTANCE float vClipDist; #endif } vertOut; @@ -205,11 +210,15 @@ out VertexOutput { #prereplace ENDIF_FLAG //MODEL_SDR_FLAG_SHADOWS if (use_clip_plane) { - #ifdef GL_ES + #ifndef USE_HW_CLIP_DISTANCE vertOut.vClipDist = vertIn[vert].vClipDist; #else gl_ClipDistance[0] = gl_in[vert].gl_ClipDistance[0]; #endif + } else { + #ifndef USE_HW_CLIP_DISTANCE + vertOut.vClipDist = 1.0; + #endif } EmitVertex(); } @@ -263,16 +272,14 @@ out VertexOutput { #prereplace ENDIF_FLAG //MODEL_SDR_FLAG_SHADOWS if (use_clip_plane) { - #ifdef GL_ES + #ifndef USE_HW_CLIP_DISTANCE vertOut.vClipDist = vertIn[vert].vClipDist; #else gl_ClipDistance[0] = gl_in[vert].gl_ClipDistance[0]; #endif } else { - #ifdef GL_ES + #ifndef USE_HW_CLIP_DISTANCE vertOut.vClipDist = 1.0; - #else - gl_ClipDistance[0] = 1.0; #endif } diff --git a/code/def_files/data/effects/main-v.sdr b/code/def_files/data/effects/main-v.sdr index d03819293a4..7ee40b205a7 100644 --- a/code/def_files/data/effects/main-v.sdr +++ b/code/def_files/data/effects/main-v.sdr @@ -1,6 +1,7 @@ //? #version 150 #ifdef GL_ES #extension GL_EXT_gpu_shader5: enable +#extension GL_EXT_clip_cull_distance: enable precision highp float; precision highp int; precision highp sampler2D; @@ -11,6 +12,10 @@ precision highp samplerBuffer; #extension GL_ARB_gpu_shader5: enable #endif +#if !defined(GL_ES) || defined(GL_EXT_clip_cull_distance) +#define USE_HW_CLIP_DISTANCE +#endif + #include "shadows.sdr" #conditional_include +"LARGE_SHADER" "main_large.sdr" @@ -135,7 +140,7 @@ out VertexOutput { vec4 shadowPos; #prereplace ENDIF_FLAG_COMPILED MODEL_SDR_FLAG_SHADOWS -#ifdef GL_ES +#ifndef USE_HW_CLIP_DISTANCE float vClipDist; #endif } vertOut; @@ -216,22 +221,21 @@ void main() #endif #prereplace ENDIF_FLAG //MODEL_SDR_FLAG_TRANSFORM - #ifdef GL_ES + #ifdef USE_HW_CLIP_DISTANCE if (use_clip_plane) { - vertOut.vClipDist = dot(clip_equation, modelMatrix * orient * vertex); + gl_ClipDistance[0] = dot(clip_equation, modelMatrix * orient * vertex); } else { - vertOut.vClipDist = 1.0; + gl_ClipDistance[0] = 1.0; } #else if (use_clip_plane) { - gl_ClipDistance[0] = dot(clip_equation, modelMatrix * orient * vertex); + vertOut.vClipDist = dot(clip_equation, modelMatrix * orient * vertex); } else { - gl_ClipDistance[0] = 1.0; + vertOut.vClipDist = 1.0; } #endif - #ifndef MODEL_SDR_FLAG_SHADOW_MAP vertOut.position = position; vertOut.normal = normal; diff --git a/code/graphics/opengl/gropengl.cpp b/code/graphics/opengl/gropengl.cpp index 79252e7eec3..9ef570b9169 100644 --- a/code/graphics/opengl/gropengl.cpp +++ b/code/graphics/opengl/gropengl.cpp @@ -1397,7 +1397,8 @@ bool gr_opengl_init(std::unique_ptr&& graphicsOps) "Deferred lightning is enabled in settings but the gpu does not support the minimum of 6 draw buffers. " "This will result in rendering errors."); } - + + mprintf((" HW Cull distance support : %s\n", GLAD_GL_EXT_clip_cull_distance ? NOX("YES") : NOX("NO"))); mprintf((" Precompiled shaders support : %s\n", GLAD_GL_OES_get_program_binary ? NOX("YES") : NOX("NO"))); mprintf((" Immutable buffer storage support : %s\n", GLAD_GL_EXT_buffer_storage ? NOX("YES") : NOX("NO"))); mprintf((" BGRA8888 format support: %s\n", GLAD_GL_EXT_texture_format_BGRA8888 ? NOX("YES") : NOX("NO"))); diff --git a/code/graphics/shaders/compiled/default-material.frag.spv.gles.glsl b/code/graphics/shaders/compiled/default-material.frag.spv.gles.glsl index a9a9b5c890e..eaa4710f2c7 100644 --- a/code/graphics/shaders/compiled/default-material.frag.spv.gles.glsl +++ b/code/graphics/shaders/compiled/default-material.frag.spv.gles.glsl @@ -1,9 +1,14 @@ #version 320 es +#extension GL_EXT_clip_cull_distance : enable precision highp float; precision highp int; precision highp sampler2D; precision highp sampler2DArray; +#if defined(GL_EXT_clip_cull_distance) +#define USE_HW_CLIP_DISTANCE +#endif + layout(std140) uniform genericData { mat4 modelMatrix; @@ -19,16 +24,20 @@ layout(std140) uniform genericData } _39; uniform sampler2DArray baseMap; +#ifndef USE_HW_CLIP_DISTANCE in highp float vClipDist; +#endif in vec4 fragTexCoord; in vec4 fragColor; layout (location=0) out vec4 fragOut0; void main() { +#ifndef USE_HW_CLIP_DISTANCE if (_39.clipEnabled != 0u && vClipDist < 0.0) { discard; } +#endif vec4 _48 = texture(baseMap, vec3(fragTexCoord.xy, float(_39.baseMapIndex))); if (_39.alphaThreshold > _48.w) { @@ -55,4 +64,3 @@ void main() } fragOut0 = mix(mix(vec4(_146.x, _146.y, _146.z, _48.w) * _148, vec4(_148.xyz, _146.x * _148.w), vec4(float(_39.alphaTexture))), _148, vec4(float(_39.noTexturing))) * _39.intensity; } - diff --git a/code/graphics/shaders/compiled/default-material.vert.spv.gles.glsl b/code/graphics/shaders/compiled/default-material.vert.spv.gles.glsl index b0cbd8e944b..aa17641dc11 100644 --- a/code/graphics/shaders/compiled/default-material.vert.spv.gles.glsl +++ b/code/graphics/shaders/compiled/default-material.vert.spv.gles.glsl @@ -1,9 +1,14 @@ #version 320 es +#extension GL_EXT_clip_cull_distance : enable precision highp float; precision highp int; precision highp sampler2D; precision highp sampler2DArray; +#if defined(GL_EXT_clip_cull_distance) +#define USE_HW_CLIP_DISTANCE +#endif + layout(std140) uniform genericData { mat4 modelMatrix; @@ -29,7 +34,9 @@ in vec4 vertTexCoord; out vec4 fragColor; in vec4 vertColor; in vec4 vertPosition; +#ifndef USE_HW_CLIP_DISTANCE out float vClipDist; +#endif void main() { @@ -37,6 +44,9 @@ void main() fragColor = vertColor * _22.color; gl_Position = (_36.projMatrix * _36.modelViewMatrix) * vertPosition; float d = dot(_22.clipEquation, _22.modelMatrix * vertPosition); +#ifdef USE_HW_CLIP_DISTANCE + gl_ClipDistance[0] = (_22.clipEnabled != 0u) ? d : 1.0; +#else vClipDist = (_22.clipEnabled != 0u) ? d : 1.0; +#endif } -