summaryrefslogtreecommitdiff
path: root/shaders/godot3.4/34-12.shader_test
diff options
context:
space:
mode:
Diffstat (limited to 'shaders/godot3.4/34-12.shader_test')
-rw-r--r--shaders/godot3.4/34-12.shader_test1585
1 files changed, 1585 insertions, 0 deletions
diff --git a/shaders/godot3.4/34-12.shader_test b/shaders/godot3.4/34-12.shader_test
new file mode 100644
index 0000000..ae985e4
--- /dev/null
+++ b/shaders/godot3.4/34-12.shader_test
@@ -0,0 +1,1585 @@
+[require]
+GLSL >= 1.20
+
+[fragment shader]
+#version 120
+#define USE_GLES_OVER_GL
+#define USE_TEXTURE_RECT
+#define COLOR_USED
+
+// texture2DLodEXT and textureCubeLodEXT are fragment shader specific.
+// Do not copy these defines in the vertex section.
+#ifndef USE_GLES_OVER_GL
+#ifdef GL_EXT_shader_texture_lod
+#extension GL_EXT_shader_texture_lod : enable
+#define texture2DLod(img, coord, lod) texture2DLodEXT(img, coord, lod)
+#define textureCubeLod(img, coord, lod) textureCubeLodEXT(img, coord, lod)
+#endif
+#endif // !USE_GLES_OVER_GL
+
+#ifdef GL_ARB_shader_texture_lod
+#extension GL_ARB_shader_texture_lod : enable
+#endif
+
+#if !defined(GL_EXT_shader_texture_lod) && !defined(GL_ARB_shader_texture_lod)
+#define texture2DLod(img, coord, lod) texture2D(img, coord, lod)
+#define textureCubeLod(img, coord, lod) textureCube(img, coord, lod)
+#endif
+
+#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
+
+
+vec2 select2(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;
+}
+
+vec3 select3(vec3 a, vec3 b, bvec3 c) {
+ vec3 ret;
+
+ ret.x = c.x ? b.x : a.x;
+ ret.y = c.y ? b.y : a.y;
+ ret.z = c.z ? b.z : a.z;
+
+ return ret;
+}
+
+vec4 select4(vec4 a, vec4 b, bvec4 c) {
+ vec4 ret;
+
+ ret.x = c.x ? b.x : a.x;
+ ret.y = c.y ? b.y : a.y;
+ ret.z = c.z ? b.z : a.z;
+ ret.w = c.w ? b.w : a.w;
+
+ return ret;
+}
+
+highp vec4 texel2DFetch(highp sampler2D tex, ivec2 size, ivec2 coord) {
+ float x_coord = float(2 * coord.x + 1) / float(size.x * 2);
+ float y_coord = float(2 * coord.y + 1) / float(size.y * 2);
+
+ return texture2DLod(tex, vec2(x_coord, y_coord), 0.0);
+}
+
+#if defined(SINH_USED)
+
+highp float sinh(highp float x) {
+ return 0.5 * (exp(x) - exp(-x));
+}
+
+highp vec2 sinh(highp vec2 x) {
+ return 0.5 * vec2(exp(x.x) - exp(-x.x), exp(x.y) - exp(-x.y));
+}
+
+highp vec3 sinh(highp vec3 x) {
+ return 0.5 * vec3(exp(x.x) - exp(-x.x), exp(x.y) - exp(-x.y), exp(x.z) - exp(-x.z));
+}
+
+highp vec4 sinh(highp vec4 x) {
+ return 0.5 * vec4(exp(x.x) - exp(-x.x), exp(x.y) - exp(-x.y), exp(x.z) - exp(-x.z), exp(x.w) - exp(-x.w));
+}
+
+#endif
+
+#if defined(COSH_USED)
+
+highp float cosh(highp float x) {
+ return 0.5 * (exp(x) + exp(-x));
+}
+
+highp vec2 cosh(highp vec2 x) {
+ return 0.5 * vec2(exp(x.x) + exp(-x.x), exp(x.y) + exp(-x.y));
+}
+
+highp vec3 cosh(highp vec3 x) {
+ return 0.5 * vec3(exp(x.x) + exp(-x.x), exp(x.y) + exp(-x.y), exp(x.z) + exp(-x.z));
+}
+
+highp vec4 cosh(highp vec4 x) {
+ return 0.5 * vec4(exp(x.x) + exp(-x.x), exp(x.y) + exp(-x.y), exp(x.z) + exp(-x.z), exp(x.w) + exp(-x.w));
+}
+
+#endif
+
+#if defined(TANH_USED)
+
+highp float tanh(highp float x) {
+ highp float exp2x = exp(2.0 * x);
+ return (exp2x - 1.0) / (exp2x + 1.0);
+}
+
+highp vec2 tanh(highp vec2 x) {
+ highp float exp2x = exp(2.0 * x.x);
+ highp float exp2y = exp(2.0 * x.y);
+ return vec2((exp2x - 1.0) / (exp2x + 1.0), (exp2y - 1.0) / (exp2y + 1.0));
+}
+
+highp vec3 tanh(highp vec3 x) {
+ highp float exp2x = exp(2.0 * x.x);
+ highp float exp2y = exp(2.0 * x.y);
+ highp float exp2z = exp(2.0 * x.z);
+ return vec3((exp2x - 1.0) / (exp2x + 1.0), (exp2y - 1.0) / (exp2y + 1.0), (exp2z - 1.0) / (exp2z + 1.0));
+}
+
+highp vec4 tanh(highp vec4 x) {
+ highp float exp2x = exp(2.0 * x.x);
+ highp float exp2y = exp(2.0 * x.y);
+ highp float exp2z = exp(2.0 * x.z);
+ highp float exp2w = exp(2.0 * x.w);
+ return vec4((exp2x - 1.0) / (exp2x + 1.0), (exp2y - 1.0) / (exp2y + 1.0), (exp2z - 1.0) / (exp2z + 1.0), (exp2w - 1.0) / (exp2w + 1.0));
+}
+
+#endif
+
+#if defined(ASINH_USED)
+
+highp float asinh(highp float x) {
+ return sign(x) * log(abs(x) + sqrt(1.0 + x * x));
+}
+
+highp vec2 asinh(highp vec2 x) {
+ return vec2(sign(x.x) * log(abs(x.x) + sqrt(1.0 + x.x * x.x)), sign(x.y) * log(abs(x.y) + sqrt(1.0 + x.y * x.y)));
+}
+
+highp vec3 asinh(highp vec3 x) {
+ return vec3(sign(x.x) * log(abs(x.x) + sqrt(1.0 + x.x * x.x)), sign(x.y) * log(abs(x.y) + sqrt(1.0 + x.y * x.y)), sign(x.z) * log(abs(x.z) + sqrt(1.0 + x.z * x.z)));
+}
+
+highp vec4 asinh(highp vec4 x) {
+ return vec4(sign(x.x) * log(abs(x.x) + sqrt(1.0 + x.x * x.x)), sign(x.y) * log(abs(x.y) + sqrt(1.0 + x.y * x.y)), sign(x.z) * log(abs(x.z) + sqrt(1.0 + x.z * x.z)), sign(x.w) * log(abs(x.w) + sqrt(1.0 + x.w * x.w)));
+}
+
+#endif
+
+#if defined(ACOSH_USED)
+
+highp float acosh(highp float x) {
+ return log(x + sqrt(x * x - 1.0));
+}
+
+highp vec2 acosh(highp vec2 x) {
+ return vec2(log(x.x + sqrt(x.x * x.x - 1.0)), log(x.y + sqrt(x.y * x.y - 1.0)));
+}
+
+highp vec3 acosh(highp vec3 x) {
+ return vec3(log(x.x + sqrt(x.x * x.x - 1.0)), log(x.y + sqrt(x.y * x.y - 1.0)), log(x.z + sqrt(x.z * x.z - 1.0)));
+}
+
+highp vec4 acosh(highp vec4 x) {
+ return vec4(log(x.x + sqrt(x.x * x.x - 1.0)), log(x.y + sqrt(x.y * x.y - 1.0)), log(x.z + sqrt(x.z * x.z - 1.0)), log(x.w + sqrt(x.w * x.w - 1.0)));
+}
+
+#endif
+
+#if defined(ATANH_USED)
+
+highp float atanh(highp float x) {
+ return 0.5 * log((1.0 + x) / (1.0 - x));
+}
+
+highp vec2 atanh(highp vec2 x) {
+ return 0.5 * vec2(log((1.0 + x.x) / (1.0 - x.x)), log((1.0 + x.y) / (1.0 - x.y)));
+}
+
+highp vec3 atanh(highp vec3 x) {
+ return 0.5 * vec3(log((1.0 + x.x) / (1.0 - x.x)), log((1.0 + x.y) / (1.0 - x.y)), log((1.0 + x.z) / (1.0 - x.z)));
+}
+
+highp vec4 atanh(highp vec4 x) {
+ return 0.5 * vec4(log((1.0 + x.x) / (1.0 - x.x)), log((1.0 + x.y) / (1.0 - x.y)), log((1.0 + x.z) / (1.0 - x.z)), log((1.0 + x.w) / (1.0 - x.w)));
+}
+
+#endif
+
+#if defined(ROUND_USED)
+
+highp float round(highp float x) {
+ return floor(x + 0.5);
+}
+
+highp vec2 round(highp vec2 x) {
+ return floor(x + vec2(0.5));
+}
+
+highp vec3 round(highp vec3 x) {
+ return floor(x + vec3(0.5));
+}
+
+highp vec4 round(highp vec4 x) {
+ return floor(x + vec4(0.5));
+}
+
+#endif
+
+#if defined(ROUND_EVEN_USED)
+
+highp float roundEven(highp float x) {
+ highp float t = x + 0.5;
+ highp float f = floor(t);
+ highp float r;
+ if (t == f) {
+ if (x > 0)
+ r = f - mod(f, 2);
+ else
+ r = f + mod(f, 2);
+ } else
+ r = f;
+ return r;
+}
+
+highp vec2 roundEven(highp vec2 x) {
+ return vec2(roundEven(x.x), roundEven(x.y));
+}
+
+highp vec3 roundEven(highp vec3 x) {
+ return vec3(roundEven(x.x), roundEven(x.y), roundEven(x.z));
+}
+
+highp vec4 roundEven(highp vec4 x) {
+ return vec4(roundEven(x.x), roundEven(x.y), roundEven(x.z), roundEven(x.w));
+}
+
+#endif
+
+#if defined(IS_INF_USED)
+
+bool isinf(highp float x) {
+ return (2 * x == x) && (x != 0);
+}
+
+bvec2 isinf(highp vec2 x) {
+ return bvec2((2 * x.x == x.x) && (x.x != 0), (2 * x.y == x.y) && (x.y != 0));
+}
+
+bvec3 isinf(highp vec3 x) {
+ return bvec3((2 * x.x == x.x) && (x.x != 0), (2 * x.y == x.y) && (x.y != 0), (2 * x.z == x.z) && (x.z != 0));
+}
+
+bvec4 isinf(highp vec4 x) {
+ return bvec4((2 * x.x == x.x) && (x.x != 0), (2 * x.y == x.y) && (x.y != 0), (2 * x.z == x.z) && (x.z != 0), (2 * x.w == x.w) && (x.w != 0));
+}
+
+#endif
+
+#if defined(IS_NAN_USED)
+
+bool isnan(highp float x) {
+ return x != x;
+}
+
+bvec2 isnan(highp vec2 x) {
+ return bvec2(x.x != x.x, x.y != x.y);
+}
+
+bvec3 isnan(highp vec3 x) {
+ return bvec3(x.x != x.x, x.y != x.y, x.z != x.z);
+}
+
+bvec4 isnan(highp vec4 x) {
+ return bvec4(x.x != x.x, x.y != x.y, x.z != x.z, x.w != x.w);
+}
+
+#endif
+
+#if defined(TRUNC_USED)
+
+highp float trunc(highp float x) {
+ return x < 0.0 ? -floor(-x) : floor(x);
+}
+
+highp vec2 trunc(highp vec2 x) {
+ return vec2(x.x < 0.0 ? -floor(-x.x) : floor(x.x), x.y < 0.0 ? -floor(-x.y) : floor(x.y));
+}
+
+highp vec3 trunc(highp vec3 x) {
+ return vec3(x.x < 0.0 ? -floor(-x.x) : floor(x.x), x.y < 0.0 ? -floor(-x.y) : floor(x.y), x.z < 0.0 ? -floor(-x.z) : floor(x.z));
+}
+
+highp vec4 trunc(highp vec4 x) {
+ return vec4(x.x < 0.0 ? -floor(-x.x) : floor(x.x), x.y < 0.0 ? -floor(-x.y) : floor(x.y), x.z < 0.0 ? -floor(-x.z) : floor(x.z), x.w < 0.0 ? -floor(-x.w) : floor(x.w));
+}
+
+#endif
+
+#if defined(DETERMINANT_USED)
+
+highp float determinant(highp mat2 m) {
+ return m[0].x * m[1].y - m[1].x * m[0].y;
+}
+
+highp float determinant(highp mat3 m) {
+ return m[0].x * (m[1].y * m[2].z - m[2].y * m[1].z) - m[1].x * (m[0].y * m[2].z - m[2].y * m[0].z) + m[2].x * (m[0].y * m[1].z - m[1].y * m[0].z);
+}
+
+highp float determinant(highp mat4 m) {
+ highp float s00 = m[2].z * m[3].w - m[3].z * m[2].w;
+ highp float s01 = m[2].y * m[3].w - m[3].y * m[2].w;
+ highp float s02 = m[2].y * m[3].z - m[3].y * m[2].z;
+ highp float s03 = m[2].x * m[3].w - m[3].x * m[2].w;
+ highp float s04 = m[2].x * m[3].z - m[3].x * m[2].z;
+ highp float s05 = m[2].x * m[3].y - m[3].x * m[2].y;
+ highp vec4 c = vec4((m[1].y * s00 - m[1].z * s01 + m[1].w * s02), -(m[1].x * s00 - m[1].z * s03 + m[1].w * s04), (m[1].x * s01 - m[1].y * s03 + m[1].w * s05), -(m[1].x * s02 - m[1].y * s04 + m[1].z * s05));
+ return m[0].x * c.x + m[0].y * c.y + m[0].z * c.z + m[0].w * c.w;
+}
+
+#endif
+
+#if defined(INVERSE_USED)
+
+highp mat2 inverse(highp mat2 m) {
+ highp float d = 1.0 / (m[0].x * m[1].y - m[1].x * m[0].y);
+ return mat2(
+ vec2(m[1].y * d, -m[0].y * d),
+ vec2(-m[1].x * d, m[0].x * d));
+}
+
+highp mat3 inverse(highp mat3 m) {
+ highp float c01 = m[2].z * m[1].y - m[1].z * m[2].y;
+ highp float c11 = -m[2].z * m[1].x + m[1].z * m[2].x;
+ highp float c21 = m[2].y * m[1].x - m[1].y * m[2].x;
+ highp float d = 1.0 / (m[0].x * c01 + m[0].y * c11 + m[0].z * c21);
+
+ return mat3(c01, (-m[2].z * m[0].y + m[0].z * m[2].y), (m[1].z * m[0].y - m[0].z * m[1].y),
+ c11, (m[2].z * m[0].x - m[0].z * m[2].x), (-m[1].z * m[0].x + m[0].z * m[1].x),
+ c21, (-m[2].y * m[0].x + m[0].y * m[2].x), (m[1].y * m[0].x - m[0].y * m[1].x)) *
+ d;
+}
+
+highp mat4 inverse(highp mat4 m) {
+ highp float c00 = m[2].z * m[3].w - m[3].z * m[2].w;
+ highp float c02 = m[1].z * m[3].w - m[3].z * m[1].w;
+ highp float c03 = m[1].z * m[2].w - m[2].z * m[1].w;
+
+ highp float c04 = m[2].y * m[3].w - m[3].y * m[2].w;
+ highp float c06 = m[1].y * m[3].w - m[3].y * m[1].w;
+ highp float c07 = m[1].y * m[2].w - m[2].y * m[1].w;
+
+ highp float c08 = m[2].y * m[3].z - m[3].y * m[2].z;
+ highp float c10 = m[1].y * m[3].z - m[3].y * m[1].z;
+ highp float c11 = m[1].y * m[2].z - m[2].y * m[1].z;
+
+ highp float c12 = m[2].x * m[3].w - m[3].x * m[2].w;
+ highp float c14 = m[1].x * m[3].w - m[3].x * m[1].w;
+ highp float c15 = m[1].x * m[2].w - m[2].x * m[1].w;
+
+ highp float c16 = m[2].x * m[3].z - m[3].x * m[2].z;
+ highp float c18 = m[1].x * m[3].z - m[3].x * m[1].z;
+ highp float c19 = m[1].x * m[2].z - m[2].x * m[1].z;
+
+ highp float c20 = m[2].x * m[3].y - m[3].x * m[2].y;
+ highp float c22 = m[1].x * m[3].y - m[3].x * m[1].y;
+ highp float c23 = m[1].x * m[2].y - m[2].x * m[1].y;
+
+ vec4 f0 = vec4(c00, c00, c02, c03);
+ vec4 f1 = vec4(c04, c04, c06, c07);
+ vec4 f2 = vec4(c08, c08, c10, c11);
+ vec4 f3 = vec4(c12, c12, c14, c15);
+ vec4 f4 = vec4(c16, c16, c18, c19);
+ vec4 f5 = vec4(c20, c20, c22, c23);
+
+ vec4 v0 = vec4(m[1].x, m[0].x, m[0].x, m[0].x);
+ vec4 v1 = vec4(m[1].y, m[0].y, m[0].y, m[0].y);
+ vec4 v2 = vec4(m[1].z, m[0].z, m[0].z, m[0].z);
+ vec4 v3 = vec4(m[1].w, m[0].w, m[0].w, m[0].w);
+
+ vec4 inv0 = vec4(v1 * f0 - v2 * f1 + v3 * f2);
+ vec4 inv1 = vec4(v0 * f0 - v2 * f3 + v3 * f4);
+ vec4 inv2 = vec4(v0 * f1 - v1 * f3 + v3 * f5);
+ vec4 inv3 = vec4(v0 * f2 - v1 * f4 + v2 * f5);
+
+ vec4 sa = vec4(+1, -1, +1, -1);
+ vec4 sb = vec4(-1, +1, -1, +1);
+
+ mat4 inv = mat4(inv0 * sa, inv1 * sb, inv2 * sa, inv3 * sb);
+
+ vec4 r0 = vec4(inv[0].x, inv[1].x, inv[2].x, inv[3].x);
+ vec4 d0 = vec4(m[0] * r0);
+
+ highp float d1 = (d0.x + d0.y) + (d0.z + d0.w);
+ highp float d = 1.0 / d1;
+
+ return inv * d;
+}
+
+#endif
+
+#ifndef USE_GLES_OVER_GL
+
+#if defined(TRANSPOSE_USED)
+
+highp mat2 transpose(highp mat2 m) {
+ return mat2(
+ vec2(m[0].x, m[1].x),
+ vec2(m[0].y, m[1].y));
+}
+
+highp mat3 transpose(highp mat3 m) {
+ return mat3(
+ vec3(m[0].x, m[1].x, m[2].x),
+ vec3(m[0].y, m[1].y, m[2].y),
+ vec3(m[0].z, m[1].z, m[2].z));
+}
+
+#endif
+
+highp mat4 transpose(highp mat4 m) {
+ return mat4(
+ vec4(m[0].x, m[1].x, m[2].x, m[3].x),
+ vec4(m[0].y, m[1].y, m[2].y, m[3].y),
+ vec4(m[0].z, m[1].z, m[2].z, m[3].z),
+ vec4(m[0].w, m[1].w, m[2].w, m[3].w));
+}
+
+#if defined(OUTER_PRODUCT_USED)
+
+highp mat2 outerProduct(highp vec2 c, highp vec2 r) {
+ return mat2(c * r.x, c * r.y);
+}
+
+highp mat3 outerProduct(highp vec3 c, highp vec3 r) {
+ return mat3(c * r.x, c * r.y, c * r.z);
+}
+
+highp mat4 outerProduct(highp vec4 c, highp vec4 r) {
+ return mat4(c * r.x, c * r.y, c * r.z, c * r.w);
+}
+
+#endif
+
+#endif
+
+uniform sampler2D color_texture; // texunit:-1
+/* clang-format on */
+uniform highp vec2 color_texpixel_size;
+uniform mediump sampler2D normal_texture; // texunit:-2
+
+varying mediump vec2 uv_interp;
+varying mediump vec4 color_interp;
+
+#ifdef USE_ATTRIB_MODULATE
+varying 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
+varying vec4 light_uv_interp;
+varying vec2 transformed_light_uv;
+
+varying vec4 local_rot;
+
+#ifdef USE_SHADOWS
+
+uniform highp sampler2D shadow_texture; // texunit:-5
+varying highp vec2 pos;
+
+#endif
+
+const bool at_light_pass = true;
+#else
+const bool at_light_pass = false;
+#endif
+
+uniform bool use_default_normal;
+
+/* clang-format off */
+uniform highp vec4 m_bkg_color;
+uniform highp vec4 m_dir_color;
+uniform bool m_differences_only;
+uniform highp sampler2D m_present;
+
+float m_zero_if_equal(in vec4 m_a, in vec4 m_b)
+{
+ return smoothstep(0.0, 0.005, (length((m_a.rgb - m_b.rgb)) / sqrt(3.0)));
+}
+
+
+/* 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 */
+
+
+ /* 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 *= texture2D(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 = texture2D(normal_texture, uv).xy * 2.0 - 1.0;
+ normal.z = sqrt(max(0.0, 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
+
+ // If larger fvfs are used, final_modulate is passed as an attribute.
+ // we need to read from this in custom fragment shaders or applying in the post step,
+ // rather than using final_modulate directly.
+#if defined(final_modulate_alias)
+#undef final_modulate_alias
+#endif
+#ifdef USE_ATTRIB_MODULATE
+#define final_modulate_alias modulate_interp
+#else
+#define final_modulate_alias final_modulate
+#endif
+
+ /* clang-format off */
+{
+ vec4 m_capture_samp = texture2D(color_texture, uv);
+ vec4 m_present_samp = texture2D(m_present, uv);
+ float m_bkg_mask = m_zero_if_equal(m_capture_samp, m_bkg_color);
+ float m_diff_mask = (1.0 - m_zero_if_equal(m_present_samp, m_bkg_color));
+ m_diff_mask = min(1.0, (m_diff_mask + float(!m_differences_only)));
+ color = vec4((m_capture_samp.rgb * m_dir_color.rgb), (m_bkg_mask * m_diff_mask));
+}
+
+
+ /* 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
+ }
+
+#if !defined(MODULATE_USED)
+ color *= final_modulate_alias;
+#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 = texture2D(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(texture2D((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) (texture2D((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
+
+#ifdef LINEAR_TO_SRGB
+ // regular Linear -> SRGB conversion
+ vec3 a = vec3(0.055);
+ color.rgb = mix((vec3(1.0) + a) * pow(color.rgb, vec3(1.0 / 2.4)) - a, 12.92 * color.rgb, vec3(lessThan(color.rgb, vec3(0.0031308))));
+#endif
+
+ gl_FragColor = color;
+}
+
+[vertex shader]
+#version 120
+#define USE_GLES_OVER_GL
+#define USE_TEXTURE_RECT
+#define COLOR_USED
+
+#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 */
+
+
+vec2 select2(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;
+}
+
+vec3 select3(vec3 a, vec3 b, bvec3 c) {
+ vec3 ret;
+
+ ret.x = c.x ? b.x : a.x;
+ ret.y = c.y ? b.y : a.y;
+ ret.z = c.z ? b.z : a.z;
+
+ return ret;
+}
+
+vec4 select4(vec4 a, vec4 b, bvec4 c) {
+ vec4 ret;
+
+ ret.x = c.x ? b.x : a.x;
+ ret.y = c.y ? b.y : a.y;
+ ret.z = c.z ? b.z : a.z;
+ ret.w = c.w ? b.w : a.w;
+
+ return ret;
+}
+
+highp vec4 texel2DFetch(highp sampler2D tex, ivec2 size, ivec2 coord) {
+ float x_coord = float(2 * coord.x + 1) / float(size.x * 2);
+ float y_coord = float(2 * coord.y + 1) / float(size.y * 2);
+
+ return texture2DLod(tex, vec2(x_coord, y_coord), 0.0);
+}
+
+#if defined(SINH_USED)
+
+highp float sinh(highp float x) {
+ return 0.5 * (exp(x) - exp(-x));
+}
+
+highp vec2 sinh(highp vec2 x) {
+ return 0.5 * vec2(exp(x.x) - exp(-x.x), exp(x.y) - exp(-x.y));
+}
+
+highp vec3 sinh(highp vec3 x) {
+ return 0.5 * vec3(exp(x.x) - exp(-x.x), exp(x.y) - exp(-x.y), exp(x.z) - exp(-x.z));
+}
+
+highp vec4 sinh(highp vec4 x) {
+ return 0.5 * vec4(exp(x.x) - exp(-x.x), exp(x.y) - exp(-x.y), exp(x.z) - exp(-x.z), exp(x.w) - exp(-x.w));
+}
+
+#endif
+
+#if defined(COSH_USED)
+
+highp float cosh(highp float x) {
+ return 0.5 * (exp(x) + exp(-x));
+}
+
+highp vec2 cosh(highp vec2 x) {
+ return 0.5 * vec2(exp(x.x) + exp(-x.x), exp(x.y) + exp(-x.y));
+}
+
+highp vec3 cosh(highp vec3 x) {
+ return 0.5 * vec3(exp(x.x) + exp(-x.x), exp(x.y) + exp(-x.y), exp(x.z) + exp(-x.z));
+}
+
+highp vec4 cosh(highp vec4 x) {
+ return 0.5 * vec4(exp(x.x) + exp(-x.x), exp(x.y) + exp(-x.y), exp(x.z) + exp(-x.z), exp(x.w) + exp(-x.w));
+}
+
+#endif
+
+#if defined(TANH_USED)
+
+highp float tanh(highp float x) {
+ highp float exp2x = exp(2.0 * x);
+ return (exp2x - 1.0) / (exp2x + 1.0);
+}
+
+highp vec2 tanh(highp vec2 x) {
+ highp float exp2x = exp(2.0 * x.x);
+ highp float exp2y = exp(2.0 * x.y);
+ return vec2((exp2x - 1.0) / (exp2x + 1.0), (exp2y - 1.0) / (exp2y + 1.0));
+}
+
+highp vec3 tanh(highp vec3 x) {
+ highp float exp2x = exp(2.0 * x.x);
+ highp float exp2y = exp(2.0 * x.y);
+ highp float exp2z = exp(2.0 * x.z);
+ return vec3((exp2x - 1.0) / (exp2x + 1.0), (exp2y - 1.0) / (exp2y + 1.0), (exp2z - 1.0) / (exp2z + 1.0));
+}
+
+highp vec4 tanh(highp vec4 x) {
+ highp float exp2x = exp(2.0 * x.x);
+ highp float exp2y = exp(2.0 * x.y);
+ highp float exp2z = exp(2.0 * x.z);
+ highp float exp2w = exp(2.0 * x.w);
+ return vec4((exp2x - 1.0) / (exp2x + 1.0), (exp2y - 1.0) / (exp2y + 1.0), (exp2z - 1.0) / (exp2z + 1.0), (exp2w - 1.0) / (exp2w + 1.0));
+}
+
+#endif
+
+#if defined(ASINH_USED)
+
+highp float asinh(highp float x) {
+ return sign(x) * log(abs(x) + sqrt(1.0 + x * x));
+}
+
+highp vec2 asinh(highp vec2 x) {
+ return vec2(sign(x.x) * log(abs(x.x) + sqrt(1.0 + x.x * x.x)), sign(x.y) * log(abs(x.y) + sqrt(1.0 + x.y * x.y)));
+}
+
+highp vec3 asinh(highp vec3 x) {
+ return vec3(sign(x.x) * log(abs(x.x) + sqrt(1.0 + x.x * x.x)), sign(x.y) * log(abs(x.y) + sqrt(1.0 + x.y * x.y)), sign(x.z) * log(abs(x.z) + sqrt(1.0 + x.z * x.z)));
+}
+
+highp vec4 asinh(highp vec4 x) {
+ return vec4(sign(x.x) * log(abs(x.x) + sqrt(1.0 + x.x * x.x)), sign(x.y) * log(abs(x.y) + sqrt(1.0 + x.y * x.y)), sign(x.z) * log(abs(x.z) + sqrt(1.0 + x.z * x.z)), sign(x.w) * log(abs(x.w) + sqrt(1.0 + x.w * x.w)));
+}
+
+#endif
+
+#if defined(ACOSH_USED)
+
+highp float acosh(highp float x) {
+ return log(x + sqrt(x * x - 1.0));
+}
+
+highp vec2 acosh(highp vec2 x) {
+ return vec2(log(x.x + sqrt(x.x * x.x - 1.0)), log(x.y + sqrt(x.y * x.y - 1.0)));
+}
+
+highp vec3 acosh(highp vec3 x) {
+ return vec3(log(x.x + sqrt(x.x * x.x - 1.0)), log(x.y + sqrt(x.y * x.y - 1.0)), log(x.z + sqrt(x.z * x.z - 1.0)));
+}
+
+highp vec4 acosh(highp vec4 x) {
+ return vec4(log(x.x + sqrt(x.x * x.x - 1.0)), log(x.y + sqrt(x.y * x.y - 1.0)), log(x.z + sqrt(x.z * x.z - 1.0)), log(x.w + sqrt(x.w * x.w - 1.0)));
+}
+
+#endif
+
+#if defined(ATANH_USED)
+
+highp float atanh(highp float x) {
+ return 0.5 * log((1.0 + x) / (1.0 - x));
+}
+
+highp vec2 atanh(highp vec2 x) {
+ return 0.5 * vec2(log((1.0 + x.x) / (1.0 - x.x)), log((1.0 + x.y) / (1.0 - x.y)));
+}
+
+highp vec3 atanh(highp vec3 x) {
+ return 0.5 * vec3(log((1.0 + x.x) / (1.0 - x.x)), log((1.0 + x.y) / (1.0 - x.y)), log((1.0 + x.z) / (1.0 - x.z)));
+}
+
+highp vec4 atanh(highp vec4 x) {
+ return 0.5 * vec4(log((1.0 + x.x) / (1.0 - x.x)), log((1.0 + x.y) / (1.0 - x.y)), log((1.0 + x.z) / (1.0 - x.z)), log((1.0 + x.w) / (1.0 - x.w)));
+}
+
+#endif
+
+#if defined(ROUND_USED)
+
+highp float round(highp float x) {
+ return floor(x + 0.5);
+}
+
+highp vec2 round(highp vec2 x) {
+ return floor(x + vec2(0.5));
+}
+
+highp vec3 round(highp vec3 x) {
+ return floor(x + vec3(0.5));
+}
+
+highp vec4 round(highp vec4 x) {
+ return floor(x + vec4(0.5));
+}
+
+#endif
+
+#if defined(ROUND_EVEN_USED)
+
+highp float roundEven(highp float x) {
+ highp float t = x + 0.5;
+ highp float f = floor(t);
+ highp float r;
+ if (t == f) {
+ if (x > 0)
+ r = f - mod(f, 2);
+ else
+ r = f + mod(f, 2);
+ } else
+ r = f;
+ return r;
+}
+
+highp vec2 roundEven(highp vec2 x) {
+ return vec2(roundEven(x.x), roundEven(x.y));
+}
+
+highp vec3 roundEven(highp vec3 x) {
+ return vec3(roundEven(x.x), roundEven(x.y), roundEven(x.z));
+}
+
+highp vec4 roundEven(highp vec4 x) {
+ return vec4(roundEven(x.x), roundEven(x.y), roundEven(x.z), roundEven(x.w));
+}
+
+#endif
+
+#if defined(IS_INF_USED)
+
+bool isinf(highp float x) {
+ return (2 * x == x) && (x != 0);
+}
+
+bvec2 isinf(highp vec2 x) {
+ return bvec2((2 * x.x == x.x) && (x.x != 0), (2 * x.y == x.y) && (x.y != 0));
+}
+
+bvec3 isinf(highp vec3 x) {
+ return bvec3((2 * x.x == x.x) && (x.x != 0), (2 * x.y == x.y) && (x.y != 0), (2 * x.z == x.z) && (x.z != 0));
+}
+
+bvec4 isinf(highp vec4 x) {
+ return bvec4((2 * x.x == x.x) && (x.x != 0), (2 * x.y == x.y) && (x.y != 0), (2 * x.z == x.z) && (x.z != 0), (2 * x.w == x.w) && (x.w != 0));
+}
+
+#endif
+
+#if defined(IS_NAN_USED)
+
+bool isnan(highp float x) {
+ return x != x;
+}
+
+bvec2 isnan(highp vec2 x) {
+ return bvec2(x.x != x.x, x.y != x.y);
+}
+
+bvec3 isnan(highp vec3 x) {
+ return bvec3(x.x != x.x, x.y != x.y, x.z != x.z);
+}
+
+bvec4 isnan(highp vec4 x) {
+ return bvec4(x.x != x.x, x.y != x.y, x.z != x.z, x.w != x.w);
+}
+
+#endif
+
+#if defined(TRUNC_USED)
+
+highp float trunc(highp float x) {
+ return x < 0.0 ? -floor(-x) : floor(x);
+}
+
+highp vec2 trunc(highp vec2 x) {
+ return vec2(x.x < 0.0 ? -floor(-x.x) : floor(x.x), x.y < 0.0 ? -floor(-x.y) : floor(x.y));
+}
+
+highp vec3 trunc(highp vec3 x) {
+ return vec3(x.x < 0.0 ? -floor(-x.x) : floor(x.x), x.y < 0.0 ? -floor(-x.y) : floor(x.y), x.z < 0.0 ? -floor(-x.z) : floor(x.z));
+}
+
+highp vec4 trunc(highp vec4 x) {
+ return vec4(x.x < 0.0 ? -floor(-x.x) : floor(x.x), x.y < 0.0 ? -floor(-x.y) : floor(x.y), x.z < 0.0 ? -floor(-x.z) : floor(x.z), x.w < 0.0 ? -floor(-x.w) : floor(x.w));
+}
+
+#endif
+
+#if defined(DETERMINANT_USED)
+
+highp float determinant(highp mat2 m) {
+ return m[0].x * m[1].y - m[1].x * m[0].y;
+}
+
+highp float determinant(highp mat3 m) {
+ return m[0].x * (m[1].y * m[2].z - m[2].y * m[1].z) - m[1].x * (m[0].y * m[2].z - m[2].y * m[0].z) + m[2].x * (m[0].y * m[1].z - m[1].y * m[0].z);
+}
+
+highp float determinant(highp mat4 m) {
+ highp float s00 = m[2].z * m[3].w - m[3].z * m[2].w;
+ highp float s01 = m[2].y * m[3].w - m[3].y * m[2].w;
+ highp float s02 = m[2].y * m[3].z - m[3].y * m[2].z;
+ highp float s03 = m[2].x * m[3].w - m[3].x * m[2].w;
+ highp float s04 = m[2].x * m[3].z - m[3].x * m[2].z;
+ highp float s05 = m[2].x * m[3].y - m[3].x * m[2].y;
+ highp vec4 c = vec4((m[1].y * s00 - m[1].z * s01 + m[1].w * s02), -(m[1].x * s00 - m[1].z * s03 + m[1].w * s04), (m[1].x * s01 - m[1].y * s03 + m[1].w * s05), -(m[1].x * s02 - m[1].y * s04 + m[1].z * s05));
+ return m[0].x * c.x + m[0].y * c.y + m[0].z * c.z + m[0].w * c.w;
+}
+
+#endif
+
+#if defined(INVERSE_USED)
+
+highp mat2 inverse(highp mat2 m) {
+ highp float d = 1.0 / (m[0].x * m[1].y - m[1].x * m[0].y);
+ return mat2(
+ vec2(m[1].y * d, -m[0].y * d),
+ vec2(-m[1].x * d, m[0].x * d));
+}
+
+highp mat3 inverse(highp mat3 m) {
+ highp float c01 = m[2].z * m[1].y - m[1].z * m[2].y;
+ highp float c11 = -m[2].z * m[1].x + m[1].z * m[2].x;
+ highp float c21 = m[2].y * m[1].x - m[1].y * m[2].x;
+ highp float d = 1.0 / (m[0].x * c01 + m[0].y * c11 + m[0].z * c21);
+
+ return mat3(c01, (-m[2].z * m[0].y + m[0].z * m[2].y), (m[1].z * m[0].y - m[0].z * m[1].y),
+ c11, (m[2].z * m[0].x - m[0].z * m[2].x), (-m[1].z * m[0].x + m[0].z * m[1].x),
+ c21, (-m[2].y * m[0].x + m[0].y * m[2].x), (m[1].y * m[0].x - m[0].y * m[1].x)) *
+ d;
+}
+
+highp mat4 inverse(highp mat4 m) {
+ highp float c00 = m[2].z * m[3].w - m[3].z * m[2].w;
+ highp float c02 = m[1].z * m[3].w - m[3].z * m[1].w;
+ highp float c03 = m[1].z * m[2].w - m[2].z * m[1].w;
+
+ highp float c04 = m[2].y * m[3].w - m[3].y * m[2].w;
+ highp float c06 = m[1].y * m[3].w - m[3].y * m[1].w;
+ highp float c07 = m[1].y * m[2].w - m[2].y * m[1].w;
+
+ highp float c08 = m[2].y * m[3].z - m[3].y * m[2].z;
+ highp float c10 = m[1].y * m[3].z - m[3].y * m[1].z;
+ highp float c11 = m[1].y * m[2].z - m[2].y * m[1].z;
+
+ highp float c12 = m[2].x * m[3].w - m[3].x * m[2].w;
+ highp float c14 = m[1].x * m[3].w - m[3].x * m[1].w;
+ highp float c15 = m[1].x * m[2].w - m[2].x * m[1].w;
+
+ highp float c16 = m[2].x * m[3].z - m[3].x * m[2].z;
+ highp float c18 = m[1].x * m[3].z - m[3].x * m[1].z;
+ highp float c19 = m[1].x * m[2].z - m[2].x * m[1].z;
+
+ highp float c20 = m[2].x * m[3].y - m[3].x * m[2].y;
+ highp float c22 = m[1].x * m[3].y - m[3].x * m[1].y;
+ highp float c23 = m[1].x * m[2].y - m[2].x * m[1].y;
+
+ vec4 f0 = vec4(c00, c00, c02, c03);
+ vec4 f1 = vec4(c04, c04, c06, c07);
+ vec4 f2 = vec4(c08, c08, c10, c11);
+ vec4 f3 = vec4(c12, c12, c14, c15);
+ vec4 f4 = vec4(c16, c16, c18, c19);
+ vec4 f5 = vec4(c20, c20, c22, c23);
+
+ vec4 v0 = vec4(m[1].x, m[0].x, m[0].x, m[0].x);
+ vec4 v1 = vec4(m[1].y, m[0].y, m[0].y, m[0].y);
+ vec4 v2 = vec4(m[1].z, m[0].z, m[0].z, m[0].z);
+ vec4 v3 = vec4(m[1].w, m[0].w, m[0].w, m[0].w);
+
+ vec4 inv0 = vec4(v1 * f0 - v2 * f1 + v3 * f2);
+ vec4 inv1 = vec4(v0 * f0 - v2 * f3 + v3 * f4);
+ vec4 inv2 = vec4(v0 * f1 - v1 * f3 + v3 * f5);
+ vec4 inv3 = vec4(v0 * f2 - v1 * f4 + v2 * f5);
+
+ vec4 sa = vec4(+1, -1, +1, -1);
+ vec4 sb = vec4(-1, +1, -1, +1);
+
+ mat4 inv = mat4(inv0 * sa, inv1 * sb, inv2 * sa, inv3 * sb);
+
+ vec4 r0 = vec4(inv[0].x, inv[1].x, inv[2].x, inv[3].x);
+ vec4 d0 = vec4(m[0] * r0);
+
+ highp float d1 = (d0.x + d0.y) + (d0.z + d0.w);
+ highp float d = 1.0 / d1;
+
+ return inv * d;
+}
+
+#endif
+
+#ifndef USE_GLES_OVER_GL
+
+#if defined(TRANSPOSE_USED)
+
+highp mat2 transpose(highp mat2 m) {
+ return mat2(
+ vec2(m[0].x, m[1].x),
+ vec2(m[0].y, m[1].y));
+}
+
+highp mat3 transpose(highp mat3 m) {
+ return mat3(
+ vec3(m[0].x, m[1].x, m[2].x),
+ vec3(m[0].y, m[1].y, m[2].y),
+ vec3(m[0].z, m[1].z, m[2].z));
+}
+
+#endif
+
+highp mat4 transpose(highp mat4 m) {
+ return mat4(
+ vec4(m[0].x, m[1].x, m[2].x, m[3].x),
+ vec4(m[0].y, m[1].y, m[2].y, m[3].y),
+ vec4(m[0].z, m[1].z, m[2].z, m[3].z),
+ vec4(m[0].w, m[1].w, m[2].w, m[3].w));
+}
+
+#if defined(OUTER_PRODUCT_USED)
+
+highp mat2 outerProduct(highp vec2 c, highp vec2 r) {
+ return mat2(c * r.x, c * r.y);
+}
+
+highp mat3 outerProduct(highp vec3 c, highp vec3 r) {
+ return mat3(c * r.x, c * r.y, c * r.z);
+}
+
+highp mat4 outerProduct(highp vec4 c, highp vec4 r) {
+ return mat4(c * r.x, c * r.y, c * r.z, c * r.w);
+}
+
+#endif
+
+#endif
+
+uniform highp mat4 modelview_matrix;
+uniform highp mat4 extra_matrix;
+attribute highp vec2 vertex; // attrib:0
+
+#ifdef USE_ATTRIB_LIGHT_ANGLE
+// shared with tangent, not used in canvas shader
+attribute highp float light_angle; // attrib:2
+#endif
+
+attribute vec4 color_attrib; // attrib:3
+attribute vec2 uv_attrib; // attrib:4
+
+#ifdef USE_ATTRIB_MODULATE
+attribute highp vec4 modulate_attrib; // attrib:5
+#endif
+
+// Usually, final_modulate is passed as a uniform. However during batching
+// If larger fvfs are used, final_modulate is passed as an attribute.
+// we need to read from the attribute in custom vertex shader
+// rather than the uniform. We do this by specifying final_modulate_alias
+// in shaders rather than final_modulate directly.
+#ifdef USE_ATTRIB_MODULATE
+#define final_modulate_alias modulate_attrib
+#else
+#define final_modulate_alias final_modulate
+#endif
+
+#ifdef USE_ATTRIB_LARGE_VERTEX
+// shared with skeleton attributes, not used in batched shader
+attribute highp vec2 translate_attrib; // attrib:6
+attribute highp vec4 basis_attrib; // attrib:7
+#endif
+
+#ifdef USE_SKELETON
+attribute highp vec4 bone_indices; // attrib:6
+attribute highp vec4 bone_weights; // attrib:7
+#endif
+
+#ifdef USE_INSTANCING
+
+attribute highp vec4 instance_xform0; //attrib:8
+attribute highp vec4 instance_xform1; //attrib:9
+attribute highp vec4 instance_xform2; //attrib:10
+attribute highp vec4 instance_color; //attrib:11
+
+#ifdef USE_INSTANCE_CUSTOM
+attribute highp vec4 instance_custom_data; //attrib:12
+#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
+
+varying vec2 uv_interp;
+varying vec4 color_interp;
+
+#ifdef USE_ATTRIB_MODULATE
+// modulate doesn't need interpolating but we need to send it to the fragment shader
+varying 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;
+
+varying vec4 light_uv_interp;
+varying vec2 transformed_light_uv;
+varying vec4 local_rot;
+
+#ifdef USE_SHADOWS
+varying highp vec2 pos;
+#endif
+
+const bool at_light_pass = true;
+#else
+const bool at_light_pass = false;
+#endif
+
+/* clang-format off */
+uniform highp vec4 m_bkg_color;
+uniform highp vec4 m_dir_color;
+uniform bool m_differences_only;
+uniform highp sampler2D m_present;
+
+
+/* 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 */
+
+
+ /* 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 */
+