From 40be1a9559524894ff2a0bc03fbdd0ced12dd64e Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Wed, 24 Jul 2024 00:48:16 +0300 Subject: [PATCH] Some minor optimizations in BlendLayer.gdshader --- src/Shaders/BlendLayers.gdshader | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Shaders/BlendLayers.gdshader b/src/Shaders/BlendLayers.gdshader index 09bdf875d..0a1d8a3d6 100644 --- a/src/Shaders/BlendLayers.gdshader +++ b/src/Shaders/BlendLayers.gdshader @@ -146,35 +146,37 @@ float border_trim(vec4 color, vec2 uv) { void fragment() { ivec2 metadata_size = textureSize(metadata, 0) - 1; - vec2 first_origin = texture(metadata, vec2(0.0, 2.0 / float(metadata_size.y))).rg; + vec2 metadata_size_float = vec2(metadata_size); + vec2 first_origin = texture(metadata, vec2(0.0, 2.0 / metadata_size_float.y)).rg; if (!origin_x_positive) { first_origin.x = -first_origin.x; } if (!origin_y_positive) { first_origin.y = -first_origin.y; } - float first_opacity = texture(metadata, vec2(0.0, 1.0 / float(metadata_size.y))).r; + float first_opacity = texture(metadata, vec2(0.0, 1.0 / metadata_size_float.y)).r; vec4 result_color = texture(layers, vec3(UV - first_origin, 0.0)); result_color.a = border_trim(result_color, UV - first_origin); result_color.a *= first_opacity; for(int i = 1; i < metadata_size.x + 1; i++) // Loops through every layer { - float blend_mode_float = texture(metadata, vec2(float(i) / float(metadata_size.x), 0.0)).r; + float layer_index = float(i) / metadata_size_float.x; + float blend_mode_float = texture(metadata, vec2(layer_index, 0.0)).r; // Blend modes are being stored as integers divided by 255, so convert them back to // their integer form int current_blend_mode = int(floor(blend_mode_float * 255.0)); - vec2 current_origin = texture(metadata, vec2(float(i) / float(metadata_size.x), 2.0 / float(metadata_size.y))).rg; + vec2 current_origin = texture(metadata, vec2(layer_index, 2.0 / metadata_size_float.y)).rg; if (!origin_x_positive) { current_origin.x = -current_origin.x; } if (!origin_y_positive) { current_origin.y = -current_origin.y; } - float current_opacity = texture(metadata, vec2(float(i) / float(metadata_size.x), 1.0 / float(metadata_size.y))).r; + float current_opacity = texture(metadata, vec2(layer_index, 1.0 / metadata_size_float.y)).r; vec2 uv = UV - current_origin; vec4 layer_color = texture(layers, vec3(uv, float(i))); vec4 prev_layer_color = texture(layers, vec3(uv, float(i - 1))); - float clipping_mask = texture(metadata, vec2(float(i) / float(metadata_size.x), 3.0 / float(metadata_size.y))).r; + float clipping_mask = texture(metadata, vec2(layer_index, 3.0 / metadata_size_float.y)).r; layer_color.a *= prev_layer_color.a * step(0.5, clipping_mask) + 1.0 * step(clipping_mask, 0.5); layer_color.a = border_trim(layer_color, uv); result_color = blend(current_blend_mode, layer_color, result_color, current_opacity);