From 2eda9314adb0bceb1c369b71987b4817ff3e1ef4 Mon Sep 17 00:00:00 2001 From: luboslenco Date: Sat, 16 Nov 2024 01:21:56 +0100 Subject: [PATCH] gles fixes done --- armorpaint/shaders/dilate_pass.frag.glsl | 39 ++++++++++-------------- base/shaders/ssao_blur_pass.frag.glsl | 23 ++++---------- 2 files changed, 22 insertions(+), 40 deletions(-) diff --git a/armorpaint/shaders/dilate_pass.frag.glsl b/armorpaint/shaders/dilate_pass.frag.glsl index e6df46aa9..75792d2d5 100644 --- a/armorpaint/shaders/dilate_pass.frag.glsl +++ b/armorpaint/shaders/dilate_pass.frag.glsl @@ -8,53 +8,46 @@ in vec2 tex_coord; out vec4 frag_color; #ifdef ESSL -#define CONST_ARRAY_BEGIN(t, v, n) const t v[n] = t[]( -#define CONST_ARRAY_END() ); +const vec2 offsets[8] = vec2[]( + vec2(-1.0, 0.0), vec2( 1.0, 0.0), vec2( 0.0, 1.0), vec2( 0.0, -1.0), + vec2(-1.0, 1.0), vec2( 1.0, 1.0), vec2( 1.0, -1.0), vec2(-1.0, -1.0) +); #else -#define CONST_ARRAY_BEGIN(t, v, n) const t v[n] = { -#define CONST_ARRAY_END() }; +const vec2 offsets[8] = { + vec2(-1.0, 0.0), vec2( 1.0, 0.0), vec2( 0.0, 1.0), vec2( 0.0, -1.0), + vec2(-1.0, 1.0), vec2( 1.0, 1.0), vec2( 1.0, -1.0), vec2(-1.0, -1.0) +}; #endif -CONST_ARRAY_BEGIN(vec2, offsets, 8) - vec2(-1.0, 0.0), - vec2( 1.0, 0.0), - vec2( 0.0, 1.0), - vec2( 0.0, -1.0), - vec2(-1.0, 1.0), - vec2( 1.0, 1.0), - vec2( 1.0, -1.0), - vec2(-1.0, -1.0) -CONST_ARRAY_END() - void main() { // Based on https://shaderbits.com/blog/uv-dilation by Ryan Brucks - vec2 size = textureSize(tex, 0).xy; + vec2 size = vec2(textureSize(tex, 0).xy); vec2 texel_size = vec2(1.0, 1.0) / size; float min_dist = 10000000.0; ivec2 coord = ivec2(tex_coord * size); float mask = texelFetch(texdilate, coord, 0).r; - if (mask > 0) discard; + if (mask > 0.0) discard; frag_color = texelFetch(tex, coord, 0); int i = 0; - while (i < dilate_radius) { + while (i < int(dilate_radius)) { i++; int j = 0; while (j < 8) { - vec2 cur_uv = tex_coord + offsets[j] * texel_size * i; + vec2 cur_uv = tex_coord + offsets[j] * texel_size * vec2(i, i); coord = ivec2(cur_uv * size); float offset_mask = texelFetch(texdilate, coord, 0).r; vec4 offset_col = texelFetch(tex, coord, 0); - if (offset_mask != 0) { + if (offset_mask != 0.0) { float cur_dist = length(tex_coord - cur_uv); if (cur_dist < min_dist) { - vec2 project_uv = cur_uv + offsets[j] * texel_size * i * 0.25; + vec2 project_uv = cur_uv + offsets[j] * texel_size * vec2(i, i) * vec2(0.25, 0.25); vec4 direction = textureLod(tex, project_uv, 0.0); min_dist = cur_dist; - if (direction.x != 0 || direction.y != 0 || direction.z != 0) { + if (direction.x != 0.0 || direction.y != 0.0 || direction.z != 0.0) { vec4 delta = offset_col - direction; - frag_color = offset_col + delta * 4; + frag_color = offset_col + delta * vec4(4.0, 4.0, 4.0, 4.0); } else { frag_color = offset_col; diff --git a/base/shaders/ssao_blur_pass.frag.glsl b/base/shaders/ssao_blur_pass.frag.glsl index 3adfea70b..93b4785b8 100644 --- a/base/shaders/ssao_blur_pass.frag.glsl +++ b/base/shaders/ssao_blur_pass.frag.glsl @@ -10,26 +10,15 @@ in vec2 tex_coord; out float frag_color; #ifdef ESSL -#define CONST_ARRAY_BEGIN(t, v, n) const t v[n] = t[]( -#define CONST_ARRAY_END() ); +const float blur_weights[10] = float[]( + 0.132572, 0.125472, 0.106373, 0.08078, 0.05495, 0.033482, 0.018275, 0.008934, 0.003912, 0.001535 +); #else -#define CONST_ARRAY_BEGIN(t, v, n) const t v[n] = { -#define CONST_ARRAY_END() }; +const float blur_weights[10] = { + 0.132572, 0.125472, 0.106373, 0.08078, 0.05495, 0.033482, 0.018275, 0.008934, 0.003912, 0.001535 +}; #endif -CONST_ARRAY_BEGIN(float, blur_weights, 10) - 0.132572, - 0.125472, - 0.106373, - 0.08078, - 0.05495, - 0.033482, - 0.018275, - 0.008934, - 0.003912, - 0.001535 -CONST_ARRAY_END() - const float discard_threshold = 0.95; void main() {