diff options
author | Juan Linietsky <reduzio@gmail.com> | 2017-06-18 22:55:02 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2017-06-18 22:55:02 -0300 |
commit | 0288be1e7698c984b159bbb7816ddc7aca43b2f1 (patch) | |
tree | 4adea769e6d921e9c79cdff654c80ddac855fe2b /drivers/gles3/shaders | |
parent | 969fa3cc73e3523fe066357b4f45ca0b52353fea (diff) |
Texture rect_region drawing now clamps UV to avoid bleeding. This avoids scenarios like single-texture tilemap tiles leaking pixels to the next tile when filter is enabled on it.
Diffstat (limited to 'drivers/gles3/shaders')
-rw-r--r-- | drivers/gles3/shaders/canvas.glsl | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/drivers/gles3/shaders/canvas.glsl b/drivers/gles3/shaders/canvas.glsl index b0ce38cb68..7be6ee857a 100644 --- a/drivers/gles3/shaders/canvas.glsl +++ b/drivers/gles3/shaders/canvas.glsl @@ -6,8 +6,8 @@ layout(location=3) in vec4 color_attrib; #ifdef USE_TEXTURE_RECT -layout(location=1) in highp vec4 dst_rect; -layout(location=2) in highp vec4 src_rect; +uniform vec4 dst_rect; +uniform vec4 src_rect; #else @@ -65,6 +65,7 @@ const bool at_light_pass = false; #endif + VERTEX_SHADER_GLOBALS #if defined(USE_MATERIAL) @@ -228,22 +229,39 @@ LIGHT_SHADER_CODE } +#ifdef USE_TEXTURE_RECT + +uniform vec4 dst_rect; +uniform vec4 src_rect; +uniform bool clip_rect_uv; + +#endif + uniform bool use_default_normal; void main() { vec4 color = color_interp; + vec2 uv = uv_interp; +#ifdef USE_TEXTURE_RECT + if (clip_rect_uv) { + + vec2 half_texpixel = color_texpixel_size * 0.5; + uv = clamp(uv,src_rect.xy+half_texpixel,src_rect.xy+abs(src_rect.zw)-color_texpixel_size); + } + +#endif #if !defined(COLOR_USED) //default behavior, texture by color #ifdef USE_DISTANCE_FIELD const float smoothing = 1.0/32.0; - float distance = textureLod(color_texture, uv_interp,0.0).a; + float distance = textureLod(color_texture, uv,0.0).a; color.a = smoothstep(0.5 - smoothing, 0.5 + smoothing, distance) * color.a; #else - color *= texture( color_texture, uv_interp ); + color *= texture( color_texture, uv ); #endif @@ -259,7 +277,7 @@ void main() { #endif if (use_default_normal) { - normal.xy = textureLod(normal_texture, uv_interp,0.0).xy * 2.0 - 1.0; + normal.xy = textureLod(normal_texture, uv,0.0).xy * 2.0 - 1.0; normal.z = sqrt(1.0-dot(normal.xy,normal.xy)); normal_used=true; } else { |