summaryrefslogtreecommitdiff
path: root/drivers/gles2/shaders/canvas.glsl
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gles2/shaders/canvas.glsl')
-rw-r--r--drivers/gles2/shaders/canvas.glsl62
1 files changed, 48 insertions, 14 deletions
diff --git a/drivers/gles2/shaders/canvas.glsl b/drivers/gles2/shaders/canvas.glsl
index c4a8c8b990..7dce784f52 100644
--- a/drivers/gles2/shaders/canvas.glsl
+++ b/drivers/gles2/shaders/canvas.glsl
@@ -107,6 +107,7 @@ vec2 select(vec2 a, vec2 b, bvec2 c) {
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)));
@@ -121,9 +122,9 @@ void main() {
#ifdef USE_TEXTURE_RECT
if (dst_rect.z < 0.0) { // Transpose is encoded as negative dst_rect.z
- uv_interp = src_rect.xy + abs(src_rect.zw) * vertex.yx;
+ uv = src_rect.xy + abs(src_rect.zw) * vertex.yx;
} else {
- uv_interp = src_rect.xy + abs(src_rect.zw) * vertex;
+ uv = src_rect.xy + abs(src_rect.zw) * vertex;
}
vec4 outvec = vec4(0.0, 0.0, 0.0, 1.0);
@@ -140,7 +141,7 @@ void main() {
#else
vec4 outvec = vec4(vertex.xy, 0.0, 1.0);
- uv_interp = uv_attrib;
+ uv = uv_attrib;
#endif
{
@@ -161,6 +162,9 @@ VERTEX_SHADER_CODE
#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
@@ -189,6 +193,7 @@ VERTEX_SHADER_CODE
#endif
+ uv_interp = uv;
gl_Position = projection_matrix * outvec;
#ifdef USE_LIGHTING
@@ -215,29 +220,25 @@ VERTEX_SHADER_CODE
/* clang-format off */
[fragment]
+// 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
+#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
@@ -316,13 +317,43 @@ 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,
+ 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 *= texture2D(color_texture, uv_interp);
+ color *= texture2D(color_texture, uv);
#endif
#ifdef SCREEN_UV_USED
@@ -339,7 +370,7 @@ void main() {
#endif
if (use_default_normal) {
- normal.xy = texture2D(normal_texture, uv_interp).xy * 2.0 - 1.0;
+ normal.xy = texture2D(normal_texture, uv).xy * 2.0 - 1.0;
normal.z = sqrt(1.0 - dot(normal.xy, normal.xy));
normal_used = true;
} else {
@@ -414,7 +445,10 @@ FRAGMENT_SHADER_CODE
color *= light;
#ifdef USE_SHADOWS
- light_vec = light_uv_interp.zw; //for shadows
+ // Reset light_vec to compute shadows, the shadow map is created from the light origin, so it only
+ // makes sense to compute shadows from there.
+ light_vec = light_uv_interp.zw;
+
float angle_to_light = -atan(light_vec.x, light_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
@@ -451,7 +485,7 @@ FRAGMENT_SHADER_CODE
#ifdef USE_RGBA_SHADOWS
-#define SHADOW_DEPTH(m_tex, m_uv) dot(texture2D((m_tex), (m_uv)), vec4(1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1))
+#define SHADOW_DEPTH(m_tex, m_uv) dot(texture2D((m_tex), (m_uv)), vec4(1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0))
#else