Merge pull request #71382 from jainl28patel/sprite2d_flip_normal_map

fix normal map not flipping in sprite2D
This commit is contained in:
Rémi Verschelde 2023-01-17 10:56:44 +01:00
commit 59dcf64dd6
No known key found for this signature in database
GPG Key ID: C3336907360768E1
8 changed files with 28 additions and 0 deletions

View File

@ -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) {

View File

@ -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 {

View File

@ -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 {

View File

@ -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];
};

View File

@ -525,10 +525,12 @@ void RendererCanvasRenderRD::_render_item(RD::DrawListID p_draw_list, RID p_rend
if (rect->flags & CANVAS_RECT_FLIP_H) {
src_rect.size.x *= -1;
push_constant.flags |= FLAGS_FLIP_H;
}
if (rect->flags & CANVAS_RECT_FLIP_V) {
src_rect.size.y *= -1;
push_constant.flags |= FLAGS_FLIP_V;
}
if (rect->flags & CANVAS_RECT_TRANSPOSE) {

View File

@ -86,6 +86,9 @@ class RendererCanvasRenderRD : public RendererCanvasRender {
FLAGS_USE_MSDF = (1 << 28),
FLAGS_USE_LCD = (1 << 29),
FLAGS_FLIP_H = (1 << 30),
FLAGS_FLIP_V = (1 << 31),
};
enum {

View File

@ -502,6 +502,12 @@ void main() {
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 (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 {

View File

@ -27,6 +27,9 @@
#define FLAGS_USE_MSDF (1 << 28)
#define FLAGS_USE_LCD (1 << 29)
#define FLAGS_FLIP_H (1 << 30)
#define FLAGS_FLIP_V (1 << 31)
#define SAMPLER_NEAREST_CLAMP 0
#define SAMPLER_LINEAR_CLAMP 1
#define SAMPLER_NEAREST_WITH_MIPMAPS_CLAMP 2