diff --git a/CMakeLists.txt b/CMakeLists.txt index 43508ae83f..7c8144d78a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -138,13 +138,13 @@ OPTION(FSO_BUILD_WITH_DISCORD "Build with Discord support" ON) OPTION(FSO_BUILD_WITH_OPENGL "Enable compilation of the OpenGL renderer" ON) OPTION(FSO_BUILD_WITH_OPENGL_DEBUG "Enables debug option for OpenGL" OFF) -OPTION(FSO_BUILD_WITH_OPENGL_ES "When building OpenGL, use OpenGL ES compatibility layer (External shaders only!)" OFF) +OPTION(FSO_BUILD_WITH_OPENGL_ES "When building OpenGL, use OpenGL ES compatibility layer" OFF) OPTION(FSO_BUILD_WITH_VULKAN "Enable compilation of the Vulkan renderer" ON) if(NOT FSO_BUILD_WITH_OPENGL AND FSO_BUILD_WITH_OPENGL_ES) # Disable GLES if not building with OpenGL - set(FSO_BUILD_WITH_OPENGL_ES OFF FORCE) + set(FSO_BUILD_WITH_OPENGL_ES OFF CACHE BOOL "" FORCE) endif() diff --git a/code/def_files/data/effects/batched-f.sdr b/code/def_files/data/effects/batched-f.sdr index 660787fe4e..e46e5208af 100644 --- a/code/def_files/data/effects/batched-f.sdr +++ b/code/def_files/data/effects/batched-f.sdr @@ -1,12 +1,16 @@ +#ifdef GL_ES +precision highp float; +precision highp sampler2DArray; +#endif #include "gamma.sdr" +layout(location=0) out vec4 fragOut0; + #ifdef VULKAN layout (location = 0) in vec4 fragTexCoord; layout (location = 1) in vec4 fragColor; -layout (location = 0) out vec4 fragOut0; - layout (set = 1, binding = 1) uniform sampler2DArray baseMap; layout (set = 2, binding = 0, std140) uniform genericData { @@ -17,8 +21,6 @@ layout (set = 2, binding = 0, std140) uniform genericData { in vec4 fragTexCoord; in vec4 fragColor; -out vec4 fragOut0; - uniform sampler2DArray baseMap; layout (std140) uniform genericData { diff --git a/code/def_files/data/effects/batched-v.sdr b/code/def_files/data/effects/batched-v.sdr index 9f1efb6f21..87bb3983ac 100644 --- a/code/def_files/data/effects/batched-v.sdr +++ b/code/def_files/data/effects/batched-v.sdr @@ -1,3 +1,7 @@ +#ifdef GL_ES +precision highp float; +#endif + #ifdef VULKAN layout (location = 0) in vec4 vertPosition; layout (location = 1) 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 20d8859a64..74fee1c1c1 100644 --- a/code/def_files/data/effects/bloom-comp-f.sdr +++ b/code/def_files/data/effects/bloom-comp-f.sdr @@ -1,11 +1,16 @@ +#ifdef GL_ES +precision highp float; +precision highp sampler2D; +#endif + +layout(location=0) out vec4 fragOut0; #ifdef VULKAN layout(location = 0) in vec2 fragTexCoord; -layout(location = 0) out vec4 fragOut0; layout(set = 1, binding = 1) uniform sampler2D bloomed; #else in vec4 fragTexCoord; -out vec4 fragOut0; + uniform sampler2D bloomed; #endif diff --git a/code/def_files/data/effects/blur-f.sdr b/code/def_files/data/effects/blur-f.sdr index 8063b8e4e0..47bcf42da0 100644 --- a/code/def_files/data/effects/blur-f.sdr +++ b/code/def_files/data/effects/blur-f.sdr @@ -1,9 +1,15 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +#endif + +layout(location = 0) out vec4 fragOut0; + #ifdef VULKAN layout(location = 0) in vec2 fragTexCoord; -layout(location = 0) out vec4 fragOut0; layout(set = 1, binding = 1) uniform sampler2D tex; #else -out vec4 fragOut0; in vec4 fragTexCoord; uniform sampler2D tex; #endif diff --git a/code/def_files/data/effects/brightpass-f.sdr b/code/def_files/data/effects/brightpass-f.sdr index e1632a23d1..219f65bd06 100644 --- a/code/def_files/data/effects/brightpass-f.sdr +++ b/code/def_files/data/effects/brightpass-f.sdr @@ -1,12 +1,18 @@ +#ifdef GL_ES +precision highp float; +precision highp sampler2D; +#endif + +layout(location = 0) out vec4 fragOut0; + #ifdef VULKAN layout(location = 0) in vec2 fragTexCoord; -layout(location = 0) out vec4 fragOut0; layout(set = 1, binding = 1) uniform sampler2D tex; #else in vec4 fragTexCoord; -out vec4 fragOut0; uniform sampler2D tex; #endif + const float Luminance = 0.08; const float fMiddleGray = 0.2; const float fWhiteCutoff = 0.4; diff --git a/code/def_files/data/effects/copy-f.sdr b/code/def_files/data/effects/copy-f.sdr index 28c29bdfac..52510a75a7 100644 --- a/code/def_files/data/effects/copy-f.sdr +++ b/code/def_files/data/effects/copy-f.sdr @@ -1,10 +1,16 @@ +#ifdef GL_ES +precision highp float; +precision highp sampler2D; +precision highp sampler2DArray; +#endif + +layout(location = 0) out vec4 fragOut0; + #ifdef VULKAN layout(location = 0) in vec2 fragTexCoord; -layout(location = 0) out vec4 fragOut0; layout(set = 1, binding = 1) uniform sampler2D tex; #else in vec4 fragTexCoord; -out vec4 fragOut0; #ifdef COPY_ARRAY uniform sampler2DArray tex; #else diff --git a/code/def_files/data/effects/decal-f.sdr b/code/def_files/data/effects/decal-f.sdr index 34d65a67ba..6c1577bcd3 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/ @@ -29,9 +35,14 @@ layout (set = 1, binding = 1) uniform sampler2DArray decalTextures; layout (set = 1, binding = 4) uniform sampler2D gDepthBuffer; layout (set = 1, binding = 6) uniform sampler2D gNormalBuffer; #else -out vec4 fragOut0; // Diffuse buffer -out vec4 fragOut1; // Normal buffer -out vec4 fragOut2; // Emissive buffer +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; @@ -124,7 +135,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 42d9914632..46998b7983 100644 --- a/code/def_files/data/effects/decal-v.sdr +++ b/code/def_files/data/effects/decal-v.sdr @@ -1,3 +1,7 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +#endif #ifdef VULKAN // Binding 0: box vertex positions diff --git a/code/def_files/data/effects/default-material-f.sdr b/code/def_files/data/effects/default-material-f.sdr index cec7df3a76..5d8df90178 100644 --- a/code/def_files/data/effects/default-material-f.sdr +++ b/code/def_files/data/effects/default-material-f.sdr @@ -1,3 +1,10 @@ +#ifdef GL_ES +#extension GL_EXT_clip_cull_distance : enable +precision highp float; +precision highp int; +precision highp sampler2DArray; +#endif + #ifdef VULKAN layout(set = 2, binding = 0, std140) #else @@ -20,22 +27,28 @@ uniform genericData { uint clipEnabled; }; +layout(location = 0) out vec4 fragOut0; + #ifdef VULKAN layout(set = 1, binding = 1) uniform sampler2DArray baseMap; layout(location = 0) in vec4 fragTexCoord; layout(location = 1) in vec4 fragColor; - -layout(location = 0) out vec4 fragOut0; +#ifdef SDR_FLAG_SW_CLIP_FALLBACK +layout(location = 2) in float vClipDist; +#endif #else +#ifdef SDR_FLAG_SW_CLIP_FALLBACK +in float vClipDist; +#endif + uniform sampler2DArray baseMap; in vec4 fragTexCoord; in vec4 fragColor; -out vec4 fragOut0; #endif @@ -43,6 +56,11 @@ out vec4 fragOut0; void main() { +#ifdef SDR_FLAG_SW_CLIP_FALLBACK + if (clipEnabled != 0u && vClipDist < 0.0) { + discard; + } +#endif 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; diff --git a/code/def_files/data/effects/default-material-v.sdr b/code/def_files/data/effects/default-material-v.sdr index 902240860e..bf016f7ea4 100644 --- a/code/def_files/data/effects/default-material-v.sdr +++ b/code/def_files/data/effects/default-material-v.sdr @@ -1,3 +1,9 @@ +#ifdef GL_ES +#extension GL_EXT_clip_cull_distance : enable +precision highp float; +precision highp int; +#endif + #ifdef VULKAN layout(set = 2, binding = 0, std140) #else @@ -38,10 +44,15 @@ layout(location = 2) in vec4 vertTexCoord; layout(location = 0) out vec4 fragTexCoord; layout(location = 1) out vec4 fragColor; +#ifdef SDR_FLAG_SW_CLIP_FALLBACK +layout(location = 2) out float vClipDist; +#endif #else -out float gl_ClipDistance[1]; +#ifdef SDR_FLAG_SW_CLIP_FALLBACK +out float vClipDist; +#endif out vec4 fragTexCoord; in vec4 vertTexCoord; @@ -58,13 +69,16 @@ void main() gl_Position = projMatrix * modelViewMatrix * vertPosition; if (clipEnabled != 0u) { + #ifndef SDR_FLAG_SW_CLIP_FALLBACK gl_ClipDistance[0] = dot(clipEquation, modelMatrix * vertPosition); + #else + vClipDist = dot(clipEquation, modelMatrix * vertPosition); + #endif } else { -#ifdef VULKAN - // Vulkan has no glEnable(GL_CLIP_DISTANCE0) equivalent — clip distances are - // always evaluated when declared in the shader. Must write a positive value - // when clipping is disabled to prevent undefined-value vertex culling. + #ifndef SDR_FLAG_SW_CLIP_FALLBACK gl_ClipDistance[0] = 1.0; -#endif + #else + vClipDist = 1.0; + #endif } } diff --git a/code/def_files/data/effects/deferred-clear-f.sdr b/code/def_files/data/effects/deferred-clear-f.sdr index 4d49695ef9..3faddb831f 100644 --- a/code/def_files/data/effects/deferred-clear-f.sdr +++ b/code/def_files/data/effects/deferred-clear-f.sdr @@ -1,9 +1,14 @@ -out vec4 fragOut0; -out vec4 fragOut1; -out vec4 fragOut2; -out vec4 fragOut3; -out vec4 fragOut4; -out vec4 fragOut5; +#ifdef GL_ES +precision highp float; +#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 d5d4dba032..0ae8434b34 100644 --- a/code/def_files/data/effects/deferred-f.sdr +++ b/code/def_files/data/effects/deferred-f.sdr @@ -1,13 +1,21 @@ //? #version 150 +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp samplerCube; +precision highp sampler2DArrayShadow; +#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" -#ifdef VULKAN +#ifndef GL_ES layout(location = 0) out vec4 fragOut0; #else -out vec4 fragOut0; +layout(location = 5) out vec4 fragOut0; //COLOR_ATTACHMENTn is on location n in ES, here it uses COLOR_ATTACHMENT5 #endif #ifdef VULKAN @@ -145,7 +153,7 @@ void GetLightInfo(vec3 position, in float alpha, in vec3 reflectDir, out vec3 li dist = length(lightDirOut); lightDist = dist; // 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 @@ -188,7 +196,7 @@ void GetLightInfo(vec3 position, in float alpha, in vec3 reflectDir, out vec3 li float dist = length(lightDirOut); lightDist = dist; // 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 @@ -235,11 +243,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. @@ -257,7 +265,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; @@ -338,6 +346,6 @@ 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; } - + 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 2c9d4b02c6..98fa87d7f6 100644 --- a/code/def_files/data/effects/deferred-v.sdr +++ b/code/def_files/data/effects/deferred-v.sdr @@ -1,3 +1,7 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +#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 b43907a39d..d06ff7409d 100644 --- a/code/def_files/data/effects/effect-distort-f.sdr +++ b/code/def_files/data/effects/effect-distort-f.sdr @@ -1,10 +1,16 @@ +#ifdef GL_ES +precision highp float; +precision highp sampler2D; +precision highp sampler2DArray; +#endif + +layout(location = 0) out vec4 fragOut0; + #ifdef VULKAN layout(location = 0) in vec4 fragTexCoord; layout(location = 1) in vec4 fragColor; layout(location = 2) in float fragOffset; -layout(location = 0) out vec4 fragOut0; - layout(set = 1, binding = 1) uniform sampler2DArray baseMap; layout(set = 1, binding = 4) uniform sampler2D depthMap; layout(set = 1, binding = 5) uniform sampler2D frameBuffer; @@ -14,8 +20,6 @@ in vec4 fragTexCoord; in vec4 fragColor; in float fragOffset; -out vec4 fragOut0; - uniform sampler2DArray baseMap; uniform sampler2D depthMap; uniform sampler2D distMap; diff --git a/code/def_files/data/effects/effect-distort-v.sdr b/code/def_files/data/effects/effect-distort-v.sdr index 5673b1baf3..2eb075be1d 100644 --- a/code/def_files/data/effects/effect-distort-v.sdr +++ b/code/def_files/data/effects/effect-distort-v.sdr @@ -1,3 +1,7 @@ +#ifdef GL_ES +precision highp float; +#endif + #ifdef VULKAN layout(location = 0) in vec4 vertPosition; layout(location = 1) in vec4 vertColor; diff --git a/code/def_files/data/effects/effect-f.sdr b/code/def_files/data/effects/effect-f.sdr index f46147830e..b8a73fbef8 100644 --- a/code/def_files/data/effects/effect-f.sdr +++ b/code/def_files/data/effects/effect-f.sdr @@ -1,15 +1,21 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +#endif #include "gamma.sdr" #include "z-compress.sdr" +layout(location = 0) out vec4 fragOut0; + #ifdef VULKAN layout(location = 0) in vec4 fragTexCoord; layout(location = 1) in vec4 fragColor; layout(location = 2) in float fragRadius; layout(location = 3) in vec4 fragPosition; -layout(location = 0) out vec4 fragOut0; - layout(set = 1, binding = 1) uniform sampler2DArray baseMap; layout(set = 1, binding = 4) uniform sampler2D depthMap; #else @@ -18,8 +24,6 @@ in vec4 fragPosition; in vec4 fragTexCoord; in vec4 fragColor; -out vec4 fragOut0; - uniform sampler2DArray baseMap; uniform sampler2D depthMap; #endif diff --git a/code/def_files/data/effects/effect-g.sdr b/code/def_files/data/effects/effect-g.sdr index d1cb231129..44e8545ee7 100644 --- a/code/def_files/data/effects/effect-g.sdr +++ b/code/def_files/data/effects/effect-g.sdr @@ -1,3 +1,7 @@ +#ifdef GL_ES +precision highp float; +#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 86244a7ee8..3662e9e864 100644 --- a/code/def_files/data/effects/effect-v.sdr +++ b/code/def_files/data/effects/effect-v.sdr @@ -1,3 +1,6 @@ +#ifdef GL_ES +precision highp float; +#endif #ifdef VULKAN layout(location = 0) in vec4 vertPosition; 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 ab2b407161..8cc562e693 100644 --- a/code/def_files/data/effects/envmap-sphere-warp-f.sdr +++ b/code/def_files/data/effects/envmap-sphere-warp-f.sdr @@ -1,11 +1,14 @@ #define M_PI 3.1415926535897932384626433832795 +#ifdef GL_ES +precision highp float; +precision highp samplerCube; +#endif + uniform samplerCube envmap; in vec4 fragTexCoord; -out vec4 fragOut0; - -layout (location = 0) out vec4 outColor; +layout(location=0) out vec4 fragOut0; void main() { const float theta = -fragTexCoord.x * (2.0 * M_PI); diff --git a/code/def_files/data/effects/fog-f.sdr b/code/def_files/data/effects/fog-f.sdr index 6c822bb67e..c252e91b61 100644 --- a/code/def_files/data/effects/fog-f.sdr +++ b/code/def_files/data/effects/fog-f.sdr @@ -1,17 +1,20 @@ +#ifdef GL_ES +precision highp float; +precision highp sampler2D; +#endif #include "gamma.sdr" +layout(location=0) out vec4 fragOut0; + #ifdef VULKAN layout(location = 0) in vec2 fragTexCoord; -layout(location = 0) out vec4 fragOut0; layout(set = 1, binding = 1) uniform sampler2D tex; layout(set = 1, binding = 4) uniform sampler2D depth_tex; #else in vec4 fragTexCoord; -out vec4 fragOut0; - uniform sampler2D tex; uniform sampler2D depth_tex; #endif @@ -40,7 +43,7 @@ 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)); @@ -50,7 +53,7 @@ void main() 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 329b68384b..0cd59026d2 100644 --- a/code/def_files/data/effects/fxaa-f.sdr +++ b/code/def_files/data/effects/fxaa-f.sdr @@ -1,3 +1,12 @@ +#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 sampler2D; +#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 @@ -500,8 +509,12 @@ layout(std140, set = 2, binding = 0) uniform genericData { #else 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; #endif void main() { diff --git a/code/def_files/data/effects/fxaa-v.sdr b/code/def_files/data/effects/fxaa-v.sdr index 22a9053f2a..fa5bc259b2 100644 --- a/code/def_files/data/effects/fxaa-v.sdr +++ b/code/def_files/data/effects/fxaa-v.sdr @@ -1,3 +1,6 @@ +#ifdef GL_ES +precision highp float; +#endif #ifdef VULKAN layout(location = 0) out vec2 fragTexCoord; @@ -10,7 +13,11 @@ void main() { 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 64dd348734..a9f6c03c50 100644 --- a/code/def_files/data/effects/fxaapre-f.sdr +++ b/code/def_files/data/effects/fxaapre-f.sdr @@ -1,6 +1,12 @@ +#ifdef GL_ES +precision highp float; +precision highp sampler2D; +#endif + +layout(location=0) out vec4 fragOut0; + #ifdef VULKAN layout(location = 0) in vec2 fragTexCoord; -layout(location = 0) out vec4 fragOut0; // [0]=real color (passed through as-is), [1]=luma detection proxy (see // getAADetectionView; may be the same view as [0] when not HDR) layout(set = 1, binding = 1) uniform sampler2D fxaaTex[2]; @@ -8,9 +14,9 @@ layout(set = 1, binding = 1) uniform sampler2D fxaaTex[2]; #define lumaTex fxaaTex[1] #else in vec4 fragTexCoord; -out vec4 fragOut0; uniform sampler2D tex; #endif + void main() { vec4 color = texture(tex, fragTexCoord.xy); #ifdef VULKAN diff --git a/code/def_files/data/effects/gamma-correct-f.sdr b/code/def_files/data/effects/gamma-correct-f.sdr index dc6ec53425..2f5201fcd1 100644 --- a/code/def_files/data/effects/gamma-correct-f.sdr +++ b/code/def_files/data/effects/gamma-correct-f.sdr @@ -1,12 +1,17 @@ +#ifdef GL_ES +precision highp float; +precision highp sampler2D; +#endif + #include "gamma.sdr" +layout(location=0)out vec4 fragOut0; + #ifdef VULKAN layout(location = 0) in vec2 fragTexCoord; -layout(location = 0) out vec4 fragOut0; layout(set = 1, binding = 1) uniform sampler2D tex; #else in vec4 fragTexCoord; -out vec4 fragOut0; uniform sampler2D tex; #endif diff --git a/code/def_files/data/effects/gamma.sdr b/code/def_files/data/effects/gamma.sdr index a57ce437bd..7067fef93b 100644 --- a/code/def_files/data/effects/gamma.sdr +++ b/code/def_files/data/effects/gamma.sdr @@ -1,3 +1,6 @@ +#ifdef GL_ES +precision highp float; +#endif const float SRGB_GAMMA = 2.2; const float SRGB_GAMMA_INVERSE = 1.0 / SRGB_GAMMA; diff --git a/code/def_files/data/effects/irrmap-f.sdr b/code/def_files/data/effects/irrmap-f.sdr index 556480d22e..ea07011469 100644 --- a/code/def_files/data/effects/irrmap-f.sdr +++ b/code/def_files/data/effects/irrmap-f.sdr @@ -1,15 +1,21 @@ //!#version 150 -#include "gamma.sdr" //! #include "gamma.sdr" +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp samplerCube; +#endif + +#include "gamma.sdr" #define PI 3.1415926535897932384626433832795 +layout(location = 0) out vec4 fragOut0; + #ifdef VULKAN layout(location = 0) in vec2 fragTexCoord; -layout(location = 0) out vec4 fragOut0; layout(set = 1, binding = 1) uniform samplerCube envmap; #else uniform samplerCube envmap; in vec4 fragTexCoord; -out vec4 fragOut0; #endif #ifdef VULKAN @@ -154,8 +160,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); @@ -191,5 +197,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 799617b52e..2166b61de7 100644 --- a/code/def_files/data/effects/lighting.sdr +++ b/code/def_files/data/effects/lighting.sdr @@ -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 cc4ff755da..694ed7f454 100644 --- a/code/def_files/data/effects/ls-f.sdr +++ b/code/def_files/data/effects/ls-f.sdr @@ -1,7 +1,14 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +#endif + +layout(location = 0) out vec4 fragOut0; #ifdef VULKAN layout(location = 0) in vec2 fragTexCoord; -layout(location = 0) out vec4 fragOut0; + layout(set = 1, binding = 1) uniform sampler2D textures[16]; #define scene textures[0] @@ -9,8 +16,6 @@ layout(set = 1, binding = 1) uniform sampler2D textures[16]; #else in vec4 fragTexCoord; -out vec4 fragOut0; - uniform sampler2D scene; uniform sampler2D cockpit; #endif diff --git a/code/def_files/data/effects/main-f.sdr b/code/def_files/data/effects/main-f.sdr index 746fe0973b..5b2beb5d91 100644 --- a/code/def_files/data/effects/main-f.sdr +++ b/code/def_files/data/effects/main-f.sdr @@ -1,4 +1,13 @@ //? #version 150 +#ifdef GL_ES +#extension GL_EXT_clip_cull_distance: enable +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler2DArray; +precision highp sampler2DArrayShadow; +#endif + #include "shadows.sdr" //! #include "shadows.sdr" #include "lighting.sdr" //! #include "lighting.sdr" #include "gamma.sdr" //! #include "gamma.sdr" @@ -112,6 +121,13 @@ uniform shadowCascadeParams { vec4 smoothness_factors[(NUM_SHADOW_CASCADES + 4 - 1) / 4]; }; + +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; + #ifdef VULKAN layout(set = 1, binding = 1) uniform sampler2DArray materialTextures[16]; #define sBasemap materialTextures[0] @@ -139,13 +155,12 @@ layout(location = 0) in VertexOutput { vec4 shadowUV[NUM_SHADOW_CASCADES]; vec4 shadowPos; #prereplace ENDIF_FLAG_COMPILED MODEL_SDR_FLAG_SHADOWS + +#ifdef SDR_FLAG_SW_CLIP_FALLBACK + float vClipDist; +#endif } vertIn; -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; #else #prereplace IF_FLAG_COMPILED MODEL_SDR_FLAG_DIFFUSE uniform sampler2DArray sBasemap; @@ -185,13 +200,10 @@ in VertexOutput { vec4 shadowUV[NUM_SHADOW_CASCADES]; vec4 shadowPos; #prereplace ENDIF_FLAG_COMPILED MODEL_SDR_FLAG_SHADOWS +#ifdef SDR_FLAG_SW_CLIP_FALLBACK + float vClipDist; +#endif } vertIn; - -out vec4 fragOut0; -out vec4 fragOut1; -out vec4 fragOut2; -out vec4 fragOut3; -out vec4 fragOut4; #endif vec3 FresnelLazarovEnv(vec3 specColor, vec3 view, vec3 normal, float gloss) @@ -283,6 +295,10 @@ vec3 CalculateLighting(vec3 normal, vec3 diffuseMaterial, vec3 specularMaterial, void main() { + #ifdef SDR_FLAG_SW_CLIP_FALLBACK + if (vertIn.vClipDist < 0.0) discard; + #endif + vec3 eyeDir = vec3(normalize(-vertIn.position).xyz); vec2 texCoord = vertIn.texCoord.xy; @@ -464,7 +480,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; @@ -509,11 +525,12 @@ 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; // and leave nothing for the light pass to add on top of it baseColor.rgb = vec3(0.0); specColor = vec4(0.0); diff --git a/code/def_files/data/effects/main-g.sdr b/code/def_files/data/effects/main-g.sdr index e348c386df..4c288fa4d4 100644 --- a/code/def_files/data/effects/main-g.sdr +++ b/code/def_files/data/effects/main-g.sdr @@ -1,4 +1,11 @@ +#ifdef GL_ES +#extension GL_EXT_gpu_shader5: enable +#extension GL_EXT_clip_cull_distance: enable +precision highp float; +precision highp int; +#else #extension GL_ARB_gpu_shader5: enable +#endif #conditional_include +"LARGE_SHADER" "main_large.sdr" #conditional_include -"LARGE_SHADER" "main_small.sdr" @@ -100,6 +107,9 @@ in VertexOutput { vec4 shadowUV[NUM_SHADOW_CASCADES]; vec4 shadowPos; #prereplace ENDIF_FLAG_COMPILED MODEL_SDR_FLAG_SHADOWS +#ifdef SDR_FLAG_SW_CLIP_FALLBACK + float vClipDist; +#endif } vertIn[]; out VertexOutput { @@ -117,6 +127,10 @@ out VertexOutput { vec4 shadowUV[NUM_SHADOW_CASCADES]; vec4 shadowPos; #prereplace ENDIF_FLAG_COMPILED MODEL_SDR_FLAG_SHADOWS + +#ifdef SDR_FLAG_SW_CLIP_FALLBACK + float vClipDist; +#endif } vertOut; #ifdef MODEL_SDR_FLAG_THICK_OUTLINES @@ -166,8 +180,19 @@ out VertexOutput { #prereplace ENDIF_FLAG //MODEL_SDR_FLAG_SHADOWS if (use_clip_plane != 0) { - gl_ClipDistance[0] = gl_in[vert].gl_ClipDistance[0]; + #ifdef SDR_FLAG_SW_CLIP_FALLBACK + vertOut.vClipDist = vertIn[vert].vClipDist; + #else + gl_ClipDistance[0] = gl_in[vert].gl_ClipDistance[0]; + #endif + } else { + #ifdef SDR_FLAG_SW_CLIP_FALLBACK + 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 a0adda205a..3dbe2cd77e 100644 --- a/code/def_files/data/effects/main-v.sdr +++ b/code/def_files/data/effects/main-v.sdr @@ -1,8 +1,18 @@ #ifndef VULKAN //? #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 samplerBuffer; +precision highp sampler2DArrayShadow; +#else #extension GL_ARB_gpu_shader5: enable #endif +#endif + #include "shadows.sdr" #conditional_include +"LARGE_SHADER" "main_large.sdr" @@ -145,6 +155,10 @@ layout(location = 0) out VertexOutput { vec4 shadowUV[NUM_SHADOW_CASCADES]; vec4 shadowPos; #prereplace ENDIF_FLAG_COMPILED MODEL_SDR_FLAG_SHADOWS + +#ifdef SDR_FLAG_SW_CLIP_FALLBACK + float vClipDist; +#endif } vertOut; #else #prereplace IF_FLAG_COMPILED MODEL_SDR_FLAG_TRANSFORM @@ -166,6 +180,10 @@ out VertexOutput { vec4 shadowUV[NUM_SHADOW_CASCADES]; vec4 shadowPos; #prereplace ENDIF_FLAG_COMPILED MODEL_SDR_FLAG_SHADOWS + +#ifdef SDR_FLAG_SW_CLIP_FALLBACK + float vClipDist; +#endif } vertOut; #define TEXELS_PER_MATRIX 4 @@ -247,12 +265,20 @@ void main() } #prereplace ENDIF_FLAG //MODEL_SDR_FLAG_TRANSFORM - // Clip plane - if(use_clip_plane != 0) { - gl_ClipDistance[0] = dot(clip_equation, modelMatrix * orient * vertex); - } else { - gl_ClipDistance[0] = 1.0; - } + #ifndef SDR_FLAG_SW_CLIP_FALLBACK + if (use_clip_plane != 0) { + gl_ClipDistance[0] = dot(clip_equation, modelMatrix * orient * vertex); + } else { + gl_ClipDistance[0] = 1.0; + } + #else + if (use_clip_plane != 0) { + vertOut.vClipDist = dot(clip_equation, modelMatrix * orient * vertex); + } else { + vertOut.vClipDist = 1.0; + } + #endif + vertOut.position = position; vertOut.normal = normal; diff --git a/code/def_files/data/effects/msaa-f.sdr b/code/def_files/data/effects/msaa-f.sdr index 85ce8d36af..ddee352792 100644 --- a/code/def_files/data/effects/msaa-f.sdr +++ b/code/def_files/data/effects/msaa-f.sdr @@ -1,7 +1,10 @@ -#include "z-compress.sdr" +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2DMS; +#endif -#ifdef VULKAN -layout(location = 0) in vec2 fragTexCoord; +#include "z-compress.sdr" layout(location = 0) out vec4 fragOut0; layout(location = 1) out vec4 fragOut1; @@ -9,6 +12,9 @@ layout(location = 2) out vec4 fragOut2; layout(location = 3) out vec4 fragOut3; layout(location = 4) out vec4 fragOut4; +#ifdef VULKAN +layout(location = 0) in vec2 fragTexCoord; + layout(set = 1, binding = 1) uniform sampler2DMS msaaTex[6]; #define texColor msaaTex[0] #define texPos msaaTex[1] @@ -23,12 +29,7 @@ layout(std140, set = 2, binding = 0) uniform genericData { }; #else in vec4 fragTexCoord; -out vec4 fragOut0; -out vec4 fragOut1; -out vec4 fragOut2; -out vec4 fragOut3; -out vec4 fragOut4; -out vec4 fragOut5; +layout(location=5)out vec4 fragOut5; uniform sampler2DMS texColor; uniform sampler2DMS texPos; @@ -176,7 +177,7 @@ float getMedianDist(ivec2 texel) { //Fallback, do front first float getMedianDist(ivec2 texel) { - float minDist = -1000000; + float minDist = -1000000.0; for(int i = 0; i < samples; i++) { minDist = max(minDist, uncompress_depth_value(texelFetch(texPos, texel, i).z)); } @@ -190,7 +191,7 @@ float getMedianDist(ivec2 texel) { void main() { - vec2 texSize = textureSize(texColor); + vec2 texSize = vec2(textureSize(texColor)); #ifdef VULKAN ivec2 texel = ivec2(texSize * fragTexCoord); #else @@ -206,7 +207,7 @@ void main() vec4 normal = vec4(0); vec4 specular = vec4(0); vec4 emissive = vec4(0); - float depth = 0; + float depth = 0.0; for(int i = 0; i < SAMPLE_CNT; i++) { vec4 localPos = texelFetch(texPos, texel, i); diff --git a/code/def_files/data/effects/nanovg-f.sdr b/code/def_files/data/effects/nanovg-f.sdr index dbe4170306..4ba74a86c9 100644 --- a/code/def_files/data/effects/nanovg-f.sdr +++ b/code/def_files/data/effects/nanovg-f.sdr @@ -1,3 +1,8 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2DArray; +#endif #ifdef VULKAN layout (location = 0) in vec2 ftcoord; diff --git a/code/def_files/data/effects/nanovg-v.sdr b/code/def_files/data/effects/nanovg-v.sdr index 2974de708e..89a56d5a4c 100644 --- a/code/def_files/data/effects/nanovg-v.sdr +++ b/code/def_files/data/effects/nanovg-v.sdr @@ -1,3 +1,7 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +#endif #ifdef VULKAN layout (location = 0) in vec4 vertPosition; diff --git a/code/def_files/data/effects/normals.sdr b/code/def_files/data/effects/normals.sdr index 8123bd1374..185dc5cbff 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 6e3134e068..3b06379b9b 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 6e12a5e20f..29bc2a78ae 100644 --- a/code/def_files/data/effects/post-f.sdr +++ b/code/def_files/data/effects/post-f.sdr @@ -1,11 +1,16 @@ +#ifdef GL_ES +precision highp float; +precision highp sampler2D; +#endif + +layout(location = 0) out vec4 fragOut0; + #ifdef VULKAN layout(location = 0) in vec2 fragTexCoord; -layout(location = 0) out vec4 fragOut0; layout(set = 1, binding = 1) uniform sampler2D tex; layout(set = 1, binding = 4) uniform sampler2D depth_tex; #else in vec4 fragTexCoord; -out vec4 fragOut0; uniform sampler2D tex; uniform sampler2D depth_tex; #endif diff --git a/code/def_files/data/effects/rocketui-f.sdr b/code/def_files/data/effects/rocketui-f.sdr index 688d2ec5fe..a3559ab4b8 100644 --- a/code/def_files/data/effects/rocketui-f.sdr +++ b/code/def_files/data/effects/rocketui-f.sdr @@ -1,10 +1,17 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2DArray; +#endif + +layout(location = 0) out vec4 fragOut0; #ifdef VULKAN layout(location = 0) in vec2 fragTexCoord; layout(location = 1) in vec4 fragColor; layout(location = 2) in vec2 fragScreenPosition; -layout(location = 0) out vec4 fragOut0; + layout(set = 1, binding = 1) uniform sampler2DArray baseMap; #else @@ -12,8 +19,6 @@ in vec2 fragTexCoord; in vec4 fragColor; in vec2 fragScreenPosition; -out vec4 fragOut0; - uniform sampler2DArray baseMap; #endif diff --git a/code/def_files/data/effects/rocketui-v.sdr b/code/def_files/data/effects/rocketui-v.sdr index 07ae245966..df966d8a1d 100644 --- a/code/def_files/data/effects/rocketui-v.sdr +++ b/code/def_files/data/effects/rocketui-v.sdr @@ -1,3 +1,7 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +#endif #ifdef VULKAN layout(location = 0) in vec2 vertPosition; diff --git a/code/def_files/data/effects/shadow_map-f.sdr b/code/def_files/data/effects/shadow_map-f.sdr index fff405831f..23067e898a 100644 --- a/code/def_files/data/effects/shadow_map-f.sdr +++ b/code/def_files/data/effects/shadow_map-f.sdr @@ -1,5 +1,24 @@ //? #version 150 +#ifdef GL_ES +#extension GL_EXT_clip_cull_distance: enable +precision highp float; +#endif + +#ifdef SDR_FLAG_SW_CLIP_FALLBACK +#ifdef VULKAN +layout(location = 0) in VertexOutput { + float vClipDist; +} vertIn; +#else +in VertexOutput { + float vClipDist; +} vertIn; +#endif +#endif void main() { +#ifdef SDR_FLAG_SW_CLIP_FALLBACK + if (vertIn.vClipDist < 0.0) discard; +#endif } diff --git a/code/def_files/data/effects/shadow_map-g.sdr b/code/def_files/data/effects/shadow_map-g.sdr index 6375b79300..4b196e9463 100644 --- a/code/def_files/data/effects/shadow_map-g.sdr +++ b/code/def_files/data/effects/shadow_map-g.sdr @@ -1,9 +1,16 @@ //? #version 150 +#ifdef GL_ES +#extension GL_EXT_gpu_shader5: enable +#extension GL_EXT_clip_cull_distance: enable +precision highp float; +precision highp int; +#else #extension GL_ARB_gpu_shader5: enable +#endif layout (triangles) in; layout (triangle_strip, max_vertices = 3) out; -#ifdef GL_ARB_gpu_shader5 +#if defined(GL_ARB_gpu_shader5) || defined(GL_EXT_gpu_shader5) layout(invocations = NUM_SHADOW_CASCADES) in; #endif @@ -24,16 +31,25 @@ layout (std140) uniform shadowCascadeParams { }; in VertexOutput { -#if !defined(GL_ARB_gpu_shader5) +#if !defined(GL_ARB_gpu_shader5) && !defined(GL_EXT_gpu_shader5) float instance; #endif float clipModel; vec3 normal; +#ifdef SDR_FLAG_SW_CLIP_FALLBACK + float vClipDist; +#endif } vertIn[]; +#ifdef SDR_FLAG_SW_CLIP_FALLBACK +out VertexOutput { + float vClipDist; +} vertOut; +#endif + void main(void) { -#ifdef GL_ARB_gpu_shader5 +#if defined(GL_ARB_gpu_shader5) || defined(GL_EXT_gpu_shader5) if (gl_InvocationID >= cascade_count) return; int cascade_id = cascade_offset + gl_InvocationID; #else @@ -49,7 +65,12 @@ void main(void) } gl_Layer = cascade_id; - gl_ClipDistance[0] = gl_in[vert].gl_ClipDistance[0]; + + #ifdef SDR_FLAG_SW_CLIP_FALLBACK + vertOut.vClipDist = vertIn[vert].vClipDist; + #else + gl_ClipDistance[0] = gl_in[vert].gl_ClipDistance[0]; + #endif EmitVertex(); } diff --git a/code/def_files/data/effects/shadow_map-v.sdr b/code/def_files/data/effects/shadow_map-v.sdr index 736ff37f16..3d846ad3af 100644 --- a/code/def_files/data/effects/shadow_map-v.sdr +++ b/code/def_files/data/effects/shadow_map-v.sdr @@ -1,9 +1,16 @@ //? #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 samplerBuffer; +#else #extension GL_ARB_gpu_shader5: enable - #ifndef GEOMETRY_FALLBACK #extension GL_ARB_shader_viewport_layer_array : enable #endif +#endif #ifdef VULKAN layout(location = 0) in vec4 vertPosition; @@ -66,12 +73,25 @@ uniform samplerBuffer transform_tex; // supports writing gl_Layer from the vertex shader, see CAPABILITY_FAST_SHADOWS). #ifdef GEOMETRY_FALLBACK out VertexOutput { -#if !defined(GL_ARB_gpu_shader5) +#if !defined(GL_ARB_gpu_shader5) && !defined(GL_EXT_gpu_shader5) float instance; #endif float clipModel; vec3 normal; +#ifdef SDR_FLAG_SW_CLIP_FALLBACK + float vClipDist; +#endif } vertOut; +#elif defined(SDR_FLAG_SW_CLIP_FALLBACK) +#ifdef VULKAN +layout(location = 0) out VertexOutput { + float vClipDist; +} vertOut; +#else +out VertexOutput { + float vClipDist; +} vertOut; +#endif #endif #define TEXELS_PER_MATRIX 4 @@ -112,7 +132,7 @@ void main() #ifdef VULKAN int instanceIndex = gl_InstanceIndex; #else - #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 @@ -133,11 +153,19 @@ void main() gl_Position = position; } +#ifndef SDR_FLAG_SW_CLIP_FALLBACK if (use_clip_plane != 0) { gl_ClipDistance[0] = dot(clip_equation, modelMatrix * orient * vertex); } else { gl_ClipDistance[0] = 1.0; } +#else + if (use_clip_plane != 0) { + vertOut.vClipDist = dot(clip_equation, modelMatrix * orient * vertex); + } else { + vertOut.vClipDist = 1.0; + } +#endif #ifdef GEOMETRY_FALLBACK vertOut.normal = normal; diff --git a/code/def_files/data/effects/shield-impact-f.sdr b/code/def_files/data/effects/shield-impact-f.sdr index e847867a9b..fbdc1ecd14 100644 --- a/code/def_files/data/effects/shield-impact-f.sdr +++ b/code/def_files/data/effects/shield-impact-f.sdr @@ -1,21 +1,22 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2DArray; +#endif #include "gamma.sdr" const float EMISSIVE_GAIN = 2.0; +layout(location = 0) out vec4 fragOut0; + #ifdef VULKAN layout(location = 0) in vec4 fragImpactUV; layout(location = 1) in float fragNormOffset; - -layout(location = 0) out vec4 fragOut0; - layout(set = 1, binding = 1) uniform sampler2DArray shieldMap; #else in vec4 fragImpactUV; in float fragNormOffset; - -out vec4 fragOut0; - uniform sampler2DArray shieldMap; #endif diff --git a/code/def_files/data/effects/shield-impact-v.sdr b/code/def_files/data/effects/shield-impact-v.sdr index 22f423cb3f..ee078d041a 100644 --- a/code/def_files/data/effects/shield-impact-v.sdr +++ b/code/def_files/data/effects/shield-impact-v.sdr @@ -1,3 +1,7 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +#endif #ifdef VULKAN layout(location = 0) in vec4 vertPosition; diff --git a/code/def_files/data/effects/smaa-blend-f.sdr b/code/def_files/data/effects/smaa-blend-f.sdr index 055d4b617b..cbb8f3a591 100644 --- a/code/def_files/data/effects/smaa-blend-f.sdr +++ b/code/def_files/data/effects/smaa-blend-f.sdr @@ -1,3 +1,7 @@ +#ifdef GL_ES +precision highp float; +precision highp sampler2D; +#endif #ifdef VULKAN layout(std140, set = 2, binding = 0) uniform genericData { @@ -16,13 +20,13 @@ layout (std140) uniform genericData { #include "SMAA.sdr" +layout(location=0) out vec4 fragOut0; + #ifdef VULKAN layout(location = 0) in vec2 fragTexCoord; layout(location = 1) in vec2 fragPixcoord; layout(location = 2) in vec4 fragOffset[3]; -layout(location = 0) out vec4 fragOut0; - // [0]=edgesTex, [1]=areaTex, [2]=searchTex layout(set = 1, binding = 1) uniform sampler2D smaaTex[3]; #define edgesTex smaaTex[0] @@ -33,8 +37,6 @@ in vec2 fragTexCoord; in vec2 fragPixcoord; in vec4 fragOffset[3]; -out vec4 fragOut0; - uniform sampler2D edgesTex; uniform sampler2D areaTex; uniform sampler2D searchTex; diff --git a/code/def_files/data/effects/smaa-edge-f.sdr b/code/def_files/data/effects/smaa-edge-f.sdr index 3628177a08..24e27ee0dc 100644 --- a/code/def_files/data/effects/smaa-edge-f.sdr +++ b/code/def_files/data/effects/smaa-edge-f.sdr @@ -1,3 +1,7 @@ +#ifdef GL_ES +precision highp float; +precision highp sampler2D; +#endif #ifdef VULKAN layout(std140, set = 2, binding = 0) uniform genericData { @@ -16,19 +20,17 @@ layout (std140) uniform genericData { #include "SMAA.sdr" +layout(location = 0) out vec4 fragOut0; + #ifdef VULKAN layout(location = 0) in vec2 fragTexCoord; layout(location = 1) in vec4 fragOffset[3]; -layout(location = 0) out vec4 fragOut0; - layout(set = 1, binding = 1) uniform sampler2D colorTex; #else in vec2 fragTexCoord; in vec4 fragOffset[3]; -out vec4 fragOut0; - uniform sampler2D colorTex; #endif diff --git a/code/def_files/data/effects/smaa-neighbour-f.sdr b/code/def_files/data/effects/smaa-neighbour-f.sdr index 56813d9ca5..18973d57d4 100644 --- a/code/def_files/data/effects/smaa-neighbour-f.sdr +++ b/code/def_files/data/effects/smaa-neighbour-f.sdr @@ -1,3 +1,7 @@ +#ifdef GL_ES +precision highp float; +precision highp sampler2D; +#endif #ifdef VULKAN layout(std140, set = 2, binding = 0) uniform genericData { @@ -16,11 +20,12 @@ layout (std140) uniform genericData { #include "SMAA.sdr" +layout(location = 0) out vec4 fragOut0; + #ifdef VULKAN layout(location = 0) in vec2 fragTexCoord; layout(location = 1) in vec4 fragOffset; -layout(location = 0) out vec4 fragOut0; // [0]=colorTex, [1]=blendTex layout(set = 1, binding = 1) uniform sampler2D smaaTex[2]; @@ -30,8 +35,6 @@ layout(set = 1, binding = 1) uniform sampler2D smaaTex[2]; in vec2 fragTexCoord; in vec4 fragOffset; -out vec4 fragOut0; - uniform sampler2D colorTex; uniform sampler2D blendTex; #endif diff --git a/code/def_files/data/effects/smaa-resolve-f.sdr b/code/def_files/data/effects/smaa-resolve-f.sdr index fffe936741..4151d19ea4 100644 --- a/code/def_files/data/effects/smaa-resolve-f.sdr +++ b/code/def_files/data/effects/smaa-resolve-f.sdr @@ -1,10 +1,15 @@ +#ifdef GL_ES +precision highp float; +precision highp sampler2D; +#endif + +layout(location = 0) out vec4 fragOut0; + #ifdef VULKAN layout(location = 0) in vec2 fragTexCoord; -layout(location = 0) out vec4 fragOut0; layout(set = 1, binding = 1) uniform sampler2D tex; #else in vec4 fragTexCoord; -out vec4 fragOut0; uniform sampler2D tex; #endif diff --git a/code/def_files/data/effects/tonemapping-f.sdr b/code/def_files/data/effects/tonemapping-f.sdr index 98d7a04838..93d12a134c 100644 --- a/code/def_files/data/effects/tonemapping-f.sdr +++ b/code/def_files/data/effects/tonemapping-f.sdr @@ -1,13 +1,18 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +#endif #include "gamma.sdr" +layout(location=0) out vec4 fragOut0; + #ifdef VULKAN layout(location = 0) in vec2 fragTexCoord; -layout(location = 0) out vec4 fragOut0; layout(set = 1, binding = 1) uniform sampler2D tex; #else in vec4 fragTexCoord; -out vec4 fragOut0; uniform sampler2D tex; #endif diff --git a/code/def_files/data/effects/video-f.sdr b/code/def_files/data/effects/video-f.sdr index 8ea4044baa..0322b26813 100644 --- a/code/def_files/data/effects/video-f.sdr +++ b/code/def_files/data/effects/video-f.sdr @@ -1,6 +1,12 @@ +#ifdef GL_ES +precision highp float; +precision highp sampler2DArray; +#endif + +layout(location = 0) out vec4 fragOut0; + #ifdef VULKAN layout(location = 0) in vec4 fragTexCoord; -layout(location = 0) out vec4 fragOut0; layout(set = 1, binding = 1) uniform sampler2DArray textures[16]; #define ytex textures[0] @@ -8,7 +14,6 @@ layout(set = 1, binding = 1) uniform sampler2DArray textures[16]; #define vtex textures[2] #else in vec4 fragTexCoord; -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 b00e721317..6fe0c0e5e5 100644 --- a/code/def_files/data/effects/volumetric-f.sdr +++ b/code/def_files/data/effects/volumetric-f.sdr @@ -1,7 +1,14 @@ +#ifdef GL_ES +precision highp float; +precision highp int; +precision highp sampler2D; +precision highp sampler3D; +#endif + +layout(location = 0) out vec4 fragOut0; #ifdef VULKAN layout(location = 0) in vec2 fragTexCoord; -layout(location = 0) out vec4 fragOut0; layout(set = 1, binding = 1) uniform sampler2D tex2D[16]; #define composite tex2D[0] #define emissive tex2D[1] @@ -10,7 +17,7 @@ layout(set = 1, binding = 5) uniform sampler3D volume_tex; layout(set = 1, binding = 6) uniform sampler3D noise_volume_tex; #else in vec4 fragTexCoord; -out vec4 fragOut0; + layout (binding = 0) uniform sampler2D composite; layout (binding = 1) uniform sampler2D emissive; layout (binding = 2) uniform sampler2D depth_tex; @@ -77,7 +84,7 @@ void main() #else vec4 eyeDirection = p_inv * vec4(fragTexCoord.xy * 2.0 - 1.0, -1, 1); #endif - eyeDirection.w = 0; + eyeDirection.w = 0.0; vec3 rayDirection = normalize((v_inv * eyeDirection).xyz); vec4 color_in = texture(composite, fragTexCoord.xy); @@ -103,14 +110,14 @@ void main() #endif //The t at which the ray enters the nebula cube - float maxtMin = max(0,max(tMin.x, max(tMin.y, tMin.z))); + float maxtMin = max(0.0, max(tMin.x, max(tMin.y, tMin.z))); //The t at which the ray leaves the nebula cube float mintMax = min(fragDepth, min(tMax.x, min(tMax.y, tMax.z))); //The cumulative one minus alpha value of the nebula. Corresponds to the multiplier of the current step when additively drawing to a fragment for which the steps closer to the camera are already drawn. - float cumOMAlpha = 1; + float cumOMAlpha = 1.0; //The cumulative distance already travelled through the nebula. - float cumnebdist = 0; + float cumnebdist = 0.0; //The color of the current fragment vec3 cumcolor = vec3(0, 0, 0); @@ -121,6 +128,14 @@ void main() vec3 sidestep = 1.0 / vec3(textureSize(volume_tex, 0)); +#ifdef GL_ES + // The emissive texture has a complete mip chain generated by the engine. + ivec2 emissiveSize = textureSize(emissive, 0); + float maxEmissiveLod = float(findMSB(max(emissiveSize.x, emissiveSize.y))); +#else + float maxEmissiveLod = float(textureQueryLevels(emissive) - 1); +#endif + for(float stept = maxtMin; stept < mintMax;) { //Step setup vec3 position = camera + rayDirection * stept - nebPos; @@ -159,7 +174,7 @@ void main() #ifdef NOISE //Mix the actual nebula color with the noise color depending on the product of the noise channels multiplied with intensity, smooth-clamped from 0 to 1 vec3 stepcolor_neb = mix(nebulaColor, noiseColor, - smoothstep(0, 1, (textureGrad(noise_volume_tex, position / noiseColorScale1, gradX, gradY).r + textureGrad(noise_volume_tex, position / noiseColorScale2, gradX, gradY).g) / 2.0 * noiseIntensity)); + smoothstep(0.0, 1.0, (textureGrad(noise_volume_tex, position / noiseColorScale1, gradX, gradY).r + textureGrad(noise_volume_tex, position / noiseColorScale2, gradX, gradY).g) / 2.0 * noiseIntensity)); #else vec3 stepcolor_neb = nebulaColor; #endif @@ -169,19 +184,19 @@ void main() //From the current position in the volumetric cloud, sample towards the sun to test whether or not the current part of the nebula is bright or not for(int dlstep = 1; dlstep <= directionalLightSampleSteps; dlstep++){ //TODO Sample these in a cone towards the sun, not just a line. Also add the high-distance sample for concave nebulae - vec3 dlsteppos = (position - globalLightDirection * (dlstep * directionalLightStepSize)) / nebSize + 0.5; - float dlstepalpha = textureGrad(volume_tex, dlsteppos, gradX, gradY).a * step(0, dlsteppos.x) * step(dlsteppos.x, 1) * step(0, dlsteppos.y) * step(dlsteppos.y, 1) * step(0, dlsteppos.z) * step(dlsteppos.z, 1); + vec3 dlsteppos = (position - globalLightDirection * (float(dlstep) * directionalLightStepSize)) / nebSize + 0.5; + float dlstepalpha = textureGrad(volume_tex, dlsteppos, gradX, gradY).a * step(0.0, dlsteppos.x) * step(dlsteppos.x, 1.0) * step(0.0, dlsteppos.y) * step(dlsteppos.y, 1.0) * step(0.0, dlsteppos.z) * step(dlsteppos.z, 1.0); directionalLightDepth += dlstepalpha * directionalLightStep; } - stepcolor_diffuse *= beer_powder_norm * (1 - exp(-directionalLightDepth * 2.0)) * exp(-directionalLightDepth); + stepcolor_diffuse *= beer_powder_norm * (1.0 - exp(-directionalLightDepth * 2.0)) * exp(-directionalLightDepth); //Emissive cumnebdist += stepcolor_alpha * stepsize_current; - vec3 emissive_lod = textureLod(emissive, fragTexCoord.xy, clamp(cumnebdist * emissiveSpreadFactor, 0, float(textureQueryLevels(emissive) - 1))).rgb; - vec3 stepcolor_emissive = clamp(emissive_lod.rgb * pow(alphalim, 1.0 / (opacitydistance / ((fragDepth - stept) * emissiveFalloff + 0.01))) * emissiveIntensity, 0, 1); + vec3 emissive_lod = textureLod(emissive, fragTexCoord.xy, clamp(cumnebdist * emissiveSpreadFactor, 0.0, maxEmissiveLod)).rgb; + vec3 stepcolor_emissive = clamp(emissive_lod.rgb * pow(alphalim, 1.0 / (opacitydistance / ((fragDepth - stept) * emissiveFalloff + 0.01))) * emissiveIntensity, 0.0, 1.0); //Step finish - vec3 stepcolor = clamp(stepcolor_diffuse + stepcolor_emissive, 0, 1); + vec3 stepcolor = clamp(stepcolor_diffuse + stepcolor_emissive, 0.0, 1.0); cumcolor += stepalpha * cumOMAlpha * stepcolor; } diff --git a/code/graphics/opengl/es_compatibility.h b/code/graphics/opengl/es_compatibility.h index a864be1545..5ccece3378 100644 --- a/code/graphics/opengl/es_compatibility.h +++ b/code/graphics/opengl/es_compatibility.h @@ -32,6 +32,7 @@ #define GL_CLAMP_VERTEX_COLOR 0x891A #define GL_CLAMP_FRAGMENT_COLOR 0x891B #define GL_FIXED_ONLY 0x891D +#define GLAD_GL_ARB_shader_viewport_layer_array 0 // Disabled, no gl_layer in vertex shader //0x8DAE //Enums Redefinitions #define GL_CLIP_DISTANCE0 GL_CLIP_DISTANCE0_EXT // GL_EXT_clip_cull_distance @@ -48,6 +49,7 @@ #define GLAD_GL_ARB_texture_storage GL_TRUE // ES 3.2 #define GLAD_GL_ARB_draw_buffers_blend GL_TRUE // ES 3.2 (glBlendFunci and glBlendEquationi) #define GLAD_GL_ARB_vertex_attrib_binding GL_TRUE // ES 3.1 +#define GL_DEPTH_CLAMP GL_DEPTH_CLAMP_EXT //Functions Redefinitions #define glBlendFunciARB glBlendFunci // ES 3.2 @@ -234,9 +236,7 @@ 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. +// ES uses layout(location = ) directly on shader #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 @@ -254,6 +254,7 @@ static inline void glQueryCounter(GLuint id, GLenum target) #else (void)id; #endif + (void)target; } // glGetCompressedTexImage not present on GLES and no equivalent diff --git a/code/graphics/opengl/gropengl.cpp b/code/graphics/opengl/gropengl.cpp index 73f1e100c8..509406d4cd 100644 --- a/code/graphics/opengl/gropengl.cpp +++ b/code/graphics/opengl/gropengl.cpp @@ -1453,7 +1453,9 @@ 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((" Depth Clamp support : %s\n", GLAD_GL_EXT_depth_clamp ? NOX("YES") : NOX("NO"))); + 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/opengl/gropenglshader.cpp b/code/graphics/opengl/gropenglshader.cpp index 41c3142d15..335bbceb42 100644 --- a/code/graphics/opengl/gropenglshader.cpp +++ b/code/graphics/opengl/gropenglshader.cpp @@ -178,10 +178,20 @@ static SCP_string opengl_shader_get_header(shader_type type_id, int flags, bool #ifndef USE_OPENGL_ES sflags << "#version " << GLSL_version << " core\n"; + if (GLSL_version < 330) { + sflags << "#extension GL_ARB_explicit_attrib_location : enable\n"; + } #else sflags << "#version " << GLSL_version << " es\n"; #endif sflags << "#define OPENGL\n"; + +#ifdef USE_OPENGL_ES + if (!GLAD_GL_EXT_clip_cull_distance) { + sflags << "#define SDR_FLAG_SW_CLIP_FALLBACK\n"; + } +#endif + sflags << shader_get_shadow_cascade_defines(); sflags << shader_get_rt_shadow_light_limit_define(); diff --git a/code/graphics/opengl/gropenglstate.cpp b/code/graphics/opengl/gropenglstate.cpp index 824bc09b36..060eb6dd42 100644 --- a/code/graphics/opengl/gropenglstate.cpp +++ b/code/graphics/opengl/gropenglstate.cpp @@ -360,6 +360,13 @@ GLboolean opengl_state::ClipDistance(GLint num, bool state) GLboolean save_state = clipdistance_Status[num]; +#ifdef USE_OPENGL_ES + if (!GLAD_GL_EXT_clip_cull_distance) { + clipdistance_Status[num] = state; + return save_state; + } +#endif + if (state != clipdistance_Status[num]) { if (state) { glEnable(GL_CLIP_DISTANCE0+num); diff --git a/code/graphics/opengl/gropengltnl.cpp b/code/graphics/opengl/gropengltnl.cpp index 7061314fb8..d2f64076d9 100644 --- a/code/graphics/opengl/gropengltnl.cpp +++ b/code/graphics/opengl/gropengltnl.cpp @@ -732,7 +732,13 @@ void gr_opengl_shadow_map_start(matrix4 *shadow_view_matrix, const matrix *light glClear(GL_DEPTH_BUFFER_BIT); +#ifdef USE_OPENGL_ES + if (GLAD_GL_EXT_depth_clamp) { + glEnable(GL_DEPTH_CLAMP); + } +#else glEnable(GL_DEPTH_CLAMP); +#endif Glowpoint_override_save = Glowpoint_override; Glowpoint_override = true; @@ -753,7 +759,13 @@ void gr_opengl_shadow_map_end() { gr_end_view_matrix(); +#ifdef USE_OPENGL_ES + if (GLAD_GL_EXT_depth_clamp) { + glDisable(GL_DEPTH_CLAMP); + } +#else glDisable(GL_DEPTH_CLAMP); +#endif gr_zbuffer_set(ZBUFFER_TYPE_FULL); GL_state.PopFramebufferState(); @@ -1136,6 +1148,12 @@ void opengl_tnl_set_material_nanovg(nanovg_material* material_info) { void opengl_tnl_set_material_decal(decal_material* material_info) { opengl_tnl_set_material(material_info, false); +#ifdef USE_OPENGL_ES + // ES decal outputs use G-buffer locations instead of packed draw-buffer indices. + GL_state.SetAlphaBlendModei(2, material_info->get_blend_mode(1)); + GL_state.SetAlphaBlendModei(4, material_info->get_blend_mode(2)); +#endif + float u_scale, v_scale; uint32_t array_index; diff --git a/code/graphics/vulkan/VulkanRendererSetup.cpp b/code/graphics/vulkan/VulkanRendererSetup.cpp index bcb5b57d6c..9ce690fa02 100644 --- a/code/graphics/vulkan/VulkanRendererSetup.cpp +++ b/code/graphics/vulkan/VulkanRendererSetup.cpp @@ -459,8 +459,11 @@ bool VulkanRenderer::initialize() setTextureManager(m_textureManager.get()); // Initialize shader manager + if (m_deviceFeatures.shaderClipDistance != VK_TRUE) { + mprintf(("Vulkan: HW clip distance not supported, using software clip distance fallback\n")); + } m_shaderManager = std::make_unique(); - if (!m_shaderManager->init(m_device.get())) { + if (!m_shaderManager->init(m_device.get(), m_deviceFeatures.shaderClipDistance == VK_TRUE)) { nprintf(("vulkan", "Failed to initialize Vulkan shader manager!\n")); return false; } diff --git a/code/graphics/vulkan/VulkanShader.cpp b/code/graphics/vulkan/VulkanShader.cpp index da9a29bc5d..d1e7763fb0 100644 --- a/code/graphics/vulkan/VulkanShader.cpp +++ b/code/graphics/vulkan/VulkanShader.cpp @@ -34,7 +34,7 @@ void vulkan_recompile_all_shaders(const std::function& pro VulkanShaderManager::VulkanShaderManager() = default; VulkanShaderManager::~VulkanShaderManager() = default; -bool VulkanShaderManager::init(vk::Device device) +bool VulkanShaderManager::init(vk::Device device, bool hwClipDistance) { if (m_initialized) { return true; @@ -44,7 +44,7 @@ bool VulkanShaderManager::init(vk::Device device) // Initialize runtime shader compiler m_compiler = std::make_unique(); - if (!m_compiler->init()) { + if (!m_compiler->init(hwClipDistance)) { nprintf(("vulkan", "VulkanShaderManager: Failed to initialize shader compiler!\n")); return false; } diff --git a/code/graphics/vulkan/VulkanShader.h b/code/graphics/vulkan/VulkanShader.h index 0f3e13381c..25a1c724ee 100644 --- a/code/graphics/vulkan/VulkanShader.h +++ b/code/graphics/vulkan/VulkanShader.h @@ -59,7 +59,7 @@ public: * @param device Vulkan logical device * @return true on success */ - bool init(vk::Device device); + bool init(vk::Device device, bool hwClipDistance); /** * @brief Shutdown and release all shader modules diff --git a/code/graphics/vulkan/VulkanShaderCompiler.cpp b/code/graphics/vulkan/VulkanShaderCompiler.cpp index 2ff077b19e..5be2672e50 100644 --- a/code/graphics/vulkan/VulkanShaderCompiler.cpp +++ b/code/graphics/vulkan/VulkanShaderCompiler.cpp @@ -102,8 +102,9 @@ VulkanShadercLibrary::VulkanShadercLibrary() VulkanShaderCompiler::VulkanShaderCompiler() = default; VulkanShaderCompiler::~VulkanShaderCompiler() = default; -bool VulkanShaderCompiler::init() +bool VulkanShaderCompiler::init(bool hwClipDistance) { + m_hwClipDistance = hwClipDistance; if (m_initialized) { return true; } @@ -148,6 +149,13 @@ SCP_string VulkanShaderCompiler::buildHeader(vk::ShaderStageFlagBits /*stage*/, // shaderc automatically predefines VULKAN=100 when targeting Vulkan, // so we do NOT define it here — doing so causes a "Macro redefined" error. + // gl_ClipDistance[] requires the shaderClipDistance device feature. When the + // device supports it, use the hardware clip path, otherwise + // the shaders fall back to the vClipDist varying (software clipping). + if (!m_hwClipDistance) { + header += "#define SDR_FLAG_SW_CLIP_FALLBACK\n"; + } + // Blinn-Phong lighting model (matches OpenGL's opengl_shader_get_header) if (Detail.lighting < 3) { header += "#define FLAG_LIGHT_MODEL_BLINN_PHONG\n"; diff --git a/code/graphics/vulkan/VulkanShaderCompiler.h b/code/graphics/vulkan/VulkanShaderCompiler.h index 73837ef7b6..a4913e2371 100644 --- a/code/graphics/vulkan/VulkanShaderCompiler.h +++ b/code/graphics/vulkan/VulkanShaderCompiler.h @@ -23,7 +23,7 @@ public: VulkanShaderCompiler(); ~VulkanShaderCompiler(); - bool init(); + bool init(bool hwClipDistance); void shutdown(); /** @@ -69,6 +69,7 @@ private: std::unique_ptr m_shaderc; bool m_initialized = false; + bool m_hwClipDistance = false; }; } // namespace graphics::vulkan diff --git a/freespace2/SDLGraphicsOperations.cpp b/freespace2/SDLGraphicsOperations.cpp index 32702c0fa3..4c5a45c2b7 100644 --- a/freespace2/SDLGraphicsOperations.cpp +++ b/freespace2/SDLGraphicsOperations.cpp @@ -328,8 +328,9 @@ std::unique_ptr SDLGraphicsOperations::createOpenGLContext(os Assertion(ImGui::GetCurrentContext() != nullptr, "Can't use ImGui without a valid context!"); - #ifndef USE_OPENGL_ES ImGui_ImplSDL3_InitForOpenGL(viewport->toSDLWindow(), ctx); + + #ifndef USE_OPENGL_ES ImGui_ImplOpenGL3_Init(); #else ImGui_ImplOpenGL3_Init("#version 300 es"); diff --git a/lib/opengl/gl/glad_es/include/glad/glad.h b/lib/opengl/gl/glad_es/include/glad/glad.h index 550c4ad13b..5f5cdf5d54 100644 --- a/lib/opengl/gl/glad_es/include/glad/glad.h +++ b/lib/opengl/gl/glad_es/include/glad/glad.h @@ -1,6 +1,6 @@ /* - OpenGL ES loader generated by glad 0.1.36 on Wed Aug 27 15:16:54 2025. + OpenGL ES loader generated by glad 0.1.36 on Sat Jul 4 19:49:32 2026. Language/Generator: C/C++ Specification: gl @@ -10,6 +10,7 @@ GL_EXT_buffer_storage, GL_EXT_clip_cull_distance, GL_EXT_color_buffer_float, + GL_EXT_depth_clamp, GL_EXT_disjoint_timer_query, GL_EXT_gpu_shader5, GL_EXT_multisampled_render_to_texture, @@ -27,9 +28,9 @@ Reproducible: False Commandline: - --profile="core" --api="gles2=3.2" --generator="c" --spec="gl" --extensions="GL_EXT_buffer_storage,GL_EXT_clip_cull_distance,GL_EXT_color_buffer_float,GL_EXT_disjoint_timer_query,GL_EXT_gpu_shader5,GL_EXT_multisampled_render_to_texture,GL_EXT_multisampled_render_to_texture2,GL_EXT_texture_compression_bptc,GL_EXT_texture_compression_s3tc,GL_EXT_texture_filter_anisotropic,GL_EXT_texture_format_BGRA8888,GL_KHR_debug,GL_KHR_texture_compression_astc_ldr,GL_OES_get_program_binary" + --profile="core" --api="gles2=3.2" --generator="c" --spec="gl" --extensions="GL_EXT_buffer_storage,GL_EXT_clip_cull_distance,GL_EXT_color_buffer_float,GL_EXT_depth_clamp,GL_EXT_disjoint_timer_query,GL_EXT_gpu_shader5,GL_EXT_multisampled_render_to_texture,GL_EXT_multisampled_render_to_texture2,GL_EXT_texture_compression_bptc,GL_EXT_texture_compression_s3tc,GL_EXT_texture_filter_anisotropic,GL_EXT_texture_format_BGRA8888,GL_KHR_debug,GL_KHR_texture_compression_astc_ldr,GL_OES_get_program_binary" Online: - https://glad.dav1d.de/#profile=core&language=c&specification=gl&loader=on&api=gles2%3D3.2&extensions=GL_EXT_buffer_storage&extensions=GL_EXT_clip_cull_distance&extensions=GL_EXT_color_buffer_float&extensions=GL_EXT_disjoint_timer_query&extensions=GL_EXT_gpu_shader5&extensions=GL_EXT_multisampled_render_to_texture&extensions=GL_EXT_multisampled_render_to_texture2&extensions=GL_EXT_texture_compression_bptc&extensions=GL_EXT_texture_compression_s3tc&extensions=GL_EXT_texture_filter_anisotropic&extensions=GL_EXT_texture_format_BGRA8888&extensions=GL_KHR_debug&extensions=GL_KHR_texture_compression_astc_ldr&extensions=GL_OES_get_program_binary + https://glad.dav1d.de/#profile=core&language=c&specification=gl&loader=on&api=gles2%3D3.2&extensions=GL_EXT_buffer_storage&extensions=GL_EXT_clip_cull_distance&extensions=GL_EXT_color_buffer_float&extensions=GL_EXT_depth_clamp&extensions=GL_EXT_disjoint_timer_query&extensions=GL_EXT_gpu_shader5&extensions=GL_EXT_multisampled_render_to_texture&extensions=GL_EXT_multisampled_render_to_texture2&extensions=GL_EXT_texture_compression_bptc&extensions=GL_EXT_texture_compression_s3tc&extensions=GL_EXT_texture_filter_anisotropic&extensions=GL_EXT_texture_format_BGRA8888&extensions=GL_KHR_debug&extensions=GL_KHR_texture_compression_astc_ldr&extensions=GL_OES_get_program_binary */ @@ -2257,6 +2258,7 @@ GLAPI PFNGLTEXSTORAGE3DMULTISAMPLEPROC glad_glTexStorage3DMultisample; #define GL_CLIP_DISTANCE5_EXT 0x3005 #define GL_CLIP_DISTANCE6_EXT 0x3006 #define GL_CLIP_DISTANCE7_EXT 0x3007 +#define GL_DEPTH_CLAMP_EXT 0x864F #define GL_QUERY_COUNTER_BITS_EXT 0x8864 #define GL_CURRENT_QUERY_EXT 0x8865 #define GL_QUERY_RESULT_EXT 0x8866 @@ -2366,6 +2368,10 @@ GLAPI int GLAD_GL_EXT_clip_cull_distance; #define GL_EXT_color_buffer_float 1 GLAPI int GLAD_GL_EXT_color_buffer_float; #endif +#ifndef GL_EXT_depth_clamp +#define GL_EXT_depth_clamp 1 +GLAPI int GLAD_GL_EXT_depth_clamp; +#endif #ifndef GL_EXT_disjoint_timer_query #define GL_EXT_disjoint_timer_query 1 GLAPI int GLAD_GL_EXT_disjoint_timer_query; diff --git a/lib/opengl/gl/glad_es/src/glad.c b/lib/opengl/gl/glad_es/src/glad.c index e7bae0f786..df24c8490e 100644 --- a/lib/opengl/gl/glad_es/src/glad.c +++ b/lib/opengl/gl/glad_es/src/glad.c @@ -1,6 +1,6 @@ /* - OpenGL ES loader generated by glad 0.1.36 on Wed Aug 27 15:16:54 2025. + OpenGL ES loader generated by glad 0.1.36 on Sat Jul 4 19:49:32 2026. Language/Generator: C/C++ Specification: gl @@ -10,6 +10,7 @@ GL_EXT_buffer_storage, GL_EXT_clip_cull_distance, GL_EXT_color_buffer_float, + GL_EXT_depth_clamp, GL_EXT_disjoint_timer_query, GL_EXT_gpu_shader5, GL_EXT_multisampled_render_to_texture, @@ -27,9 +28,9 @@ Reproducible: False Commandline: - --profile="core" --api="gles2=3.2" --generator="c" --spec="gl" --extensions="GL_EXT_buffer_storage,GL_EXT_clip_cull_distance,GL_EXT_color_buffer_float,GL_EXT_disjoint_timer_query,GL_EXT_gpu_shader5,GL_EXT_multisampled_render_to_texture,GL_EXT_multisampled_render_to_texture2,GL_EXT_texture_compression_bptc,GL_EXT_texture_compression_s3tc,GL_EXT_texture_filter_anisotropic,GL_EXT_texture_format_BGRA8888,GL_KHR_debug,GL_KHR_texture_compression_astc_ldr,GL_OES_get_program_binary" + --profile="core" --api="gles2=3.2" --generator="c" --spec="gl" --extensions="GL_EXT_buffer_storage,GL_EXT_clip_cull_distance,GL_EXT_color_buffer_float,GL_EXT_depth_clamp,GL_EXT_disjoint_timer_query,GL_EXT_gpu_shader5,GL_EXT_multisampled_render_to_texture,GL_EXT_multisampled_render_to_texture2,GL_EXT_texture_compression_bptc,GL_EXT_texture_compression_s3tc,GL_EXT_texture_filter_anisotropic,GL_EXT_texture_format_BGRA8888,GL_KHR_debug,GL_KHR_texture_compression_astc_ldr,GL_OES_get_program_binary" Online: - https://glad.dav1d.de/#profile=core&language=c&specification=gl&loader=on&api=gles2%3D3.2&extensions=GL_EXT_buffer_storage&extensions=GL_EXT_clip_cull_distance&extensions=GL_EXT_color_buffer_float&extensions=GL_EXT_disjoint_timer_query&extensions=GL_EXT_gpu_shader5&extensions=GL_EXT_multisampled_render_to_texture&extensions=GL_EXT_multisampled_render_to_texture2&extensions=GL_EXT_texture_compression_bptc&extensions=GL_EXT_texture_compression_s3tc&extensions=GL_EXT_texture_filter_anisotropic&extensions=GL_EXT_texture_format_BGRA8888&extensions=GL_KHR_debug&extensions=GL_KHR_texture_compression_astc_ldr&extensions=GL_OES_get_program_binary + https://glad.dav1d.de/#profile=core&language=c&specification=gl&loader=on&api=gles2%3D3.2&extensions=GL_EXT_buffer_storage&extensions=GL_EXT_clip_cull_distance&extensions=GL_EXT_color_buffer_float&extensions=GL_EXT_depth_clamp&extensions=GL_EXT_disjoint_timer_query&extensions=GL_EXT_gpu_shader5&extensions=GL_EXT_multisampled_render_to_texture&extensions=GL_EXT_multisampled_render_to_texture2&extensions=GL_EXT_texture_compression_bptc&extensions=GL_EXT_texture_compression_s3tc&extensions=GL_EXT_texture_filter_anisotropic&extensions=GL_EXT_texture_format_BGRA8888&extensions=GL_KHR_debug&extensions=GL_KHR_texture_compression_astc_ldr&extensions=GL_OES_get_program_binary */ #include @@ -501,6 +502,7 @@ PFNGLWAITSYNCPROC glad_glWaitSync = NULL; int GLAD_GL_EXT_buffer_storage = 0; int GLAD_GL_EXT_clip_cull_distance = 0; int GLAD_GL_EXT_color_buffer_float = 0; +int GLAD_GL_EXT_depth_clamp = 0; int GLAD_GL_EXT_disjoint_timer_query = 0; int GLAD_GL_EXT_gpu_shader5 = 0; int GLAD_GL_EXT_multisampled_render_to_texture = 0; @@ -969,6 +971,7 @@ static int find_extensionsGLES2(void) { GLAD_GL_EXT_buffer_storage = has_ext("GL_EXT_buffer_storage"); GLAD_GL_EXT_clip_cull_distance = has_ext("GL_EXT_clip_cull_distance"); GLAD_GL_EXT_color_buffer_float = has_ext("GL_EXT_color_buffer_float"); + GLAD_GL_EXT_depth_clamp = has_ext("GL_EXT_depth_clamp"); GLAD_GL_EXT_disjoint_timer_query = has_ext("GL_EXT_disjoint_timer_query"); GLAD_GL_EXT_gpu_shader5 = has_ext("GL_EXT_gpu_shader5"); GLAD_GL_EXT_multisampled_render_to_texture = has_ext("GL_EXT_multisampled_render_to_texture");