diff --git a/core/rend/gles/gles.cpp b/core/rend/gles/gles.cpp index 07e425594..d4cda6cad 100644 --- a/core/rend/gles/gles.cpp +++ b/core/rend/gles/gles.cpp @@ -68,16 +68,23 @@ const char *PixelCompatShader = R"( )"; static const char* GouraudSource = R"( -#if TARGET_GL == GL3 || TARGET_GL == GLES3 -#define NOPERSPECTIVE noperspective -#if pp_Gouraud == 0 -#define INTERPOLATION flat +#if TARGET_GL == GL3 || defined(GL_NV_shader_noperspective_interpolation) + #define NOPERSPECTIVE noperspective + #if pp_Gouraud == 0 + #define INTERPOLATION flat + #else + #define INTERPOLATION noperspective + #endif +#elif TARGET_GL == GLES3 + #define NOPERSPECTIVE smooth + #if pp_Gouraud == 0 + #define INTERPOLATION flat + #else + #define INTERPOLATION smooth + #endif #else -#define INTERPOLATION noperspective -#endif -#else -#define NOPERSPECTIVE -#define INTERPOLATION + #define NOPERSPECTIVE + #define INTERPOLATION #endif )"; @@ -852,7 +859,8 @@ static void create_modvol_shader() VertexSource vertexShader(false); OpenGlSource fragmentShader; - fragmentShader.addSource(PixelCompatShader) + fragmentShader.addConstant("pp_Gouraud", 0) + .addSource(PixelCompatShader) .addSource(GouraudSource) .addSource(ModifierVolumeShader); diff --git a/core/rend/vulkan/oit/oit_shaders.cpp b/core/rend/vulkan/oit/oit_shaders.cpp index f4bc8713e..825b127d3 100644 --- a/core/rend/vulkan/oit/oit_shaders.cpp +++ b/core/rend/vulkan/oit/oit_shaders.cpp @@ -36,12 +36,12 @@ layout (location = 4) in uvec4 in_base1; // New for OIT, only for OP layout (location = 5) in uvec4 in_offs1; layout (location = 6) in mediump vec2 in_uv1; -layout (location = 0) INTERPOLATION out lowp vec4 vtx_base; -layout (location = 1) INTERPOLATION out lowp vec4 vtx_offs; -layout (location = 2) noperspective out mediump vec3 vtx_uv; -layout (location = 3) INTERPOLATION out lowp vec4 vtx_base1; // New for OIT, only for OP/PT with 2-volume -layout (location = 4) INTERPOLATION out lowp vec4 vtx_offs1; -layout (location = 5) noperspective out mediump vec2 vtx_uv1; +layout (location = 0) INTERPOLATION out highp vec4 vtx_base; +layout (location = 1) INTERPOLATION out highp vec4 vtx_offs; +layout (location = 2) noperspective out highp vec3 vtx_uv; +layout (location = 3) INTERPOLATION out highp vec4 vtx_base1; // New for OIT, only for OP/PT with 2-volume +layout (location = 4) INTERPOLATION out highp vec4 vtx_offs1; +layout (location = 5) noperspective out highp vec2 vtx_uv1; void main() { @@ -65,6 +65,8 @@ void main() )"; static const char OITShaderHeader[] = R"( +precision highp float; + layout (std140, set = 0, binding = 1) uniform FragmentShaderUniforms { vec4 colorClampMin; @@ -168,12 +170,12 @@ layout (input_attachment_index = 0, set = 0, binding = 5) uniform subpassInput D #endif // Vertex input -layout (location = 0) INTERPOLATION in lowp vec4 vtx_base; -layout (location = 1) INTERPOLATION in lowp vec4 vtx_offs; -layout (location = 2) noperspective in mediump vec3 vtx_uv; -layout (location = 3) INTERPOLATION in lowp vec4 vtx_base1; // new for OIT. Only if 2 vol -layout (location = 4) INTERPOLATION in lowp vec4 vtx_offs1; -layout (location = 5) noperspective in mediump vec2 vtx_uv1; +layout (location = 0) INTERPOLATION in highp vec4 vtx_base; +layout (location = 1) INTERPOLATION in highp vec4 vtx_offs; +layout (location = 2) noperspective in highp vec3 vtx_uv; +layout (location = 3) INTERPOLATION in highp vec4 vtx_base1; // new for OIT. Only if 2 vol +layout (location = 4) INTERPOLATION in highp vec4 vtx_offs1; +layout (location = 5) noperspective in highp vec2 vtx_uv1; #if pp_FogCtrl != 2 || pp_TwoVolumes == 1 layout (set = 0, binding = 2) uniform sampler2D fog_table; @@ -215,7 +217,7 @@ void main() #if PASS == PASS_OIT // Manual depth testing - highp float frontDepth = subpassLoad(DepthTex).r; + float frontDepth = subpassLoad(DepthTex).r; if (gl_FragDepth < frontDepth) discard; #endif @@ -227,8 +229,8 @@ void main() discard; #endif - highp vec4 color = vtx_base; - lowp vec4 offset = vtx_offs; + vec4 color = vtx_base; + vec4 offset = vtx_offs; bool area1 = false; ivec2 cur_blend_mode = pushConstants.blend_mode0.xy; @@ -266,7 +268,7 @@ void main() #endif #if pp_Texture==1 { - highp vec4 texcol; + vec4 texcol; #if pp_TwoVolumes == 1 if (area1) #if pp_Palette == 0 @@ -282,8 +284,8 @@ void main() texcol = palettePixel(tex0, vtx_uv); #endif #if pp_BumpMap == 1 - highp float s = PI / 2.0 * (texcol.a * 15.0 * 16.0 + texcol.r * 15.0) / 255.0; - highp float r = 2.0 * PI * (texcol.g * 15.0 * 16.0 + texcol.b * 15.0) / 255.0; + float s = PI / 2.0 * (texcol.a * 15.0 * 16.0 + texcol.r * 15.0) / 255.0; + float r = 2.0 * PI * (texcol.g * 15.0 * 16.0 + texcol.b * 15.0) / 255.0; texcol.a = clamp(offset.a + offset.r * sin(s) + offset.g * cos(s) * cos(r - 2.0 * PI * offset.b), 0.0, 1.0); texcol.rgb = vec3(1.0, 1.0, 1.0); #else @@ -428,7 +430,7 @@ void main() )"; static const char OITModifierVolumeShader[] = R"( -layout (location = 0) noperspective in float depth; +layout (location = 0) noperspective in highp float depth; void main() { @@ -593,7 +595,7 @@ void main(void) )"; static const char OITTranslucentModvolShaderSource[] = R"( -layout (location = 0) noperspective in float depth; +layout (location = 0) noperspective in highp float depth; // Must match ModifierVolumeMode enum values #define MV_XOR 0 diff --git a/core/rend/vulkan/shaders.cpp b/core/rend/vulkan/shaders.cpp index 58265aed3..22b54994f 100644 --- a/core/rend/vulkan/shaders.cpp +++ b/core/rend/vulkan/shaders.cpp @@ -34,9 +34,9 @@ layout (location = 1) in uvec4 in_base; layout (location = 2) in uvec4 in_offs; layout (location = 3) in mediump vec2 in_uv; -layout (location = 0) INTERPOLATION out lowp vec4 vtx_base; -layout (location = 1) INTERPOLATION out lowp vec4 vtx_offs; -layout (location = 2) noperspective out mediump vec3 vtx_uv; +layout (location = 0) INTERPOLATION out highp vec4 vtx_base; +layout (location = 1) INTERPOLATION out highp vec4 vtx_offs; +layout (location = 2) noperspective out highp vec3 vtx_uv; void main() { @@ -85,9 +85,9 @@ layout (set = 0, binding = 3) uniform sampler2D palette; #endif // Vertex input -layout (location = 0) INTERPOLATION in lowp vec4 vtx_base; -layout (location = 1) INTERPOLATION in lowp vec4 vtx_offs; -layout (location = 2) noperspective in mediump vec3 vtx_uv; +layout (location = 0) INTERPOLATION in highp vec4 vtx_base; +layout (location = 1) INTERPOLATION in highp vec4 vtx_offs; +layout (location = 2) noperspective in highp vec3 vtx_uv; #if pp_FogCtrl != 2 layout (set = 0, binding = 2) uniform sampler2D fog_table; @@ -131,8 +131,8 @@ void main() discard; #endif - vec4 color = vtx_base; - vec4 offset = vtx_offs; + highp vec4 color = vtx_base; + highp vec4 offset = vtx_offs; #if pp_Gouraud == 1 color /= vtx_uv.z; offset /= vtx_uv.z; @@ -216,7 +216,7 @@ void main() //color.rgb = vec3(gl_FragCoord.w * uniformBuffer.sp_FOG_DENSITY / 128.0); - float w = vtx_uv.z * 100000.0; + highp float w = vtx_uv.z * 100000.0; gl_FragDepth = log2(1.0 + w) / 34.0; gl_FragColor = color; @@ -230,18 +230,11 @@ layout (std140, set = 0, binding = 0) uniform VertexShaderUniforms } uniformBuffer; layout (location = 0) in vec4 in_pos; -layout (location = 0) noperspective out float depth; +layout (location = 0) noperspective out highp float depth; void main() { - vec4 vpos = in_pos; - if (vpos.z < 0.0 || vpos.z > 3.4e37) - { - gl_Position = vec4(0.0, 0.0, 1.0, 1.0 / vpos.z); - return; - } - - vpos = uniformBuffer.normal_matrix * vpos; + vec4 vpos = uniformBuffer.normal_matrix * in_pos; depth = vpos.z; vpos.w = 1.0; vpos.z = 0.0; @@ -250,7 +243,7 @@ void main() )"; static const char ModVolFragmentShaderSource[] = R"( -layout (location = 0) noperspective in float depth; +layout (location = 0) noperspective in highp float depth; layout (location = 0) out vec4 FragColor; layout (push_constant) uniform pushBlock @@ -260,7 +253,7 @@ layout (push_constant) uniform pushBlock void main() { - float w = depth * 100000.0; + highp float w = depth * 100000.0; gl_FragDepth = log2(1.0 + w) / 34.0; FragColor = vec4(0.0, 0.0, 0.0, pushConstants.sp_ShaderColor); }