From 38711d2ccfd29e6706fd671e83544a4c6d870dca Mon Sep 17 00:00:00 2001 From: Manolis Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Sat, 17 Apr 2021 22:33:13 +0300 Subject: [PATCH] Fix HTML5 shader issue The MarchingAntsOutline was failing to compile on the Web platform due to the for loop not having constant expressions inside the shader. "Loop index cannot be initialized with non-constant expression" --- src/Shaders/MarchingAntsOutline.shader | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Shaders/MarchingAntsOutline.shader b/src/Shaders/MarchingAntsOutline.shader index 24970fbd9..c9294b9c4 100644 --- a/src/Shaders/MarchingAntsOutline.shader +++ b/src/Shaders/MarchingAntsOutline.shader @@ -5,24 +5,24 @@ shader_type canvas_item; uniform vec4 first_color : hint_color = vec4(1.0); uniform vec4 second_color : hint_color = vec4(0.0, 0.0, 0.0, 1.0); uniform bool animated = true; -uniform float width : hint_range(0, 2) = 0.2; +uniform float width : hint_range(0, 2) = 0.05; uniform float frequency = 50.0; uniform float stripe_direction : hint_range(0, 1) = 0.5; bool hasContraryNeighbour(vec2 uv, vec2 texture_pixel_size, sampler2D texture) { - for (float i = -ceil(width); i <= ceil(width); i++) { - float x = abs(i) > width ? width * sign(i) : i; - float offset = width; - - for (float j = -ceil(offset); j <= ceil(offset); j++) { - float y = abs(j) > offset ? offset * sign(j) : j; - vec2 xy = uv + texture_pixel_size * vec2(x, y); - - if ((xy != clamp(xy, vec2(0.0), vec2(1.0)) || texture(texture, xy).a == 0.0) == true) { - return true; - } - } + float i = -ceil(width); + float j = ceil(width); + float x1 = abs(i) > width ? width * sign(i) : i; + float x2 = abs(j) > width ? width * sign(j) : j; + float y1 = abs(i) > width ? width * sign(i) : i; + float y2 = abs(j) > width ? width * sign(j) : j; + + vec2 xy1 = uv + texture_pixel_size * vec2(x1, y1); + vec2 xy2 = uv + texture_pixel_size * vec2(x2, y2); + + if (xy1 != clamp(xy1, vec2(0.0), vec2(1.0)) || texture(texture, xy1).a == 0.0 || xy2 != clamp(xy2, vec2(0.0), vec2(1.0)) || texture(texture, xy2).a == 0.0) { + return true; } return false;