diff options
Diffstat (limited to 'drivers/gles3/shaders/canvas.glsl')
-rw-r--r-- | drivers/gles3/shaders/canvas.glsl | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/drivers/gles3/shaders/canvas.glsl b/drivers/gles3/shaders/canvas.glsl index 1ac289d5a2..3857aa8841 100644 --- a/drivers/gles3/shaders/canvas.glsl +++ b/drivers/gles3/shaders/canvas.glsl @@ -110,6 +110,9 @@ layout(std140) uniform MaterialUniforms{ //ubo:4 }; #endif + +uniform mediump uint batch_flags; + /* clang-format on */ #include "canvas_uniforms_inc.glsl" @@ -179,13 +182,13 @@ void main() { vec2 uv = uv_attrib; #ifdef USE_INSTANCING - if (bool(read_draw_data_flags & FLAGS_INSTANCING_HAS_COLORS)) { + if (bool(batch_flags & BATCH_FLAGS_INSTANCING_HAS_COLORS)) { vec4 instance_color; instance_color.xy = unpackHalf2x16(uint(instance_color_custom_data.x)); instance_color.zw = unpackHalf2x16(uint(instance_color_custom_data.y)); color *= instance_color; } - if (bool(read_draw_data_flags & FLAGS_INSTANCING_HAS_CUSTOM_DATA)) { + if (bool(batch_flags & BATCH_FLAGS_INSTANCING_HAS_CUSTOM_DATA)) { instance_custom.xy = unpackHalf2x16(instance_color_custom_data.z); instance_custom.zw = unpackHalf2x16(instance_color_custom_data.w); } @@ -218,7 +221,7 @@ void main() { else if (vertex_id == 5) vertex_base = vec2(1.0, 1.0); - vec2 uv = read_draw_data_src_rect.xy + abs(read_draw_data_src_rect.zw) * ((read_draw_data_flags & FLAGS_TRANSPOSE_RECT) != uint(0) ? vertex_base.yx : vertex_base.xy); + vec2 uv = read_draw_data_src_rect.xy + abs(read_draw_data_src_rect.zw) * ((read_draw_data_flags & INSTANCE_FLAGS_TRANSPOSE_RECT) != uint(0) ? vertex_base.yx : vertex_base.xy); vec4 color = read_draw_data_modulation; vec2 vertex = read_draw_data_dst_rect.xy + abs(read_draw_data_dst_rect.zw) * mix(vertex_base, vec2(1.0, 1.0) - vertex_base, lessThan(read_draw_data_src_rect.zw, vec2(0.0, 0.0))); @@ -336,6 +339,8 @@ uniform sampler2D specular_texture; //texunit:-7 uniform sampler2D color_texture; //texunit:0 +uniform mediump uint batch_flags; + layout(location = 0) out vec4 frag_color; /* clang-format off */ @@ -519,7 +524,7 @@ float map_ninepatch_axis(float pixel, float draw_size, float tex_pixel_size, flo } else if (pixel >= draw_size - margin_end) { return (tex_size - (draw_size - pixel)) * tex_pixel_size; } else { - if (!bool(read_draw_data_flags & FLAGS_NINEPACH_DRAW_CENTER)) { + if (!bool(read_draw_data_flags & INSTANCE_FLAGS_NINEPATCH_DRAW_CENTER)) { draw_center--; } @@ -567,8 +572,8 @@ void main() { int draw_center = 2; uv = vec2( - map_ninepatch_axis(pixel_size_interp.x, abs(read_draw_data_dst_rect_z), read_draw_data_color_texture_pixel_size.x, read_draw_data_ninepatch_margins.x, read_draw_data_ninepatch_margins.z, int(read_draw_data_flags >> FLAGS_NINEPATCH_H_MODE_SHIFT) & 0x3, draw_center), - map_ninepatch_axis(pixel_size_interp.y, abs(read_draw_data_dst_rect_w), read_draw_data_color_texture_pixel_size.y, read_draw_data_ninepatch_margins.y, read_draw_data_ninepatch_margins.w, int(read_draw_data_flags >> FLAGS_NINEPATCH_V_MODE_SHIFT) & 0x3, draw_center)); + map_ninepatch_axis(pixel_size_interp.x, abs(read_draw_data_dst_rect_z), read_draw_data_color_texture_pixel_size.x, read_draw_data_ninepatch_margins.x, read_draw_data_ninepatch_margins.z, int(read_draw_data_flags >> INSTANCE_FLAGS_NINEPATCH_H_MODE_SHIFT) & 0x3, draw_center), + map_ninepatch_axis(pixel_size_interp.y, abs(read_draw_data_dst_rect_w), read_draw_data_color_texture_pixel_size.y, read_draw_data_ninepatch_margins.y, read_draw_data_ninepatch_margins.w, int(read_draw_data_flags >> INSTANCE_FLAGS_NINEPATCH_V_MODE_SHIFT) & 0x3, draw_center)); if (draw_center == 0) { color.a = 0.0; @@ -577,7 +582,7 @@ void main() { uv = uv * read_draw_data_src_rect.zw + read_draw_data_src_rect.xy; //apply region if needed #endif - if (bool(read_draw_data_flags & FLAGS_CLIP_RECT_UV)) { + if (bool(read_draw_data_flags & INSTANCE_FLAGS_CLIP_RECT_UV)) { vec2 half_texpixel = read_draw_data_color_texture_pixel_size * 0.5; uv = clamp(uv, read_draw_data_src_rect.xy + half_texpixel, read_draw_data_src_rect.xy + abs(read_draw_data_src_rect.zw) - half_texpixel); } @@ -585,7 +590,7 @@ void main() { #endif #ifndef USE_PRIMITIVE - if (bool(read_draw_data_flags & FLAGS_USE_MSDF)) { + if (bool(read_draw_data_flags & INSTANCE_FLAGS_USE_MSDF)) { float px_range = read_draw_data_ninepatch_margins.x; float outline_thickness = read_draw_data_ninepatch_margins.y; @@ -603,7 +608,7 @@ void main() { float a = clamp(d * px_size + 0.5, 0.0, 1.0); color.a = a * color.a; } - } else if (bool(read_draw_data_flags & FLAGS_USE_LCD)) { + } else if (bool(read_draw_data_flags & INSTANCE_FLAGS_USE_LCD)) { vec4 lcd_sample = texture(color_texture, uv); if (lcd_sample.a == 1.0) { color.rgb = lcd_sample.rgb * color.a; @@ -617,7 +622,7 @@ void main() { color *= texture(color_texture, uv); } - uint light_count = (read_draw_data_flags >> uint(FLAGS_LIGHT_COUNT_SHIFT)) & uint(0xF); //max 16 lights + uint light_count = read_draw_data_flags & uint(0xF); // Max 16 lights. bool using_light = light_count > 0u || directional_light_count > 0u; vec3 normal; @@ -628,17 +633,16 @@ void main() { bool normal_used = false; #endif - if (normal_used || (using_light && bool(read_draw_data_flags & FLAGS_DEFAULT_NORMAL_MAP_USED))) { + if (normal_used || (using_light && bool(batch_flags & BATCH_FLAGS_DEFAULT_NORMAL_MAP_USED))) { normal.xy = texture(normal_texture, uv).xy * vec2(2.0, -2.0) - vec2(1.0, -1.0); - if (bool(read_draw_data_flags & FLAGS_TRANSPOSE_RECT)) { + +#if !defined(USE_ATTRIBUTES) && !defined(USE_PRIMITIVE) + if (bool(read_draw_data_flags & INSTANCE_FLAGS_TRANSPOSE_RECT)) { normal.xy = normal.yx; } - if (bool(read_draw_data_flags & FLAGS_FLIP_H)) { - normal.x = -normal.x; - } - if (bool(read_draw_data_flags & FLAGS_FLIP_V)) { - normal.y = -normal.y; - } + normal.xy *= sign(read_draw_data_src_rect.zw); +#endif + normal.z = sqrt(max(0.0, 1.0 - dot(normal.xy, normal.xy))); normal_used = true; } else { @@ -654,7 +658,7 @@ void main() { bool specular_shininess_used = false; #endif - if (specular_shininess_used || (using_light && normal_used && bool(read_draw_data_flags & FLAGS_DEFAULT_SPECULAR_MAP_USED))) { + if (specular_shininess_used || (using_light && normal_used && bool(batch_flags & BATCH_FLAGS_DEFAULT_SPECULAR_MAP_USED))) { specular_shininess = texture(specular_texture, uv); specular_shininess *= godot_unpackUnorm4x8(read_draw_data_specular_shininess); specular_shininess_used = true; @@ -727,7 +731,7 @@ void main() { } #endif - if (bool(light_array[light_base].flags & LIGHT_FLAGS_HAS_SHADOW)) { + if (bool(light_array[light_base].flags & LIGHT_FLAGS_HAS_SHADOW) && bool(read_draw_data_flags & uint(INSTANCE_FLAGS_SHADOW_MASKED << i))) { vec2 shadow_pos = (vec4(shadow_vertex, 0.0, 1.0) * mat4(light_array[light_base].shadow_matrix[0], light_array[light_base].shadow_matrix[1], vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0))).xy; //multiply inverse given its transposed. Optimizer removes useless operations. vec4 shadow_uv = vec4(shadow_pos.x, light_array[light_base].shadow_y_ofs, shadow_pos.y * light_array[light_base].shadow_zfar_inv, 1.0); @@ -802,7 +806,7 @@ void main() { } #endif - if (bool(light_array[light_base].flags & LIGHT_FLAGS_HAS_SHADOW)) { + if (bool(light_array[light_base].flags & LIGHT_FLAGS_HAS_SHADOW) && bool(read_draw_data_flags & uint(INSTANCE_FLAGS_SHADOW_MASKED << i))) { vec2 shadow_pos = (vec4(shadow_vertex, 0.0, 1.0) * mat4(light_array[light_base].shadow_matrix[0], light_array[light_base].shadow_matrix[1], vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0))).xy; //multiply inverse given its transposed. Optimizer removes useless operations. vec2 pos_norm = normalize(shadow_pos); |