diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2018-07-04 15:09:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-04 15:09:59 +0200 |
commit | 92bfde531cea21555dc74ad928a79120fbc9c34d (patch) | |
tree | e0ce4fbb126641eeff7dbba7a448dea5881213f4 /drivers/gles3/shaders/scene.glsl | |
parent | db546732cf5f7b367b88c9008c74f18602167230 (diff) | |
parent | c8cf71753c4f971c25924addbfe79356e7d2ec4e (diff) |
Merge pull request #19786 from JFonS/correct_normal_scaling
Add render mode to ensure correct normals when using non-uniform scaling
Diffstat (limited to 'drivers/gles3/shaders/scene.glsl')
-rw-r--r-- | drivers/gles3/shaders/scene.glsl | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl index 0e111e59a9..ed8df04377 100644 --- a/drivers/gles3/shaders/scene.glsl +++ b/drivers/gles3/shaders/scene.glsl @@ -323,7 +323,13 @@ void main() { #if !defined(SKIP_TRANSFORM_USED) && defined(VERTEX_WORLD_COORDS_USED) vertex = world_matrix * vertex; + +#if defined(ENSURE_CORRECT_NORMALS) + mat3 normal_matrix = mat3(transpose(inverse(world_matrix))); + normal = normal_matrix * normal; +#else normal = normalize((world_matrix * vec4(normal,0.0)).xyz); +#endif #if defined(ENABLE_TANGENT_INTERP) || defined(ENABLE_NORMALMAP) || defined(LIGHT_USE_ANISOTROPY) @@ -395,7 +401,13 @@ VERTEX_SHADER_CODE #if !defined(SKIP_TRANSFORM_USED) && !defined(VERTEX_WORLD_COORDS_USED) vertex = modelview * vertex; + +#if defined(ENSURE_CORRECT_NORMALS) + mat3 normal_matrix = mat3(transpose(inverse(modelview))); + normal = normal_matrix * normal; +#else normal = normalize((modelview * vec4(normal,0.0)).xyz); +#endif #if defined(ENABLE_TANGENT_INTERP) || defined(ENABLE_NORMALMAP) || defined(LIGHT_USE_ANISOTROPY) |