summaryrefslogtreecommitdiffstats
path: root/drivers/gles3/shaders
diff options
context:
space:
mode:
authorBlueCube3310 <53150244+BlueCube3310@users.noreply.github.com>2023-10-04 19:18:40 +0200
committerBlueCube3310 <53150244+BlueCube3310@users.noreply.github.com>2023-10-22 15:00:11 +0200
commitf31371c04e6cbce08ef2d99d7b868ac9aad6c1a1 (patch)
treebe211373687754476b911cf91381f7d896842da1 /drivers/gles3/shaders
parentf71f4b80e32f6e98a4cd3cb1c06071223297e8fc (diff)
downloadredot-engine-f31371c04e6cbce08ef2d99d7b868ac9aad6c1a1.tar.gz
Automatically ensure correct normals in Compatibility renderer
Diffstat (limited to 'drivers/gles3/shaders')
-rw-r--r--drivers/gles3/shaders/scene.glsl13
1 files changed, 12 insertions, 1 deletions
diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl
index e0f8e83373..f61ec93c6f 100644
--- a/drivers/gles3/shaders/scene.glsl
+++ b/drivers/gles3/shaders/scene.glsl
@@ -139,6 +139,8 @@ layout(location = 14) in highp vec4 instance_xform2;
layout(location = 15) in highp uvec4 instance_color_custom_data; // Color packed into xy, Custom data into zw.
#endif
+#define FLAGS_NON_UNIFORM_SCALE (1 << 4)
+
layout(std140) uniform GlobalShaderUniformData { //ubo:1
vec4 global_shader_uniforms[MAX_GLOBAL_SHADER_UNIFORMS];
};
@@ -242,6 +244,8 @@ uniform highp vec3 compressed_aabb_position;
uniform highp vec3 compressed_aabb_size;
uniform highp vec4 uv_scale;
+uniform highp uint model_flags;
+
/* Varyings */
out highp vec3 vertex_interp;
@@ -310,7 +314,14 @@ void main() {
#ifdef NORMAL_USED
vec3 normal = oct_to_vec3(axis_tangent_attrib.xy * 2.0 - 1.0);
#endif
- highp mat3 model_normal_matrix = mat3(model_matrix);
+
+ highp mat3 model_normal_matrix;
+
+ if (bool(model_flags & uint(FLAGS_NON_UNIFORM_SCALE))) {
+ model_normal_matrix = transpose(inverse(mat3(model_matrix)));
+ } else {
+ model_normal_matrix = mat3(model_matrix);
+ }
#if defined(NORMAL_USED) || defined(TANGENT_USED) || defined(NORMAL_MAP_USED) || defined(LIGHT_ANISOTROPY_USED)