summaryrefslogtreecommitdiff
path: root/drivers/gles3/shaders
diff options
context:
space:
mode:
authorclayjohn <claynjohn@gmail.com>2021-11-16 07:25:42 -0800
committerclayjohn <claynjohn@gmail.com>2022-01-11 22:26:18 -0800
commit99064d57db563f85f0585aac3fa056b980b63cfe (patch)
treee0e4aa8e76668cb8399f7c8452a8bad443396c63 /drivers/gles3/shaders
parent98ac002c3430b1ff50052b19d16fe6fa8fecf0c3 (diff)
New OpenGL batching canvas renderer
Diffstat (limited to 'drivers/gles3/shaders')
-rw-r--r--drivers/gles3/shaders/SCsub12
-rw-r--r--drivers/gles3/shaders/canvas.glsl273
-rw-r--r--drivers/gles3/shaders/canvas_old.glsl665
-rw-r--r--drivers/gles3/shaders/canvas_shadow.glsl2
-rw-r--r--drivers/gles3/shaders/canvas_uniforms_inc.glsl73
-rw-r--r--drivers/gles3/shaders/copy.glsl41
-rw-r--r--drivers/gles3/shaders/cube_to_dp.glsl4
-rw-r--r--drivers/gles3/shaders/cubemap_filter.glsl4
-rw-r--r--drivers/gles3/shaders/effect_blur.glsl4
-rw-r--r--drivers/gles3/shaders/lens_distorted.glsl2
-rw-r--r--drivers/gles3/shaders/scene.glsl32
-rw-r--r--drivers/gles3/shaders/stdlib_inc.glsl58
-rw-r--r--drivers/gles3/shaders/tonemap.glsl4
13 files changed, 287 insertions, 887 deletions
diff --git a/drivers/gles3/shaders/SCsub b/drivers/gles3/shaders/SCsub
index 86542c2de5..2f56b77bdc 100644
--- a/drivers/gles3/shaders/SCsub
+++ b/drivers/gles3/shaders/SCsub
@@ -4,14 +4,4 @@ Import("env")
if "GLES3_GLSL" in env["BUILDERS"]:
env.GLES3_GLSL("canvas.glsl")
-
-if "GLES3_OLD_GLSL" in env["BUILDERS"]:
- env.GLES3_OLD_GLSL("copy.glsl")
- env.GLES3_OLD_GLSL("canvas_old.glsl")
- env.GLES3_OLD_GLSL("canvas_shadow.glsl")
- env.GLES3_OLD_GLSL("scene.glsl")
- env.GLES3_OLD_GLSL("cubemap_filter.glsl")
- env.GLES3_OLD_GLSL("cube_to_dp.glsl")
- env.GLES3_OLD_GLSL("effect_blur.glsl")
- env.GLES3_OLD_GLSL("tonemap.glsl")
- env.GLES3_OLD_GLSL("lens_distorted.glsl")
+ env.GLES3_GLSL("copy.glsl")
diff --git a/drivers/gles3/shaders/canvas.glsl b/drivers/gles3/shaders/canvas.glsl
index b64cbf01b9..a18c451858 100644
--- a/drivers/gles3/shaders/canvas.glsl
+++ b/drivers/gles3/shaders/canvas.glsl
@@ -1,22 +1,19 @@
+/* clang-format off */
#[modes]
mode_quad =
- mode_ninepatch = #define USE_NINEPATCH
- mode_primitive = #define USE_PRIMITIVE
- mode_attributes = #define USE_ATTRIBUTES
+mode_ninepatch = #define USE_NINEPATCH
+mode_primitive = #define USE_PRIMITIVE
+mode_attributes = #define USE_ATTRIBUTES
#[specializations]
- DISABLE_LIGHTING = false
+DISABLE_LIGHTING = false
#[vertex]
-#version 450
-
-#VERSION_DEFINES
-
#ifdef USE_ATTRIBUTES
- layout(location = 0) in vec2 vertex_attrib;
+layout(location = 0) in vec2 vertex_attrib;
layout(location = 3) in vec4 color_attrib;
layout(location = 4) in vec2 uv_attrib;
@@ -24,14 +21,16 @@ layout(location = 10) in uvec4 bone_attrib;
layout(location = 11) in vec4 weight_attrib;
#endif
-
+/* clang-format on */
#include "canvas_uniforms_inc.glsl"
+#include "stdlib_inc.glsl"
uniform sampler2D transforms_texture; //texunit:-1
out vec2 uv_interp;
out vec4 color_interp;
out vec2 vertex_interp;
+flat out int draw_data_instance;
#ifdef USE_NINEPATCH
@@ -52,6 +51,7 @@ layout(std140) uniform MaterialUniforms{
void main() {
vec4 instance_custom = vec4(0.0);
+ draw_data_instance = gl_InstanceID;
#ifdef USE_PRIMITIVE
//weird bug,
@@ -60,18 +60,18 @@ void main() {
vec2 uv;
vec4 color;
- if (gl_VertexIndex == 0) {
- vertex = draw_data.points[0];
- uv = draw_data.uvs[0];
- color = vec4(unpackHalf2x16(draw_data.colors[0]), unpackHalf2x16(draw_data.colors[1]));
- } else if (gl_VertexIndex == 1) {
- vertex = draw_data.points[1];
- uv = draw_data.uvs[1];
- color = vec4(unpackHalf2x16(draw_data.colors[2]), unpackHalf2x16(draw_data.colors[3]));
+ if (gl_VertexID == 0) {
+ vertex = draw_data[draw_data_instance].point_a;
+ uv = draw_data[draw_data_instance].uv_a;
+ color = vec4(unpackHalf2x16(draw_data[draw_data_instance].color_a_rg), unpackHalf2x16(draw_data[draw_data_instance].color_a_ba));
+ } else if (gl_VertexID == 1) {
+ vertex = draw_data[draw_data_instance].point_b;
+ uv = draw_data[draw_data_instance].uv_b;
+ color = vec4(unpackHalf2x16(draw_data[draw_data_instance].color_b_rg), unpackHalf2x16(draw_data[draw_data_instance].color_b_ba));
} else {
- vertex = draw_data.points[2];
- uv = draw_data.uvs[2];
- color = vec4(unpackHalf2x16(draw_data.colors[4]), unpackHalf2x16(draw_data.colors[5]));
+ vertex = draw_data[draw_data_instance].point_c;
+ uv = draw_data[draw_data_instance].uv_c;
+ color = vec4(unpackHalf2x16(draw_data[draw_data_instance].color_c_rg), unpackHalf2x16(draw_data[draw_data_instance].color_c_ba));
}
uvec4 bones = uvec4(0, 0, 0, 0);
vec4 bone_weights = vec4(0.0);
@@ -79,7 +79,7 @@ void main() {
#elif defined(USE_ATTRIBUTES)
vec2 vertex = vertex_attrib;
- vec4 color = color_attrib * draw_data.modulation;
+ vec4 color = color_attrib * draw_data[draw_data_instance].modulation;
vec2 uv = uv_attrib;
uvec4 bones = bone_attrib;
@@ -87,24 +87,22 @@ void main() {
#else
vec2 vertex_base_arr[4] = vec2[](vec2(0.0, 0.0), vec2(0.0, 1.0), vec2(1.0, 1.0), vec2(1.0, 0.0));
- vec2 vertex_base = vertex_base_arr[gl_VertexIndex];
+ vec2 vertex_base = vertex_base_arr[gl_VertexID];
- vec2 uv = draw_data.src_rect.xy + abs(draw_data.src_rect.zw) * ((draw_data.flags & FLAGS_TRANSPOSE_RECT) != 0 ? vertex_base.yx : vertex_base.xy);
- vec4 color = draw_data.modulation;
- vec2 vertex = draw_data.dst_rect.xy + abs(draw_data.dst_rect.zw) * mix(vertex_base, vec2(1.0, 1.0) - vertex_base, lessThan(draw_data.src_rect.zw, vec2(0.0, 0.0)));
+ vec2 uv = draw_data[draw_data_instance].src_rect.xy + abs(draw_data[draw_data_instance].src_rect.zw) * ((draw_data[draw_data_instance].flags & FLAGS_TRANSPOSE_RECT) != uint(0) ? vertex_base.yx : vertex_base.xy);
+ vec4 color = draw_data[draw_data_instance].modulation;
+ vec2 vertex = draw_data[draw_data_instance].dst_rect.xy + abs(draw_data[draw_data_instance].dst_rect.zw) * mix(vertex_base, vec2(1.0, 1.0) - vertex_base, lessThan(draw_data[draw_data_instance].src_rect.zw, vec2(0.0, 0.0)));
uvec4 bones = uvec4(0, 0, 0, 0);
#endif
- mat4 world_matrix = mat4(vec4(draw_data.world_x, 0.0, 0.0), vec4(draw_data.world_y, 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(draw_data.world_ofs, 0.0, 1.0));
-
-#define FLAGS_INSTANCING_MASK 0x7F
-#define FLAGS_INSTANCING_HAS_COLORS (1 << 7)
-#define FLAGS_INSTANCING_HAS_CUSTOM_DATA (1 << 8)
+ mat4 world_matrix = mat4(vec4(draw_data[draw_data_instance].world_x, 0.0, 0.0), vec4(draw_data[draw_data_instance].world_y, 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(draw_data[draw_data_instance].world_ofs, 0.0, 1.0));
- uint instancing = draw_data.flags & FLAGS_INSTANCING_MASK;
+ // MultiMeshes don't batch, so always read from draw_data[0]
+ uint instancing = draw_data[0].flags & FLAGS_INSTANCING_MASK;
#ifdef USE_ATTRIBUTES
+/*
if (instancing > 1) {
// trails
@@ -112,7 +110,7 @@ void main() {
uint trail_size = instancing;
- uint offset = trail_size * stride * gl_InstanceIndex;
+ uint offset = trail_size * stride * gl_InstanceID;
vec4 pcolor;
vec2 new_vertex;
@@ -141,31 +139,32 @@ void main() {
vertex = new_vertex;
color *= pcolor;
- } else
+ } else*/
#endif // USE_ATTRIBUTES
+/*
{
if (instancing == 1) {
uint stride = 2;
{
- if (bool(draw_data.flags & FLAGS_INSTANCING_HAS_COLORS)) {
+ if (bool(draw_data[0].flags & FLAGS_INSTANCING_HAS_COLORS)) {
stride += 1;
}
- if (bool(draw_data.flags & FLAGS_INSTANCING_HAS_CUSTOM_DATA)) {
+ if (bool(draw_data[0].flags & FLAGS_INSTANCING_HAS_CUSTOM_DATA)) {
stride += 1;
}
}
- uint offset = stride * gl_InstanceIndex;
+ uint offset = stride * gl_InstanceID;
mat4 matrix = mat4(transforms.data[offset + 0], transforms.data[offset + 1], vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0));
offset += 2;
- if (bool(draw_data.flags & FLAGS_INSTANCING_HAS_COLORS)) {
+ if (bool(draw_data[0].flags & FLAGS_INSTANCING_HAS_COLORS)) {
color *= transforms.data[offset];
offset += 1;
}
- if (bool(draw_data.flags & FLAGS_INSTANCING_HAS_CUSTOM_DATA)) {
+ if (bool(draw_data[0].flags & FLAGS_INSTANCING_HAS_CUSTOM_DATA)) {
instance_custom = transforms.data[offset];
}
@@ -173,11 +172,11 @@ void main() {
world_matrix = world_matrix * matrix;
}
}
-
+*/
#if !defined(USE_ATTRIBUTES) && !defined(USE_PRIMITIVE)
- if (bool(draw_data.flags & FLAGS_USING_PARTICLES)) {
+ if (bool(draw_data[draw_data_instance].flags & FLAGS_USING_PARTICLES)) {
//scale by texture size
- vertex /= draw_data.color_texture_pixel_size;
+ vertex /= draw_data[draw_data_instance].color_texture_pixel_size;
}
#endif
@@ -189,7 +188,7 @@ void main() {
}
#ifdef USE_NINEPATCH
- pixel_size_interp = abs(draw_data.dst_rect.zw) * vertex_base;
+ pixel_size_interp = abs(draw_data[draw_data_instance].dst_rect.zw) * vertex_base;
#endif
#if !defined(SKIP_TRANSFORM_USED)
@@ -198,7 +197,7 @@ void main() {
color_interp = color;
- if (canvas_data.use_pixel_snap) {
+ if (use_pixel_snap) {
vertex = floor(vertex + 0.5);
// precision issue on some hardware creates artifacts within texture
// offset uv by a small amount to avoid
@@ -207,7 +206,7 @@ void main() {
#ifdef USE_ATTRIBUTES
#if 0
- if (bool(draw_data.flags & FLAGS_USE_SKELETON) && bone_weights != vec4(0.0)) { //must be a valid bone
+ if (bool(draw_data[draw_data_instance].flags & FLAGS_USE_SKELETON) && bone_weights != vec4(0.0)) { //must be a valid bone
//skeleton transform
ivec4 bone_indicesi = ivec4(bone_indices);
@@ -247,12 +246,12 @@ void main() {
#endif
#endif
- vertex = (canvas_data.canvas_transform * vec4(vertex, 0.0, 1.0)).xy;
+ vertex = (canvas_transform * vec4(vertex, 0.0, 1.0)).xy;
vertex_interp = vertex;
uv_interp = uv;
- gl_Position = canvas_data.screen_transform * vec4(vertex, 0.0, 1.0);
+ gl_Position = screen_transform * vec4(vertex, 0.0, 1.0);
#ifdef USE_POINT_SIZE
gl_PointSize = point_size;
@@ -261,11 +260,8 @@ void main() {
#[fragment]
-#version 450
-
-#VERSION_DEFINES
-
#include "canvas_uniforms_inc.glsl"
+#include "stdlib_inc.glsl"
uniform sampler2D atlas_texture; //texunit:-2
uniform sampler2D shadow_atlas_texture; //texunit:-3
@@ -279,6 +275,7 @@ uniform sampler2D color_texture; //texunit:0
in vec2 uv_interp;
in vec4 color_interp;
in vec2 vertex_interp;
+flat in int draw_data_instance;
#ifdef USE_NINEPATCH
@@ -298,27 +295,27 @@ uniform MaterialUniforms{
#endif
vec2 screen_uv_to_sdf(vec2 p_uv) {
- return canvas_data.screen_to_sdf * p_uv;
+ return screen_to_sdf * p_uv;
}
float texture_sdf(vec2 p_sdf) {
- vec2 uv = p_sdf * canvas_data.sdf_to_tex.xy + canvas_data.sdf_to_tex.zw;
- float d = texture(sampler2D(sdf_texture, material_samplers[SAMPLER_LINEAR_CLAMP]), uv).r;
+ vec2 uv = p_sdf * sdf_to_tex.xy + sdf_to_tex.zw;
+ float d = texture(sdf_texture, uv).r;
d *= SDF_MAX_LENGTH;
- return d * canvas_data.tex_to_sdf;
+ return d * tex_to_sdf;
}
vec2 texture_sdf_normal(vec2 p_sdf) {
- vec2 uv = p_sdf * canvas_data.sdf_to_tex.xy + canvas_data.sdf_to_tex.zw;
+ vec2 uv = p_sdf * sdf_to_tex.xy + sdf_to_tex.zw;
const float EPSILON = 0.001;
return normalize(vec2(
- texture(sampler2D(sdf_texture, material_samplers[SAMPLER_LINEAR_CLAMP]), uv + vec2(EPSILON, 0.0)).r - texture(sampler2D(sdf_texture, material_samplers[SAMPLER_LINEAR_CLAMP]), uv - vec2(EPSILON, 0.0)).r,
- texture(sampler2D(sdf_texture, material_samplers[SAMPLER_LINEAR_CLAMP]), uv + vec2(0.0, EPSILON)).r - texture(sampler2D(sdf_texture, material_samplers[SAMPLER_LINEAR_CLAMP]), uv - vec2(0.0, EPSILON)).r));
+ texture(sdf_texture, uv + vec2(EPSILON, 0.0)).r - texture(sdf_texture, uv - vec2(EPSILON, 0.0)).r,
+ texture(sdf_texture, uv + vec2(0.0, EPSILON)).r - texture(sdf_texture, uv - vec2(0.0, EPSILON)).r));
}
vec2 sdf_to_screen_uv(vec2 p_sdf) {
- return p_sdf * canvas_data.sdf_to_screen;
+ return p_sdf * sdf_to_screen;
}
#GLOBALS
@@ -355,7 +352,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(draw_data.flags & FLAGS_NINEPACH_DRAW_CENTER)) {
+ if (!bool(draw_data[draw_data_instance].flags & FLAGS_NINEPACH_DRAW_CENTER)) {
draw_center--;
}
@@ -419,39 +416,39 @@ vec4 light_shadow_compute(uint light_base, vec4 light_color, vec4 shadow_uv
#endif
) {
float shadow;
- uint shadow_mode = light_array.data[light_base].flags & LIGHT_FLAGS_FILTER_MASK;
+ uint shadow_mode = light_data[light_base].flags & LIGHT_FLAGS_FILTER_MASK;
if (shadow_mode == LIGHT_FLAGS_SHADOW_NEAREST) {
- shadow = textureProjLod(sampler2DShadow(shadow_atlas_texture, shadow_sampler), shadow_uv, 0.0).x;
+ shadow = textureProjLod(shadow_atlas_texture, shadow_uv, 0.0).x;
} else if (shadow_mode == LIGHT_FLAGS_SHADOW_PCF5) {
- vec4 shadow_pixel_size = vec4(light_array.data[light_base].shadow_pixel_size, 0.0, 0.0, 0.0);
+ vec4 shadow_pixel_size = vec4(light_data[light_base].shadow_pixel_size, 0.0, 0.0, 0.0);
shadow = 0.0;
- shadow += textureProjLod(sampler2DShadow(shadow_atlas_texture, shadow_sampler), shadow_uv - shadow_pixel_size * 2.0, 0.0).x;
- shadow += textureProjLod(sampler2DShadow(shadow_atlas_texture, shadow_sampler), shadow_uv - shadow_pixel_size, 0.0).x;
- shadow += textureProjLod(sampler2DShadow(shadow_atlas_texture, shadow_sampler), shadow_uv, 0.0).x;
- shadow += textureProjLod(sampler2DShadow(shadow_atlas_texture, shadow_sampler), shadow_uv + shadow_pixel_size, 0.0).x;
- shadow += textureProjLod(sampler2DShadow(shadow_atlas_texture, shadow_sampler), shadow_uv + shadow_pixel_size * 2.0, 0.0).x;
+ shadow += textureProjLod(shadow_atlas_texture, shadow_uv - shadow_pixel_size * 2.0, 0.0).x;
+ shadow += textureProjLod(shadow_atlas_texture, shadow_uv - shadow_pixel_size, 0.0).x;
+ shadow += textureProjLod(shadow_atlas_texture, shadow_uv, 0.0).x;
+ shadow += textureProjLod(shadow_atlas_texture, shadow_uv + shadow_pixel_size, 0.0).x;
+ shadow += textureProjLod(shadow_atlas_texture, shadow_uv + shadow_pixel_size * 2.0, 0.0).x;
shadow /= 5.0;
} else { //PCF13
- vec4 shadow_pixel_size = vec4(light_array.data[light_base].shadow_pixel_size, 0.0, 0.0, 0.0);
+ vec4 shadow_pixel_size = vec4(light_data[light_base].shadow_pixel_size, 0.0, 0.0, 0.0);
shadow = 0.0;
- shadow += textureProjLod(sampler2DShadow(shadow_atlas_texture, shadow_sampler), shadow_uv - shadow_pixel_size * 6.0, 0.0).x;
- shadow += textureProjLod(sampler2DShadow(shadow_atlas_texture, shadow_sampler), shadow_uv - shadow_pixel_size * 5.0, 0.0).x;
- shadow += textureProjLod(sampler2DShadow(shadow_atlas_texture, shadow_sampler), shadow_uv - shadow_pixel_size * 4.0, 0.0).x;
- shadow += textureProjLod(sampler2DShadow(shadow_atlas_texture, shadow_sampler), shadow_uv - shadow_pixel_size * 3.0, 0.0).x;
- shadow += textureProjLod(sampler2DShadow(shadow_atlas_texture, shadow_sampler), shadow_uv - shadow_pixel_size * 2.0, 0.0).x;
- shadow += textureProjLod(sampler2DShadow(shadow_atlas_texture, shadow_sampler), shadow_uv - shadow_pixel_size, 0.0).x;
- shadow += textureProjLod(sampler2DShadow(shadow_atlas_texture, shadow_sampler), shadow_uv, 0.0).x;
- shadow += textureProjLod(sampler2DShadow(shadow_atlas_texture, shadow_sampler), shadow_uv + shadow_pixel_size, 0.0).x;
- shadow += textureProjLod(sampler2DShadow(shadow_atlas_texture, shadow_sampler), shadow_uv + shadow_pixel_size * 2.0, 0.0).x;
- shadow += textureProjLod(sampler2DShadow(shadow_atlas_texture, shadow_sampler), shadow_uv + shadow_pixel_size * 3.0, 0.0).x;
- shadow += textureProjLod(sampler2DShadow(shadow_atlas_texture, shadow_sampler), shadow_uv + shadow_pixel_size * 4.0, 0.0).x;
- shadow += textureProjLod(sampler2DShadow(shadow_atlas_texture, shadow_sampler), shadow_uv + shadow_pixel_size * 5.0, 0.0).x;
- shadow += textureProjLod(sampler2DShadow(shadow_atlas_texture, shadow_sampler), shadow_uv + shadow_pixel_size * 6.0, 0.0).x;
+ shadow += textureProjLod(shadow_atlas_texture, shadow_uv - shadow_pixel_size * 6.0, 0.0).x;
+ shadow += textureProjLod(shadow_atlas_texture, shadow_uv - shadow_pixel_size * 5.0, 0.0).x;
+ shadow += textureProjLod(shadow_atlas_texture, shadow_uv - shadow_pixel_size * 4.0, 0.0).x;
+ shadow += textureProjLod(shadow_atlas_texture, shadow_uv - shadow_pixel_size * 3.0, 0.0).x;
+ shadow += textureProjLod(shadow_atlas_texture, shadow_uv - shadow_pixel_size * 2.0, 0.0).x;
+ shadow += textureProjLod(shadow_atlas_texture, shadow_uv - shadow_pixel_size, 0.0).x;
+ shadow += textureProjLod(shadow_atlas_texture, shadow_uv, 0.0).x;
+ shadow += textureProjLod(shadow_atlas_texture, shadow_uv + shadow_pixel_size, 0.0).x;
+ shadow += textureProjLod(shadow_atlas_texture, shadow_uv + shadow_pixel_size * 2.0, 0.0).x;
+ shadow += textureProjLod(shadow_atlas_texture, shadow_uv + shadow_pixel_size * 3.0, 0.0).x;
+ shadow += textureProjLod(shadow_atlas_texture, shadow_uv + shadow_pixel_size * 4.0, 0.0).x;
+ shadow += textureProjLod(shadow_atlas_texture, shadow_uv + shadow_pixel_size * 5.0, 0.0).x;
+ shadow += textureProjLod(shadow_atlas_texture, shadow_uv + shadow_pixel_size * 6.0, 0.0).x;
shadow /= 13.0;
}
- vec4 shadow_color = unpackUnorm4x8(light_array.data[light_base].shadow_color);
+ vec4 shadow_color = unpackUnorm4x8(light_data[light_base].shadow_color);
#ifdef LIGHT_CODE_USED
shadow_color.rgb *= shadow_modulate;
#endif
@@ -462,7 +459,7 @@ vec4 light_shadow_compute(uint light_base, vec4 light_color, vec4 shadow_uv
}
void light_blend_compute(uint light_base, vec4 light_color, inout vec3 color) {
- uint blend_mode = light_array.data[light_base].flags & LIGHT_FLAGS_BLEND_MASK;
+ uint blend_mode = light_data[light_base].flags & LIGHT_FLAGS_BLEND_MASK;
switch (blend_mode) {
case LIGHT_FLAGS_BLEND_MODE_ADD: {
@@ -496,31 +493,31 @@ void main() {
int draw_center = 2;
uv = vec2(
- map_ninepatch_axis(pixel_size_interp.x, abs(draw_data.dst_rect.z), draw_data.color_texture_pixel_size.x, draw_data.ninepatch_margins.x, draw_data.ninepatch_margins.z, int(draw_data.flags >> FLAGS_NINEPATCH_H_MODE_SHIFT) & 0x3, draw_center),
- map_ninepatch_axis(pixel_size_interp.y, abs(draw_data.dst_rect.w), draw_data.color_texture_pixel_size.y, draw_data.ninepatch_margins.y, draw_data.ninepatch_margins.w, int(draw_data.flags >> FLAGS_NINEPATCH_V_MODE_SHIFT) & 0x3, draw_center));
+ map_ninepatch_axis(pixel_size_interp.x, abs(draw_data[draw_data_instance].dst_rect.z), draw_data[draw_data_instance].color_texture_pixel_size.x, draw_data[draw_data_instance].ninepatch_margins.x, draw_data[draw_data_instance].ninepatch_margins.z, int(draw_data[draw_data_instance].flags >> FLAGS_NINEPATCH_H_MODE_SHIFT) & 0x3, draw_center),
+ map_ninepatch_axis(pixel_size_interp.y, abs(draw_data[draw_data_instance].dst_rect.w), draw_data[draw_data_instance].color_texture_pixel_size.y, draw_data[draw_data_instance].ninepatch_margins.y, draw_data[draw_data_instance].ninepatch_margins.w, int(draw_data[draw_data_instance].flags >> FLAGS_NINEPATCH_V_MODE_SHIFT) & 0x3, draw_center));
if (draw_center == 0) {
color.a = 0.0;
}
- uv = uv * draw_data.src_rect.zw + draw_data.src_rect.xy; //apply region if needed
+ uv = uv * draw_data[draw_data_instance].src_rect.zw + draw_data[draw_data_instance].src_rect.xy; //apply region if needed
#endif
- if (bool(draw_data.flags & FLAGS_CLIP_RECT_UV)) {
- uv = clamp(uv, draw_data.src_rect.xy, draw_data.src_rect.xy + abs(draw_data.src_rect.zw));
+ if (bool(draw_data[draw_data_instance].flags & FLAGS_CLIP_RECT_UV)) {
+ uv = clamp(uv, draw_data[draw_data_instance].src_rect.xy, draw_data[draw_data_instance].src_rect.xy + abs(draw_data[draw_data_instance].src_rect.zw));
}
#endif
#ifndef USE_PRIMITIVE
- if (bool(draw_data.flags & FLAGS_USE_MSDF)) {
- float px_range = draw_data.ninepatch_margins.x;
- float outline_thickness = draw_data.ninepatch_margins.y;
- //float reserved1 = draw_data.ninepatch_margins.z;
- //float reserved2 = draw_data.ninepatch_margins.w;
-
- vec4 msdf_sample = texture(sampler2D(color_texture, texture_sampler), uv);
- vec2 msdf_size = vec2(textureSize(sampler2D(color_texture, texture_sampler), 0));
+ if (bool(draw_data[draw_data_instance].flags & FLAGS_USE_MSDF)) {
+ float px_range = draw_data[draw_data_instance].ninepatch_margins.x;
+ float outline_thickness = draw_data[draw_data_instance].ninepatch_margins.y;
+ //float reserved1 = draw_data[draw_data_instance].ninepatch_margins.z;
+ //float reserved2 = draw_data[draw_data_instance].ninepatch_margins.w;
+
+ vec4 msdf_sample = texture(color_texture, uv);
+ vec2 msdf_size = vec2(textureSize(color_texture, 0));
vec2 dest_size = vec2(1.0) / fwidth(uv);
float px_size = max(0.5 * dot((vec2(px_range) / msdf_size), dest_size), 1.0);
float d = msdf_median(msdf_sample.r, msdf_sample.g, msdf_sample.b, msdf_sample.a) - 0.5;
@@ -538,11 +535,11 @@ void main() {
#else
{
#endif
- color *= texture(sampler2D(color_texture, texture_sampler), uv);
+ color *= texture(color_texture, uv);
}
- uint light_count = (draw_data.flags >> FLAGS_LIGHT_COUNT_SHIFT) & 0xF; //max 16 lights
- bool using_light = light_count > 0 || canvas_data.directional_light_count > 0;
+ uint light_count = (draw_data[draw_data_instance].flags >> FLAGS_LIGHT_COUNT_SHIFT) & uint(0xF); //max 16 lights
+ bool using_light = light_count > uint(0) || directional_light_count > uint(0);
vec3 normal;
@@ -552,8 +549,8 @@ void main() {
bool normal_used = false;
#endif
- if (normal_used || (using_light && bool(draw_data.flags & FLAGS_DEFAULT_NORMAL_MAP_USED))) {
- normal.xy = texture(sampler2D(normal_texture, texture_sampler), uv).xy * vec2(2.0, -2.0) - vec2(1.0, -1.0);
+ if (normal_used || (using_light && bool(draw_data[draw_data_instance].flags & FLAGS_DEFAULT_NORMAL_MAP_USED))) {
+ normal.xy = texture(normal_texture, uv).xy * vec2(2.0, -2.0) - vec2(1.0, -1.0);
normal.z = sqrt(1.0 - dot(normal.xy, normal.xy));
normal_used = true;
} else {
@@ -569,16 +566,16 @@ void main() {
bool specular_shininess_used = false;
#endif
- if (specular_shininess_used || (using_light && normal_used && bool(draw_data.flags & FLAGS_DEFAULT_SPECULAR_MAP_USED))) {
- specular_shininess = texture(sampler2D(specular_texture, texture_sampler), uv);
- specular_shininess *= unpackUnorm4x8(draw_data.specular_shininess);
+ if (specular_shininess_used || (using_light && normal_used && bool(draw_data[draw_data_instance].flags & FLAGS_DEFAULT_SPECULAR_MAP_USED))) {
+ specular_shininess = texture(specular_texture, uv);
+ specular_shininess *= unpackUnorm4x8(draw_data[draw_data_instance].specular_shininess);
specular_shininess_used = true;
} else {
specular_shininess = vec4(1.0);
}
#if defined(SCREEN_UV_USED)
- vec2 screen_uv = gl_FragCoord.xy * canvas_data.screen_pixel_size;
+ vec2 screen_uv = gl_FragCoord.xy * screen_pixel_size;
#else
vec2 screen_uv = vec2(0.0);
#endif
@@ -603,46 +600,46 @@ void main() {
if (normal_used) {
//convert by item transform
- normal.xy = mat2(normalize(draw_data.world_x), normalize(draw_data.world_y)) * normal.xy;
+ normal.xy = mat2(normalize(draw_data[draw_data_instance].world_x), normalize(draw_data[draw_data_instance].world_y)) * normal.xy;
//convert by canvas transform
- normal = normalize((canvas_data.canvas_normal_transform * vec4(normal, 0.0)).xyz);
+ normal = normalize((canvas_normal_transform * vec4(normal, 0.0)).xyz);
}
vec3 base_color = color.rgb;
- if (bool(draw_data.flags & FLAGS_USING_LIGHT_MASK)) {
+ if (bool(draw_data[draw_data_instance].flags & FLAGS_USING_LIGHT_MASK)) {
color = vec4(0.0); //invisible by default due to using light mask
}
#ifdef MODE_LIGHT_ONLY
color = vec4(0.0);
#else
- color *= canvas_data.canvas_modulation;
+ color *= canvas_modulation;
#endif
#if !defined(DISABLE_LIGHTING) && !defined(MODE_UNSHADED)
- for (uint i = 0; i < canvas_data.directional_light_count; i++) {
+ for (uint i = uint(0); i < directional_light_count; i++) {
uint light_base = i;
- vec2 direction = light_array.data[light_base].position;
- vec4 light_color = light_array.data[light_base].color;
+ vec2 direction = light_data[light_base].position;
+ vec4 light_color = light_data[light_base].color;
#ifdef LIGHT_CODE_USED
vec4 shadow_modulate = vec4(1.0);
- light_color = light_compute(light_vertex, vec3(direction, light_array.data[light_base].height), normal, light_color, light_color.a, specular_shininess, shadow_modulate, screen_uv, uv, color, true);
+ light_color = light_compute(light_vertex, vec3(direction, light_data[light_base].height), normal, light_color, light_color.a, specular_shininess, shadow_modulate, screen_uv, uv, color, true);
#else
if (normal_used) {
- vec3 light_vec = normalize(mix(vec3(direction, 0.0), vec3(0, 0, 1), light_array.data[light_base].height));
+ vec3 light_vec = normalize(mix(vec3(direction, 0.0), vec3(0, 0, 1), light_data[light_base].height));
light_color.rgb = light_normal_compute(light_vec, normal, base_color, light_color.rgb, specular_shininess, specular_shininess_used);
}
#endif
- if (bool(light_array.data[light_base].flags & LIGHT_FLAGS_HAS_SHADOW)) {
- vec2 shadow_pos = (vec4(shadow_vertex, 0.0, 1.0) * mat4(light_array.data[light_base].shadow_matrix[0], light_array.data[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.
+ if (bool(light_data[light_base].flags & LIGHT_FLAGS_HAS_SHADOW)) {
+ vec2 shadow_pos = (vec4(shadow_vertex, 0.0, 1.0) * mat4(light_data[light_base].shadow_matrix[0], light_data[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.data[light_base].shadow_y_ofs, shadow_pos.y * light_array.data[light_base].shadow_zfar_inv, 1.0);
+ vec4 shadow_uv = vec4(shadow_pos.x, light_data[light_base].shadow_y_ofs, shadow_pos.y * light_data[light_base].shadow_zfar_inv, 1.0);
light_color = light_shadow_compute(light_base, light_color, shadow_uv
#ifdef LIGHT_CODE_USED
@@ -657,36 +654,36 @@ void main() {
// Positional Lights
- for (uint i = 0; i < MAX_LIGHTS_PER_ITEM; i++) {
+ for (uint i = uint(0); i < MAX_LIGHTS_PER_ITEM; i++) {
if (i >= light_count) {
break;
}
uint light_base;
- if (i < 8) {
- if (i < 4) {
- light_base = draw_data.lights[0];
+ if (i < uint(8)) {
+ if (i < uint(4)) {
+ light_base = draw_data[draw_data_instance].lights.x;
} else {
- light_base = draw_data.lights[1];
+ light_base = draw_data[draw_data_instance].lights.y;
}
} else {
- if (i < 12) {
- light_base = draw_data.lights[2];
+ if (i < uint(12)) {
+ light_base = draw_data[draw_data_instance].lights.z;
} else {
- light_base = draw_data.lights[3];
+ light_base = draw_data[draw_data_instance].lights.w;
}
}
- light_base >>= (i & 3) * 8;
- light_base &= 0xFF;
+ light_base >>= (i & uint(3)) * uint(8);
+ light_base &= uint(0xFF);
- vec2 tex_uv = (vec4(vertex, 0.0, 1.0) * mat4(light_array.data[light_base].texture_matrix[0], light_array.data[light_base].texture_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 tex_uv_atlas = tex_uv * light_array.data[light_base].atlas_rect.zw + light_array.data[light_base].atlas_rect.xy;
- vec4 light_color = textureLod(sampler2D(atlas_texture, texture_sampler), tex_uv_atlas, 0.0);
- vec4 light_base_color = light_array.data[light_base].color;
+ vec2 tex_uv = (vec4(vertex, 0.0, 1.0) * mat4(light_data[light_base].texture_matrix[0], light_data[light_base].texture_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 tex_uv_atlas = tex_uv * light_data[light_base].atlas_rect.zw + light_data[light_base].atlas_rect.xy;
+ vec4 light_color = textureLod(atlas_texture, tex_uv_atlas, 0.0);
+ vec4 light_base_color = light_data[light_base].color;
#ifdef LIGHT_CODE_USED
vec4 shadow_modulate = vec4(1.0);
- vec3 light_position = vec3(light_array.data[light_base].position, light_array.data[light_base].height);
+ vec3 light_position = vec3(light_data[light_base].position, light_data[light_base].height);
light_color.rgb *= light_base_color.rgb;
light_color = light_compute(light_vertex, light_position, normal, light_color, light_base_color.a, specular_shininess, shadow_modulate, screen_uv, uv, color, false);
@@ -695,7 +692,7 @@ void main() {
light_color.rgb *= light_base_color.rgb * light_base_color.a;
if (normal_used) {
- vec3 light_pos = vec3(light_array.data[light_base].position, light_array.data[light_base].height);
+ vec3 light_pos = vec3(light_data[light_base].position, light_data[light_base].height);
vec3 pos = light_vertex;
vec3 light_vec = normalize(light_pos - pos);
float cNdotL = max(0.0, dot(normal, light_vec));
@@ -708,8 +705,8 @@ void main() {
light_color.a = 0.0;
}
- if (bool(light_array.data[light_base].flags & LIGHT_FLAGS_HAS_SHADOW)) {
- vec2 shadow_pos = (vec4(shadow_vertex, 0.0, 1.0) * mat4(light_array.data[light_base].shadow_matrix[0], light_array.data[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.
+ if (bool(light_data[light_base].flags & LIGHT_FLAGS_HAS_SHADOW)) {
+ vec2 shadow_pos = (vec4(shadow_vertex, 0.0, 1.0) * mat4(light_data[light_base].shadow_matrix[0], light_data[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);
vec2 pos_abs = abs(pos_norm);
@@ -735,10 +732,10 @@ void main() {
}
}
- distance *= light_array.data[light_base].shadow_zfar_inv;
+ distance *= light_data[light_base].shadow_zfar_inv;
//float distance = length(shadow_pos);
- vec4 shadow_uv = vec4(tex_ofs, light_array.data[light_base].shadow_y_ofs, distance, 1.0);
+ vec4 shadow_uv = vec4(tex_ofs, light_data[light_base].shadow_y_ofs, distance, 1.0);
light_color = light_shadow_compute(light_base, light_color, shadow_uv
#ifdef LIGHT_CODE_USED
diff --git a/drivers/gles3/shaders/canvas_old.glsl b/drivers/gles3/shaders/canvas_old.glsl
deleted file mode 100644
index f2b141252a..0000000000
--- a/drivers/gles3/shaders/canvas_old.glsl
+++ /dev/null
@@ -1,665 +0,0 @@
-/* clang-format off */
-[vertex]
-
-#ifdef USE_GLES_OVER_GL
-#define lowp
-#define mediump
-#define highp
-#else
-precision highp float;
-precision highp int;
-#endif
-
-uniform highp mat4 projection_matrix;
-/* clang-format on */
-
-uniform highp mat4 modelview_matrix;
-uniform highp mat4 extra_matrix;
-layout(location = 0) in highp vec2 vertex;
-
-#ifdef USE_ATTRIB_LIGHT_ANGLE
-// shared with tangent, not used in canvas shader
-layout(location = 2) in highp float light_angle;
-#endif
-
-layout(location = 3) in vec4 color_attrib;
-layout(location = 4) in vec2 uv_attrib;
-
-#ifdef USE_ATTRIB_MODULATE
-layout(location = 5) in highp vec4 modulate_attrib;
-#endif
-
-#ifdef USE_ATTRIB_LARGE_VERTEX
-// shared with skeleton attributes, not used in batched shader
-layout(location = 6) in highp vec2 translate_attrib;
-layout(location = 7) in highp vec4 basis_attrib;
-#endif
-
-#ifdef USE_SKELETON
-layout(location = 6) in highp vec4 bone_indices;
-layout(location = 7) in highp vec4 bone_weights;
-#endif
-
-#ifdef USE_INSTANCING
-
-layout(location = 8) in highp vec4 instance_xform0;
-layout(location = 9) in highp vec4 instance_xform1;
-layout(location = 10) in highp vec4 instance_xform2;
-layout(location = 11) in highp vec4 instance_color;
-
-#ifdef USE_INSTANCE_CUSTOM
-layout(location = 12) in highp vec4 instance_custom_data;
-#endif
-
-#endif
-
-#ifdef USE_SKELETON
-uniform highp sampler2D skeleton_texture; // texunit:-3
-uniform highp ivec2 skeleton_texture_size;
-uniform highp mat4 skeleton_transform;
-uniform highp mat4 skeleton_transform_inverse;
-#endif
-
-out vec2 uv_interp;
-out vec4 color_interp;
-
-#ifdef USE_ATTRIB_MODULATE
-// modulate doesn't need interpolating but we need to send it to the fragment shader
-flat out vec4 modulate_interp;
-#endif
-
-#ifdef MODULATE_USED
-uniform vec4 final_modulate;
-#endif
-
-uniform highp vec2 color_texpixel_size;
-
-#ifdef USE_TEXTURE_RECT
-
-uniform vec4 dst_rect;
-uniform vec4 src_rect;
-
-#endif
-
-uniform highp float time;
-
-#ifdef USE_LIGHTING
-
-// light matrices
-uniform highp mat4 light_matrix;
-uniform highp mat4 light_matrix_inverse;
-uniform highp mat4 light_local_matrix;
-uniform highp mat4 shadow_matrix;
-uniform highp vec4 light_color;
-uniform highp vec4 light_shadow_color;
-uniform highp vec2 light_pos;
-uniform highp float shadowpixel_size;
-uniform highp float shadow_gradient;
-uniform highp float light_height;
-uniform highp float light_outside_alpha;
-uniform highp float shadow_distance_mult;
-
-out vec4 light_uv_interp;
-out vec2 transformed_light_uv;
-out vec4 local_rot;
-
-#ifdef USE_SHADOWS
-out highp vec2 pos;
-#endif
-
-const bool at_light_pass = true;
-#else
-const bool at_light_pass = false;
-#endif
-
-/* clang-format off */
-
-VERTEX_SHADER_GLOBALS
-
-/* clang-format on */
-
-vec2 select(vec2 a, vec2 b, bvec2 c) {
- vec2 ret;
-
- ret.x = c.x ? b.x : a.x;
- ret.y = c.y ? b.y : a.y;
-
- return ret;
-}
-
-void main() {
- vec4 color = color_attrib;
- vec2 uv;
-
-#ifdef USE_INSTANCING
- mat4 extra_matrix_instance = extra_matrix * transpose(mat4(instance_xform0, instance_xform1, instance_xform2, vec4(0.0, 0.0, 0.0, 1.0)));
- color *= instance_color;
-
-#ifdef USE_INSTANCE_CUSTOM
- vec4 instance_custom = instance_custom_data;
-#else
- vec4 instance_custom = vec4(0.0);
-#endif
-
-#else
- mat4 extra_matrix_instance = extra_matrix;
- vec4 instance_custom = vec4(0.0);
-#endif
-
-#ifdef USE_TEXTURE_RECT
-
- if (dst_rect.z < 0.0) { // Transpose is encoded as negative dst_rect.z
- uv = src_rect.xy + abs(src_rect.zw) * vertex.yx;
- } else {
- uv = src_rect.xy + abs(src_rect.zw) * vertex;
- }
-
- vec4 outvec = vec4(0.0, 0.0, 0.0, 1.0);
-
- // This is what is done in the GLES 3 bindings and should
- // take care of flipped rects.
- //
- // But it doesn't.
- // I don't know why, will need to investigate further.
-
- outvec.xy = dst_rect.xy + abs(dst_rect.zw) * select(vertex, vec2(1.0, 1.0) - vertex, lessThan(src_rect.zw, vec2(0.0, 0.0)));
-
- // outvec.xy = dst_rect.xy + abs(dst_rect.zw) * vertex;
-#else
- vec4 outvec = vec4(vertex.xy, 0.0, 1.0);
-
- uv = uv_attrib;
-#endif
-
- float point_size = 1.0;
-
- {
- vec2 src_vtx = outvec.xy;
- /* clang-format off */
-
-VERTEX_SHADER_CODE
-
- /* clang-format on */
- }
-
- gl_PointSize = point_size;
-
-#ifdef USE_ATTRIB_MODULATE
- // modulate doesn't need interpolating but we need to send it to the fragment shader
- modulate_interp = modulate_attrib;
-#endif
-
-#ifdef USE_ATTRIB_LARGE_VERTEX
- // transform is in attributes
- vec2 temp;
-
- temp = outvec.xy;
- temp.x = (outvec.x * basis_attrib.x) + (outvec.y * basis_attrib.z);
- temp.y = (outvec.x * basis_attrib.y) + (outvec.y * basis_attrib.w);
-
- temp += translate_attrib;
- outvec.xy = temp;
-
-#else
-
- // transform is in uniforms
-#if !defined(SKIP_TRANSFORM_USED)
- outvec = extra_matrix_instance * outvec;
- outvec = modelview_matrix * outvec;
-#endif
-
-#endif // not large integer
-
- color_interp = color;
-
-#ifdef USE_PIXEL_SNAP
- outvec.xy = floor(outvec + 0.5).xy;
- // precision issue on some hardware creates artifacts within texture
- // offset uv by a small amount to avoid
- uv += 1e-5;
-#endif
-
-#ifdef USE_SKELETON
-
- // look up transform from the "pose texture"
- if (bone_weights != vec4(0.0)) {
- highp mat4 bone_transform = mat4(0.0);
-
- for (int i = 0; i < 4; i++) {
- ivec2 tex_ofs = ivec2(int(bone_indices[i]) * 2, 0);
-
- highp mat4 b = mat4(
- texel2DFetch(skeleton_texture, skeleton_texture_size, tex_ofs + ivec2(0, 0)),
- texel2DFetch(skeleton_texture, skeleton_texture_size, tex_ofs + ivec2(1, 0)),
- vec4(0.0, 0.0, 1.0, 0.0),
- vec4(0.0, 0.0, 0.0, 1.0));
-
- bone_transform += b * bone_weights[i];
- }
-
- mat4 bone_matrix = skeleton_transform * transpose(bone_transform) * skeleton_transform_inverse;
-
- outvec = bone_matrix * outvec;
- }
-
-#endif
-
- uv_interp = uv;
- gl_Position = projection_matrix * outvec;
-
-#ifdef USE_LIGHTING
-
- light_uv_interp.xy = (light_matrix * outvec).xy;
- light_uv_interp.zw = (light_local_matrix * outvec).xy;
-
- transformed_light_uv = (mat3(light_matrix_inverse) * vec3(light_uv_interp.zw, 0.0)).xy; //for normal mapping
-
-#ifdef USE_SHADOWS
- pos = outvec.xy;
-#endif
-
-#ifdef USE_ATTRIB_LIGHT_ANGLE
- // we add a fixed offset because we are using the sign later,
- // and don't want floating point error around 0.0
- float la = abs(light_angle) - 1.0;
-
- // vector light angle
- vec4 vla;
- vla.xy = vec2(cos(la), sin(la));
- vla.zw = vec2(-vla.y, vla.x);
-
- // vertical flip encoded in the sign
- vla.zw *= sign(light_angle);
-
- // apply the transform matrix.
- // The rotate will be encoded in the transform matrix for single rects,
- // and just the flips in the light angle.
- // For batching we will encode the rotation and the flips
- // in the light angle, and can use the same shader.
- local_rot.xy = normalize((modelview_matrix * (extra_matrix_instance * vec4(vla.xy, 0.0, 0.0))).xy);
- local_rot.zw = normalize((modelview_matrix * (extra_matrix_instance * vec4(vla.zw, 0.0, 0.0))).xy);
-#else
- local_rot.xy = normalize((modelview_matrix * (extra_matrix_instance * vec4(1.0, 0.0, 0.0, 0.0))).xy);
- local_rot.zw = normalize((modelview_matrix * (extra_matrix_instance * vec4(0.0, 1.0, 0.0, 0.0))).xy);
-#ifdef USE_TEXTURE_RECT
- local_rot.xy *= sign(src_rect.z);
- local_rot.zw *= sign(src_rect.w);
-#endif
-#endif // not using light angle
-
-#endif
-}
-
-/* clang-format off */
-[fragment]
-
-#ifdef USE_GLES_OVER_GL
-#define lowp
-#define mediump
-#define highp
-#else
-#if defined(USE_HIGHP_PRECISION)
-precision highp float;
-precision highp int;
-#else
-precision mediump float;
-precision mediump int;
-#endif
-#endif
-
-uniform sampler2D color_texture; // texunit:-1
-/* clang-format on */
-uniform highp vec2 color_texpixel_size;
-uniform mediump sampler2D normal_texture; // texunit:-2
-
-in mediump vec2 uv_interp;
-in mediump vec4 color_interp;
-
-#ifdef USE_ATTRIB_MODULATE
-in mediump vec4 modulate_interp;
-#endif
-
-uniform highp float time;
-
-uniform vec4 final_modulate;
-
-#ifdef SCREEN_TEXTURE_USED
-
-uniform sampler2D screen_texture; // texunit:-4
-
-#endif
-
-#ifdef SCREEN_UV_USED
-
-uniform vec2 screen_pixel_size;
-
-#endif
-
-#ifdef USE_LIGHTING
-
-uniform highp mat4 light_matrix;
-uniform highp mat4 light_local_matrix;
-uniform highp mat4 shadow_matrix;
-uniform highp vec4 light_color;
-uniform highp vec4 light_shadow_color;
-uniform highp vec2 light_pos;
-uniform highp float shadowpixel_size;
-uniform highp float shadow_gradient;
-uniform highp float light_height;
-uniform highp float light_outside_alpha;
-uniform highp float shadow_distance_mult;
-
-uniform lowp sampler2D light_texture; // texunit:-6
-in vec4 light_uv_interp;
-in vec2 transformed_light_uv;
-
-in vec4 local_rot;
-
-#ifdef USE_SHADOWS
-
-uniform highp sampler2D shadow_texture; // texunit:-5
-in highp vec2 pos;
-
-#endif
-
-const bool at_light_pass = true;
-#else
-const bool at_light_pass = false;
-#endif
-
-uniform bool use_default_normal;
-
-layout(location = 0) out mediump vec4 frag_color;
-
-/* clang-format off */
-
-FRAGMENT_SHADER_GLOBALS
-
-/* clang-format on */
-
-void light_compute(
- inout vec4 light,
- inout vec2 light_vec,
- inout float light_height,
- inout vec4 light_color,
- vec2 light_uv,
- inout vec4 shadow_color,
- inout vec2 shadow_vec,
- vec3 normal,
- vec2 uv,
-#if defined(SCREEN_UV_USED)
- vec2 screen_uv,
-#endif
- vec4 color) {
-
-#if defined(USE_LIGHT_SHADER_CODE)
-
- /* clang-format off */
-
-LIGHT_SHADER_CODE
-
- /* clang-format on */
-
-#endif
-}
-
-void main() {
- vec4 color = color_interp;
- vec2 uv = uv_interp;
-#ifdef USE_FORCE_REPEAT
- //needs to use this to workaround GLES2/WebGL1 forcing tiling that textures that don't support it
- uv = mod(uv, vec2(1.0, 1.0));
-#endif
-
-#if !defined(COLOR_USED)
- //default behavior, texture by color
- color *= texture(color_texture, uv);
-#endif
-
-#ifdef SCREEN_UV_USED
- vec2 screen_uv = gl_FragCoord.xy * screen_pixel_size;
-#endif
-
- vec3 normal;
-
-#if defined(NORMAL_USED)
-
- bool normal_used = true;
-#else
- bool normal_used = false;
-#endif
-
- if (use_default_normal) {
- normal.xy = texture(normal_texture, uv).xy * 2.0 - 1.0;
- normal.z = sqrt(1.0 - dot(normal.xy, normal.xy));
- normal_used = true;
- } else {
- normal = vec3(0.0, 0.0, 1.0);
- }
-
- {
- float normal_depth = 1.0;
-
-#if defined(NORMALMAP_USED)
- vec3 normal_map = vec3(0.0, 0.0, 1.0);
- normal_used = true;
-#endif
-
- /* clang-format off */
-
-FRAGMENT_SHADER_CODE
-
- /* clang-format on */
-
-#if defined(NORMALMAP_USED)
- normal = mix(vec3(0.0, 0.0, 1.0), normal_map * vec3(2.0, -2.0, 1.0) - vec3(1.0, -1.0, 0.0), normal_depth);
-#endif
- }
-
-#ifdef USE_ATTRIB_MODULATE
- color *= modulate_interp;
-#else
-#if !defined(MODULATE_USED)
- color *= final_modulate;
-#endif
-#endif
-
-#ifdef USE_LIGHTING
-
- vec2 light_vec = transformed_light_uv;
- vec2 shadow_vec = transformed_light_uv;
-
- if (normal_used) {
- normal.xy = mat2(local_rot.xy, local_rot.zw) * normal.xy;
- }
-
- float att = 1.0;
-
- vec2 light_uv = light_uv_interp.xy;
- vec4 light = texture(light_texture, light_uv);
-
- if (any(lessThan(light_uv_interp.xy, vec2(0.0, 0.0))) || any(greaterThanEqual(light_uv_interp.xy, vec2(1.0, 1.0)))) {
- color.a *= light_outside_alpha; //invisible
-
- } else {
- float real_light_height = light_height;
- vec4 real_light_color = light_color;
- vec4 real_light_shadow_color = light_shadow_color;
-
-#if defined(USE_LIGHT_SHADER_CODE)
- //light is written by the light shader
- light_compute(
- light,
- light_vec,
- real_light_height,
- real_light_color,
- light_uv,
- real_light_shadow_color,
- shadow_vec,
- normal,
- uv,
-#if defined(SCREEN_UV_USED)
- screen_uv,
-#endif
- color);
-#endif
-
- light *= real_light_color;
-
- if (normal_used) {
- vec3 light_normal = normalize(vec3(light_vec, -real_light_height));
- light *= max(dot(-light_normal, normal), 0.0);
- }
-
- color *= light;
-
-#ifdef USE_SHADOWS
-
-#ifdef SHADOW_VEC_USED
- mat3 inverse_light_matrix = mat3(light_matrix);
- inverse_light_matrix[0] = normalize(inverse_light_matrix[0]);
- inverse_light_matrix[1] = normalize(inverse_light_matrix[1]);
- inverse_light_matrix[2] = normalize(inverse_light_matrix[2]);
- shadow_vec = (inverse_light_matrix * vec3(shadow_vec, 0.0)).xy;
-#else
- shadow_vec = light_uv_interp.zw;
-#endif
-
- float angle_to_light = -atan(shadow_vec.x, shadow_vec.y);
- float PI = 3.14159265358979323846264;
- /*int i = int(mod(floor((angle_to_light+7.0*PI/6.0)/(4.0*PI/6.0))+1.0, 3.0)); // +1 pq os indices estao em ordem 2,0,1 nos arrays
- float ang*/
-
- float su, sz;
-
- float abs_angle = abs(angle_to_light);
- vec2 point;
- float sh;
- if (abs_angle < 45.0 * PI / 180.0) {
- point = shadow_vec;
- sh = 0.0 + (1.0 / 8.0);
- } else if (abs_angle > 135.0 * PI / 180.0) {
- point = -shadow_vec;
- sh = 0.5 + (1.0 / 8.0);
- } else if (angle_to_light > 0.0) {
- point = vec2(shadow_vec.y, -shadow_vec.x);
- sh = 0.25 + (1.0 / 8.0);
- } else {
- point = vec2(-shadow_vec.y, shadow_vec.x);
- sh = 0.75 + (1.0 / 8.0);
- }
-
- highp vec4 s = shadow_matrix * vec4(point, 0.0, 1.0);
- s.xyz /= s.w;
- su = s.x * 0.5 + 0.5;
- sz = s.z * 0.5 + 0.5;
- //sz=lightlength(light_vec);
-
- highp float shadow_attenuation = 0.0;
-
-#ifdef USE_RGBA_SHADOWS
-#define SHADOW_DEPTH(m_tex, m_uv) dot(texture((m_tex), (m_uv)), vec4(1.0 / (255.0 * 255.0 * 255.0), 1.0 / (255.0 * 255.0), 1.0 / 255.0, 1.0))
-
-#else
-
-#define SHADOW_DEPTH(m_tex, m_uv) (texture((m_tex), (m_uv)).r)
-
-#endif
-
-#ifdef SHADOW_USE_GRADIENT
-
- /* clang-format off */
- /* GLSL es 100 doesn't support line continuation characters(backslashes) */
-#define SHADOW_TEST(m_ofs) { highp float sd = SHADOW_DEPTH(shadow_texture, vec2(m_ofs, sh)); shadow_attenuation += 1.0 - smoothstep(sd, sd + shadow_gradient, sz); }
-
-#else
-
-#define SHADOW_TEST(m_ofs) { highp float sd = SHADOW_DEPTH(shadow_texture, vec2(m_ofs, sh)); shadow_attenuation += step(sz, sd); }
- /* clang-format on */
-
-#endif
-
-#ifdef SHADOW_FILTER_NEAREST
-
- SHADOW_TEST(su);
-
-#endif
-
-#ifdef SHADOW_FILTER_PCF3
-
- SHADOW_TEST(su + shadowpixel_size);
- SHADOW_TEST(su);
- SHADOW_TEST(su - shadowpixel_size);
- shadow_attenuation /= 3.0;
-
-#endif
-
-#ifdef SHADOW_FILTER_PCF5
-
- SHADOW_TEST(su + shadowpixel_size * 2.0);
- SHADOW_TEST(su + shadowpixel_size);
- SHADOW_TEST(su);
- SHADOW_TEST(su - shadowpixel_size);
- SHADOW_TEST(su - shadowpixel_size * 2.0);
- shadow_attenuation /= 5.0;
-
-#endif
-
-#ifdef SHADOW_FILTER_PCF7
-
- SHADOW_TEST(su + shadowpixel_size * 3.0);
- SHADOW_TEST(su + shadowpixel_size * 2.0);
- SHADOW_TEST(su + shadowpixel_size);
- SHADOW_TEST(su);
- SHADOW_TEST(su - shadowpixel_size);
- SHADOW_TEST(su - shadowpixel_size * 2.0);
- SHADOW_TEST(su - shadowpixel_size * 3.0);
- shadow_attenuation /= 7.0;
-
-#endif
-
-#ifdef SHADOW_FILTER_PCF9
-
- SHADOW_TEST(su + shadowpixel_size * 4.0);
- SHADOW_TEST(su + shadowpixel_size * 3.0);
- SHADOW_TEST(su + shadowpixel_size * 2.0);
- SHADOW_TEST(su + shadowpixel_size);
- SHADOW_TEST(su);
- SHADOW_TEST(su - shadowpixel_size);
- SHADOW_TEST(su - shadowpixel_size * 2.0);
- SHADOW_TEST(su - shadowpixel_size * 3.0);
- SHADOW_TEST(su - shadowpixel_size * 4.0);
- shadow_attenuation /= 9.0;
-
-#endif
-
-#ifdef SHADOW_FILTER_PCF13
-
- SHADOW_TEST(su + shadowpixel_size * 6.0);
- SHADOW_TEST(su + shadowpixel_size * 5.0);
- SHADOW_TEST(su + shadowpixel_size * 4.0);
- SHADOW_TEST(su + shadowpixel_size * 3.0);
- SHADOW_TEST(su + shadowpixel_size * 2.0);
- SHADOW_TEST(su + shadowpixel_size);
- SHADOW_TEST(su);
- SHADOW_TEST(su - shadowpixel_size);
- SHADOW_TEST(su - shadowpixel_size * 2.0);
- SHADOW_TEST(su - shadowpixel_size * 3.0);
- SHADOW_TEST(su - shadowpixel_size * 4.0);
- SHADOW_TEST(su - shadowpixel_size * 5.0);
- SHADOW_TEST(su - shadowpixel_size * 6.0);
- shadow_attenuation /= 13.0;
-
-#endif
-
- //color *= shadow_attenuation;
- color = mix(real_light_shadow_color, color, shadow_attenuation);
-//use shadows
-#endif
- }
-
-//use lighting
-#endif
-
- frag_color = color;
-}
diff --git a/drivers/gles3/shaders/canvas_shadow.glsl b/drivers/gles3/shaders/canvas_shadow.glsl
index 2b3be43f6e..65389c211a 100644
--- a/drivers/gles3/shaders/canvas_shadow.glsl
+++ b/drivers/gles3/shaders/canvas_shadow.glsl
@@ -10,7 +10,7 @@ precision highp float;
precision highp int;
#endif
-layout(location = 0) highp vec3 vertex;
+layout(location = 0) in highp vec3 vertex;
uniform highp mat4 projection_matrix;
/* clang-format on */
diff --git a/drivers/gles3/shaders/canvas_uniforms_inc.glsl b/drivers/gles3/shaders/canvas_uniforms_inc.glsl
index 942ad72b93..e08a15e59d 100644
--- a/drivers/gles3/shaders/canvas_uniforms_inc.glsl
+++ b/drivers/gles3/shaders/canvas_uniforms_inc.glsl
@@ -1,53 +1,62 @@
-#define MAX_LIGHTS_PER_ITEM 16
+#define MAX_LIGHTS_PER_ITEM uint(16)
#define M_PI 3.14159265359
#define SDF_MAX_LENGTH 16384.0
//1 means enabled, 2+ means trails in use
-#define FLAGS_INSTANCING_MASK 0x7F
-#define FLAGS_INSTANCING_HAS_COLORS (1 << 7)
-#define FLAGS_INSTANCING_HAS_CUSTOM_DATA (1 << 8)
+#define FLAGS_INSTANCING_MASK uint(0x7F)
+#define FLAGS_INSTANCING_HAS_COLORS uint(1 << 7)
+#define FLAGS_INSTANCING_HAS_CUSTOM_DATA uint(1 << 8)
-#define FLAGS_CLIP_RECT_UV (1 << 9)
-#define FLAGS_TRANSPOSE_RECT (1 << 10)
-#define FLAGS_USING_LIGHT_MASK (1 << 11)
-#define FLAGS_NINEPACH_DRAW_CENTER (1 << 12)
-#define FLAGS_USING_PARTICLES (1 << 13)
+#define FLAGS_CLIP_RECT_UV uint(1 << 9)
+#define FLAGS_TRANSPOSE_RECT uint(1 << 10)
+#define FLAGS_USING_LIGHT_MASK uint(1 << 11)
+#define FLAGS_NINEPACH_DRAW_CENTER uint(1 << 12)
+#define FLAGS_USING_PARTICLES uint(1 << 13)
#define FLAGS_NINEPATCH_H_MODE_SHIFT 16
#define FLAGS_NINEPATCH_V_MODE_SHIFT 18
#define FLAGS_LIGHT_COUNT_SHIFT 20
-#define FLAGS_DEFAULT_NORMAL_MAP_USED (1 << 26)
-#define FLAGS_DEFAULT_SPECULAR_MAP_USED (1 << 27)
+#define FLAGS_DEFAULT_NORMAL_MAP_USED uint(1 << 26)
+#define FLAGS_DEFAULT_SPECULAR_MAP_USED uint(1 << 27)
-#define FLAGS_USE_MSDF (1 << 28)
+#define FLAGS_USE_MSDF uint(1 << 28)
// must be always 128 bytes long
struct DrawData {
vec2 world_x;
vec2 world_y;
vec2 world_ofs;
- uint flags;
- uint specular_shininess;
+ vec2 color_texture_pixel_size;
#ifdef USE_PRIMITIVE
- vec2 points[3];
- vec2 uvs[3];
- uint colors[6];
+ vec2 point_a;
+ vec2 point_b;
+ vec2 point_c;
+ vec2 uv_a;
+ vec2 uv_b;
+ vec2 uv_c;
+ uint color_a_rg;
+ uint color_a_ba;
+ uint color_b_rg;
+ uint color_b_ba;
+ uint color_c_rg;
+ uint color_c_ba;
#else
vec4 modulation;
vec4 ninepatch_margins;
vec4 dst_rect; //for built-in rect and UV
vec4 src_rect;
- vec2 pad;
-
+ uint pad;
+ uint pad2;
#endif
- vec2 color_texture_pixel_size;
- uint lights[4];
-}
+ uint flags;
+ uint specular_shininess;
+ uvec4 lights;
+};
layout(std140) uniform GlobalVariableData { //ubo:1
vec4 global_variables[MAX_GLOBAL_VARIABLES];
@@ -72,17 +81,17 @@ layout(std140) uniform CanvasData { //ubo:0
uint pad2;
};
-#define LIGHT_FLAGS_BLEND_MASK (3 << 16)
-#define LIGHT_FLAGS_BLEND_MODE_ADD (0 << 16)
-#define LIGHT_FLAGS_BLEND_MODE_SUB (1 << 16)
-#define LIGHT_FLAGS_BLEND_MODE_MIX (2 << 16)
-#define LIGHT_FLAGS_BLEND_MODE_MASK (3 << 16)
-#define LIGHT_FLAGS_HAS_SHADOW (1 << 20)
+#define LIGHT_FLAGS_BLEND_MASK uint(3 << 16)
+#define LIGHT_FLAGS_BLEND_MODE_ADD uint(0 << 16)
+#define LIGHT_FLAGS_BLEND_MODE_SUB uint(1 << 16)
+#define LIGHT_FLAGS_BLEND_MODE_MIX uint(2 << 16)
+#define LIGHT_FLAGS_BLEND_MODE_MASK uint(3 << 16)
+#define LIGHT_FLAGS_HAS_SHADOW uint(1 << 20)
#define LIGHT_FLAGS_FILTER_SHIFT 22
-#define LIGHT_FLAGS_FILTER_MASK (3 << 22)
-#define LIGHT_FLAGS_SHADOW_NEAREST (0 << 22)
-#define LIGHT_FLAGS_SHADOW_PCF5 (1 << 22)
-#define LIGHT_FLAGS_SHADOW_PCF13 (2 << 22)
+#define LIGHT_FLAGS_FILTER_MASK uint(3 << 22)
+#define LIGHT_FLAGS_SHADOW_NEAREST uint(0 << 22)
+#define LIGHT_FLAGS_SHADOW_PCF5 uint(1 << 22)
+#define LIGHT_FLAGS_SHADOW_PCF13 uint(2 << 22)
struct Light {
mat2x4 texture_matrix; //light to texture coordinate matrix (transposed)
diff --git a/drivers/gles3/shaders/copy.glsl b/drivers/gles3/shaders/copy.glsl
index 598c6fd614..62332a15a7 100644
--- a/drivers/gles3/shaders/copy.glsl
+++ b/drivers/gles3/shaders/copy.glsl
@@ -1,5 +1,21 @@
/* clang-format off */
-[vertex]
+#[modes]
+
+mode_default =
+mode_cubemap = #define USE_CUBEMAP
+mode_panorama = #define USE_PANORAMA
+mode_copy_section = #define USE_COPY_SECTION
+mode_asym_pano = #define USE_ASYM_PANO
+mode_no_alpha = #define USE_NO_ALPHA
+mode_custom_alpha = #define USE_CUSTOM_ALPHA
+mode_multiplier = #define USE_MULTIPLIER
+mode_sep_cbcr_texture = #define USE_SEP_CBCR_TEXTURE
+mode_ycbcr_to_rgb = #define USE_YCBCR_TO_RGB
+
+#[specializations]
+
+
+#[vertex]
#ifdef USE_GLES_OVER_GL
#define lowp
@@ -10,16 +26,16 @@ precision highp float;
precision highp int;
#endif
-layout(location = 0) highp vec4 vertex_attrib;
+layout(location = 0) in highp vec4 vertex_attrib;
/* clang-format on */
#if defined(USE_CUBEMAP) || defined(USE_PANORAMA)
-layout(location = 4) vec3 cube_in;
+layout(location = 4) in vec3 cube_in;
#else
-layout(location = 4) vec2 uv_in;
+layout(location = 4) in vec2 uv_in;
#endif
-layout(location = 5) vec2 uv2_in;
+layout(location = 5) in vec2 uv2_in;
#if defined(USE_CUBEMAP) || defined(USE_PANORAMA)
out vec3 cube_interp;
@@ -28,11 +44,6 @@ out vec2 uv_interp;
#endif
out vec2 uv2_interp;
-// These definitions are here because the shader-wrapper builder does
-// not understand `#elif defined()`
-#ifdef USE_DISPLAY_TRANSFORM
-#endif
-
#ifdef USE_COPY_SECTION
uniform highp vec4 copy_section;
#elif defined(USE_DISPLAY_TRANSFORM)
@@ -60,7 +71,7 @@ void main() {
}
/* clang-format off */
-[fragment]
+#[fragment]
#define M_PI 3.14159265359
@@ -96,7 +107,7 @@ uniform samplerCube source_cube; // texunit:0
uniform sampler2D source; // texunit:0
#endif
-#ifdef SEP_CBCR_TEXTURE
+#ifdef USE_SEP_CBCR_TEXTURE
uniform sampler2D CbCr; //texunit:1
#endif
@@ -156,8 +167,8 @@ void main() {
vec4 color = texturePanorama(source, normalize(cube_normal.xyz));
#elif defined(USE_CUBEMAP)
- vec4 color = textureCube(source_cube, normalize(cube_interp));
-#elif defined(SEP_CBCR_TEXTURE)
+ vec4 color = texture(source_cube, normalize(cube_interp));
+#elif defined(USE_SEP_CBCR_TEXTURE)
vec4 color;
color.r = texture(source, uv_interp).r;
color.gb = texture(CbCr, uv_interp).rg - vec2(0.5, 0.5);
@@ -166,7 +177,7 @@ void main() {
vec4 color = texture(source, uv_interp);
#endif
-#ifdef YCBCR_TO_RGB
+#ifdef USE_YCBCR_TO_RGB
// YCbCr -> RGB conversion
// Using BT.601, which is the standard for SDTV is provided as a reference
diff --git a/drivers/gles3/shaders/cube_to_dp.glsl b/drivers/gles3/shaders/cube_to_dp.glsl
index ea4df79d4e..2384529a89 100644
--- a/drivers/gles3/shaders/cube_to_dp.glsl
+++ b/drivers/gles3/shaders/cube_to_dp.glsl
@@ -10,9 +10,9 @@ precision mediump float;
precision mediump int;
#endif
-layout(location = 0) highp vec4 vertex_attrib;
+layout(location = 0) in highp vec4 vertex_attrib;
/* clang-format on */
-layout(location = 4) vec2 uv_in;
+layout(location = 4) in vec2 uv_in;
out vec2 uv_interp;
diff --git a/drivers/gles3/shaders/cubemap_filter.glsl b/drivers/gles3/shaders/cubemap_filter.glsl
index 04bf3ebf02..2081abfef6 100644
--- a/drivers/gles3/shaders/cubemap_filter.glsl
+++ b/drivers/gles3/shaders/cubemap_filter.glsl
@@ -10,9 +10,9 @@ precision highp float;
precision highp int;
#endif
-layout(location = 0) highp vec2 vertex;
+layout(location = 0) in highp vec2 vertex;
/* clang-format on */
-layout(location = 4) highp vec2 uv;
+layout(location = 4) in highp vec2 uv;
out highp vec2 uv_interp;
diff --git a/drivers/gles3/shaders/effect_blur.glsl b/drivers/gles3/shaders/effect_blur.glsl
index 80063a7175..c9184cca77 100644
--- a/drivers/gles3/shaders/effect_blur.glsl
+++ b/drivers/gles3/shaders/effect_blur.glsl
@@ -10,9 +10,9 @@ precision highp float;
precision highp int;
#endif
-layout(location = 0) vec2 vertex_attrib;
+layout(location = 0) in vec2 vertex_attrib;
/* clang-format on */
-layout(location = 4) vec2 uv_in;
+layout(location = 4) in vec2 uv_in;
out vec2 uv_interp;
diff --git a/drivers/gles3/shaders/lens_distorted.glsl b/drivers/gles3/shaders/lens_distorted.glsl
index 64c2d70cc8..3aaf1050e5 100644
--- a/drivers/gles3/shaders/lens_distorted.glsl
+++ b/drivers/gles3/shaders/lens_distorted.glsl
@@ -10,7 +10,7 @@ precision highp float;
precision highp int;
#endif
-layout(location = 0) highp vec2 vertex;
+layout(location = 0) in highp vec2 vertex;
/* clang-format on */
uniform vec2 offset;
diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl
index c2f3908395..98c92a1d99 100644
--- a/drivers/gles3/shaders/scene.glsl
+++ b/drivers/gles3/shaders/scene.glsl
@@ -18,38 +18,38 @@ precision highp int;
// attributes
//
-layout(location = 0) highp vec4 vertex_attrib;
+layout(location = 0) in highp vec4 vertex_attrib;
/* clang-format on */
-layout(location = 1) vec3 normal_attrib;
+layout(location = 1) in vec3 normal_attrib;
#if defined(ENABLE_TANGENT_INTERP) || defined(ENABLE_NORMALMAP)
-layout(location = 2) vec4 tangent_attrib;
+layout(location = 2) in vec4 tangent_attrib;
#endif
#if defined(ENABLE_COLOR_INTERP)
-layout(location = 3) vec4 color_attrib;
+layout(location = 3) in vec4 color_attrib;
#endif
#if defined(ENABLE_UV_INTERP)
-layout(location = 4) vec2 uv_attrib;
+layout(location = 4) in vec2 uv_attrib;
#endif
#if defined(ENABLE_UV2_INTERP) || defined(USE_LIGHTMAP)
-layout(location = 5) vec2 uv2_attrib;
+layout(location = 5) in vec2 uv2_attrib;
#endif
#ifdef USE_SKELETON
#ifdef USE_SKELETON_SOFTWARE
-layout(location = 13) highp vec4 bone_transform_row_0;
-layout(location = 14) highp vec4 bone_transform_row_1;
-layout(location = 15) highp vec4 bone_transform_row_2;
+layout(location = 13) in highp vec4 bone_transform_row_0;
+layout(location = 14) in highp vec4 bone_transform_row_1;
+layout(location = 15) in highp vec4 bone_transform_row_2;
#else
-layout(location = 6) vec4 bone_ids;
-layout(location = 7) highp vec4 bone_weights;
+layout(location = 6) in vec4 bone_ids;
+layout(location = 7) in highp vec4 bone_weights;
uniform highp sampler2D bone_transforms; // texunit:-1
uniform ivec2 skeleton_texture_size;
@@ -60,12 +60,12 @@ uniform ivec2 skeleton_texture_size;
#ifdef USE_INSTANCING
-layout(location = 8) highp vec4 instance_xform_row_0;
-layout(location = 9) highp vec4 instance_xform_row_1;
-layout(location = 10) highp vec4 instance_xform_row_2;
+layout(location = 8) in highp vec4 instance_xform_row_0;
+layout(location = 9) in highp vec4 instance_xform_row_1;
+layout(location = 10) in highp vec4 instance_xform_row_2;
-layout(location = 11) highp vec4 instance_color;
-layout(location = 12) highp vec4 instance_custom_data;
+layout(location = 11) in highp vec4 instance_color;
+layout(location = 12) in highp vec4 instance_custom_data;
#endif
diff --git a/drivers/gles3/shaders/stdlib_inc.glsl b/drivers/gles3/shaders/stdlib_inc.glsl
new file mode 100644
index 0000000000..2eddf9d479
--- /dev/null
+++ b/drivers/gles3/shaders/stdlib_inc.glsl
@@ -0,0 +1,58 @@
+//TODO: only needed by GLES_OVER_GL
+
+uint float2half(uint f) {
+ return ((f >> uint(16)) & uint(0x8000)) |
+ ((((f & uint(0x7f800000)) - uint(0x38000000)) >> uint(13)) & uint(0x7c00)) |
+ ((f >> uint(13)) & uint(0x03ff));
+}
+
+uint half2float(uint h) {
+ return ((h & uint(0x8000)) << uint(16)) | (((h & uint(0x7c00)) + uint(0x1c000)) << uint(13)) | ((h & uint(0x03ff)) << uint(13));
+}
+
+uint packHalf2x16(vec2 v) {
+ return float2half(floatBitsToUint(v.x)) | float2half(floatBitsToUint(v.y)) << uint(16);
+}
+
+vec2 unpackHalf2x16(uint v) {
+ return vec2(uintBitsToFloat(half2float(v & uint(0xffff))),
+ uintBitsToFloat(half2float(v >> uint(16))));
+}
+
+uint packUnorm2x16(vec2 v) {
+ uvec2 uv = uvec2(round(clamp(v, vec2(0.0), vec2(1.0)) * 65535.0));
+ return uv.x | uv.y << uint(16);
+}
+
+vec2 unpackUnorm2x16(uint p) {
+ return vec2(float(p & uint(0xffff)), float(p >> uint(16))) * 0.000015259021; // 1.0 / 65535.0 optimization
+}
+
+uint packSnorm2x16(vec2 v) {
+ uvec2 uv = uvec2(round(clamp(v, vec2(-1.0), vec2(1.0)) * 32767.0) + 32767.0);
+ return uv.x | uv.y << uint(16);
+}
+
+vec2 unpackSnorm2x16(uint p) {
+ vec2 v = vec2(float(p & uint(0xffff)), float(p >> uint(16)));
+ return clamp((v - 32767.0) * vec2(0.00003051851), vec2(-1.0), vec2(1.0));
+}
+
+uint packUnorm4x8(vec4 v) {
+ uvec4 uv = uvec4(round(clamp(v, vec4(0.0), vec4(1.0)) * 255.0));
+ return uv.x | uv.y << uint(8) | uv.z << uint(16) | uv.w << uint(24);
+}
+
+vec4 unpackUnorm4x8(uint p) {
+ return vec4(float(p & uint(0xffff)), float((p >> uint(8)) & uint(0xffff)), float((p >> uint(16)) & uint(0xffff)), float(p >> uint(24))) * 0.00392156862; // 1.0 / 255.0
+}
+
+uint packSnorm4x8(vec4 v) {
+ uvec4 uv = uvec4(round(clamp(v, vec4(-1.0), vec4(1.0)) * 127.0) + 127.0);
+ return uv.x | uv.y << uint(8) | uv.z << uint(16) | uv.w << uint(24);
+}
+
+vec4 unpackSnorm4x8(uint p) {
+ vec4 v = vec4(float(p & uint(0xffff)), float((p >> uint(8)) & uint(0xffff)), float((p >> uint(16)) & uint(0xffff)), float(p >> uint(24)));
+ return clamp((v - vec4(127.0)) * vec4(0.00787401574), vec4(-1.0), vec4(1.0));
+}
diff --git a/drivers/gles3/shaders/tonemap.glsl b/drivers/gles3/shaders/tonemap.glsl
index 8b3aa4d309..4f962626a3 100644
--- a/drivers/gles3/shaders/tonemap.glsl
+++ b/drivers/gles3/shaders/tonemap.glsl
@@ -10,9 +10,9 @@ precision highp float;
precision highp int;
#endif
-layout(location = 0) vec2 vertex_attrib;
+layout(location = 0) in vec2 vertex_attrib;
/* clang-format on */
-layout(location = 4) vec2 uv_in;
+layout(location = 4) in vec2 uv_in;
out vec2 uv_interp;