diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2023-01-17 10:56:44 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2023-01-17 10:56:44 +0100 |
commit | 59dcf64dd6b8f5da570a551be7a317453e427098 (patch) | |
tree | c430a37e013fe14fa207409847c5402f18ff46fd /drivers/gles3 | |
parent | 63dfdf4f89280ed993318059e7b521ea9432b531 (diff) | |
parent | 390f83bf5a1751ec2dc7892f6830285c2373985f (diff) |
Merge pull request #71382 from jainl28patel/sprite2d_flip_normal_map
fix normal map not flipping in sprite2D
Diffstat (limited to 'drivers/gles3')
-rw-r--r-- | drivers/gles3/rasterizer_canvas_gles3.cpp | 2 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_canvas_gles3.h | 3 | ||||
-rw-r--r-- | drivers/gles3/shaders/canvas.glsl | 6 | ||||
-rw-r--r-- | drivers/gles3/shaders/canvas_uniforms_inc.glsl | 3 |
4 files changed, 14 insertions, 0 deletions
diff --git a/drivers/gles3/rasterizer_canvas_gles3.cpp b/drivers/gles3/rasterizer_canvas_gles3.cpp index 2887b6b44f..a946a2ceb5 100644 --- a/drivers/gles3/rasterizer_canvas_gles3.cpp +++ b/drivers/gles3/rasterizer_canvas_gles3.cpp @@ -905,10 +905,12 @@ void RasterizerCanvasGLES3::_record_item_commands(const Item *p_item, RID p_rend if (rect->flags & CANVAS_RECT_FLIP_H) { src_rect.size.x *= -1; + state.instance_data_array[r_index].flags |= FLAGS_FLIP_H; } if (rect->flags & CANVAS_RECT_FLIP_V) { src_rect.size.y *= -1; + state.instance_data_array[r_index].flags |= FLAGS_FLIP_V; } if (rect->flags & CANVAS_RECT_TRANSPOSE) { diff --git a/drivers/gles3/rasterizer_canvas_gles3.h b/drivers/gles3/rasterizer_canvas_gles3.h index db9203b249..916e12057c 100644 --- a/drivers/gles3/rasterizer_canvas_gles3.h +++ b/drivers/gles3/rasterizer_canvas_gles3.h @@ -75,6 +75,9 @@ class RasterizerCanvasGLES3 : public RendererCanvasRender { FLAGS_USE_MSDF = (1 << 28), FLAGS_USE_LCD = (1 << 29), + + FLAGS_FLIP_H = (1 << 30), + FLAGS_FLIP_V = (1 << 31), }; enum { diff --git a/drivers/gles3/shaders/canvas.glsl b/drivers/gles3/shaders/canvas.glsl index 9a90f33674..3d3d328146 100644 --- a/drivers/gles3/shaders/canvas.glsl +++ b/drivers/gles3/shaders/canvas.glsl @@ -579,6 +579,12 @@ void main() { if (normal_used || (using_light && bool(read_draw_data_flags & FLAGS_DEFAULT_NORMAL_MAP_USED))) { normal.xy = texture(normal_texture, uv).xy * vec2(2.0, -2.0) - vec2(1.0, -1.0); + if (bool(draw_data.flags & FLAGS_FLIP_H)) { + normal.x = -normal.x; + } + if (bool(draw_data.flags & FLAGS_FLIP_V)) { + normal.y = -normal.y; + } normal.z = sqrt(1.0 - dot(normal.xy, normal.xy)); normal_used = true; } else { diff --git a/drivers/gles3/shaders/canvas_uniforms_inc.glsl b/drivers/gles3/shaders/canvas_uniforms_inc.glsl index f65558f042..d53c0fcb26 100644 --- a/drivers/gles3/shaders/canvas_uniforms_inc.glsl +++ b/drivers/gles3/shaders/canvas_uniforms_inc.glsl @@ -27,6 +27,9 @@ #define FLAGS_USE_MSDF uint(1 << 28) #define FLAGS_USE_LCD uint(1 << 29) +#define FLAGS_FLIP_H uint(1 << 30) +#define FLAGS_FLIP_V uint(1 << 31) + layout(std140) uniform GlobalShaderUniformData { //ubo:1 vec4 global_shader_uniforms[MAX_GLOBAL_SHADER_UNIFORMS]; }; |