diff options
author | JFonS <joan.fonssanchez@gmail.com> | 2018-06-21 00:12:12 +0200 |
---|---|---|
committer | JFonS <joan.fonssanchez@gmail.com> | 2018-06-21 00:12:12 +0200 |
commit | c8cf71753c4f971c25924addbfe79356e7d2ec4e (patch) | |
tree | 0821b1e63b33543b8740b980eb4036c7ec75159e /drivers/gles3 | |
parent | 0a1c1c660fc6aa0689816e85f2b6791c225c6d63 (diff) |
Add render mode to ensure correct normals when using non-uniform scaling
Diffstat (limited to 'drivers/gles3')
-rw-r--r-- | drivers/gles3/shader_compiler_gles3.cpp | 1 | ||||
-rw-r--r-- | drivers/gles3/shaders/scene.glsl | 12 |
2 files changed, 13 insertions, 0 deletions
diff --git a/drivers/gles3/shader_compiler_gles3.cpp b/drivers/gles3/shader_compiler_gles3.cpp index eb8d6c485b..9ad16ac2a2 100644 --- a/drivers/gles3/shader_compiler_gles3.cpp +++ b/drivers/gles3/shader_compiler_gles3.cpp @@ -898,6 +898,7 @@ ShaderCompilerGLES3::ShaderCompilerGLES3() { actions[VS::SHADER_SPATIAL].render_mode_defines["skip_vertex_transform"] = "#define SKIP_TRANSFORM_USED\n"; actions[VS::SHADER_SPATIAL].render_mode_defines["world_vertex_coords"] = "#define VERTEX_WORLD_COORDS_USED\n"; + actions[VS::SHADER_SPATIAL].render_mode_defines["ensure_correct_normals"] = "#define ENSURE_CORRECT_NORMALS\n"; actions[VS::SHADER_SPATIAL].render_mode_defines["cull_front"] = "#define DO_SIDE_CHECK\n"; actions[VS::SHADER_SPATIAL].render_mode_defines["cull_disabled"] = "#define DO_SIDE_CHECK\n"; diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl index f5481c597c..132e988a5a 100644 --- a/drivers/gles3/shaders/scene.glsl +++ b/drivers/gles3/shaders/scene.glsl @@ -322,7 +322,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) @@ -394,7 +400,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) |