mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-30 23:19:49 +00:00
Some minor optimizations in BlendLayer.gdshader
This commit is contained in:
parent
cec0073a84
commit
40be1a9559
|
@ -146,35 +146,37 @@ float border_trim(vec4 color, vec2 uv) {
|
||||||
|
|
||||||
void fragment() {
|
void fragment() {
|
||||||
ivec2 metadata_size = textureSize(metadata, 0) - 1;
|
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) {
|
if (!origin_x_positive) {
|
||||||
first_origin.x = -first_origin.x;
|
first_origin.x = -first_origin.x;
|
||||||
}
|
}
|
||||||
if (!origin_y_positive) {
|
if (!origin_y_positive) {
|
||||||
first_origin.y = -first_origin.y;
|
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));
|
vec4 result_color = texture(layers, vec3(UV - first_origin, 0.0));
|
||||||
result_color.a = border_trim(result_color, UV - first_origin);
|
result_color.a = border_trim(result_color, UV - first_origin);
|
||||||
result_color.a *= first_opacity;
|
result_color.a *= first_opacity;
|
||||||
for(int i = 1; i < metadata_size.x + 1; i++) // Loops through every layer
|
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
|
// Blend modes are being stored as integers divided by 255, so convert them back to
|
||||||
// their integer form
|
// their integer form
|
||||||
int current_blend_mode = int(floor(blend_mode_float * 255.0));
|
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) {
|
if (!origin_x_positive) {
|
||||||
current_origin.x = -current_origin.x;
|
current_origin.x = -current_origin.x;
|
||||||
}
|
}
|
||||||
if (!origin_y_positive) {
|
if (!origin_y_positive) {
|
||||||
current_origin.y = -current_origin.y;
|
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;
|
vec2 uv = UV - current_origin;
|
||||||
vec4 layer_color = texture(layers, vec3(uv, float(i)));
|
vec4 layer_color = texture(layers, vec3(uv, float(i)));
|
||||||
vec4 prev_layer_color = texture(layers, vec3(uv, float(i - 1)));
|
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 *= prev_layer_color.a * step(0.5, clipping_mask) + 1.0 * step(clipping_mask, 0.5);
|
||||||
layer_color.a = border_trim(layer_color, uv);
|
layer_color.a = border_trim(layer_color, uv);
|
||||||
result_color = blend(current_blend_mode, layer_color, result_color, current_opacity);
|
result_color = blend(current_blend_mode, layer_color, result_color, current_opacity);
|
||||||
|
|
Loading…
Reference in a new issue