DRW: Remove WorldNormalMatrix
authorClément Foucault <foucault.clem@gmail.com>
Wed, 8 May 2019 18:13:24 +0000 (20:13 +0200)
committerClément Foucault <foucault.clem@gmail.com>
Wed, 8 May 2019 18:13:32 +0000 (20:13 +0200)
source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl
source/blender/draw/engines/eevee/shaders/shadow_vert.glsl
source/blender/draw/intern/draw_manager.h
source/blender/draw/intern/draw_manager_data.c
source/blender/draw/intern/draw_manager_exec.c
source/blender/draw/modes/shaders/common_view_lib.glsl
source/blender/gpu/GPU_shader_interface.h
source/blender/gpu/intern/gpu_shader_interface.c
source/blender/gpu/shaders/gpu_shader_material.glsl

index 40075ed..cddc8e8 100644 (file)
@@ -1,10 +1,8 @@
 
 uniform mat4 ModelViewProjectionMatrix;
 uniform mat4 ModelViewMatrix;
-uniform mat3 WorldNormalMatrix;
 #ifndef USE_ATTR
 uniform mat4 ModelMatrix;
-uniform mat3 NormalMatrix;
 uniform mat4 ModelMatrixInverse;
 #endif
 
@@ -67,8 +65,10 @@ void main()
   gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
   viewPosition = (ModelViewMatrix * vec4(pos, 1.0)).xyz;
   worldPosition = (ModelMatrix * vec4(pos, 1.0)).xyz;
-  worldNormal = normalize(WorldNormalMatrix * nor);
-  viewNormal = normalize(NormalMatrix * nor);
+
+  worldNormal = normalize(transform_normal_object_to_world(nor));
+  /* No need to normalize since this is just a rotation. */
+  viewNormal = transform_normal_world_to_view(worldNormal);
 #endif
 
   /* Used for planar reflections */
index f9225cd..f885030 100644 (file)
@@ -2,10 +2,8 @@
 uniform mat4 ModelViewProjectionMatrix;
 #ifdef MESH_SHADER
 uniform mat4 ModelViewMatrix;
-uniform mat3 WorldNormalMatrix;
 #  ifndef USE_ATTR
 uniform mat4 ModelMatrix;
-uniform mat3 NormalMatrix;
 #  endif
 #endif
 
@@ -25,8 +23,10 @@ void main()
 #ifdef MESH_SHADER
   viewPosition = (ModelViewMatrix * vec4(pos, 1.0)).xyz;
   worldPosition = (ModelMatrix * vec4(pos, 1.0)).xyz;
-  viewNormal = normalize(NormalMatrix * nor);
-  worldNormal = normalize(WorldNormalMatrix * nor);
+
+  worldNormal = normalize(transform_normal_object_to_world(nor));
+  /* No need to normalize since this is just a rotation. */
+  viewNormal = transform_normal_world_to_view(worldNormal);
 #  ifdef USE_ATTR
   pass_attr(pos);
 #  endif
index 4d74a95..496e5b7 100644 (file)
@@ -104,7 +104,6 @@ enum {
   DRW_CALL_MODELVIEWINVERSE = (1 << 2),
   DRW_CALL_MODELVIEWPROJECTION = (1 << 3),
   DRW_CALL_NORMALVIEW = (1 << 4),
-  DRW_CALL_NORMALWORLD = (1 << 6),
   DRW_CALL_ORCOTEXFAC = (1 << 7),
   DRW_CALL_OBJECTINFO = (1 << 8),
 };
@@ -126,8 +125,7 @@ typedef struct DRWCallState {
   float modelviewinverse[4][4];
   float modelviewprojection[4][4];
   float normalview[3][3];
-  float normalworld[3][3]; /* Not view dependent */
-  float orcotexfac[2][3];  /* Not view dependent */
+  float orcotexfac[2][3]; /* Not view dependent */
   float objectinfo[2];
 } DRWCallState;
 
@@ -258,7 +256,6 @@ struct DRWShadingGroup {
   int modelviewinverse;
   int modelviewprojection;
   int normalview;
-  int normalworld;
   int orcotexfac;
   int callid;
   int objectinfo;
index b722527..deabffd 100644 (file)
@@ -838,7 +838,6 @@ static void drw_shgroup_init(DRWShadingGroup *shgroup, GPUShader *shader)
   shgroup->modelviewinverse = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_MODELVIEW_INV);
   shgroup->modelviewprojection = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_MVP);
   shgroup->normalview = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_NORMAL);
-  shgroup->normalworld = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_WORLDNORMAL);
   shgroup->orcotexfac = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_ORCO);
   shgroup->objectinfo = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_OBJECT_INFO);
   shgroup->callid = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_CALLID);
@@ -859,9 +858,6 @@ static void drw_shgroup_init(DRWShadingGroup *shgroup, GPUShader *shader)
   if (shgroup->normalview > -1) {
     shgroup->matflag |= DRW_CALL_NORMALVIEW;
   }
-  if (shgroup->normalworld > -1) {
-    shgroup->matflag |= DRW_CALL_NORMALWORLD;
-  }
   if (shgroup->orcotexfac > -1) {
     shgroup->matflag |= DRW_CALL_ORCOTEXFAC;
   }
index f98c2cb..51ec380 100644 (file)
@@ -806,13 +806,6 @@ static void draw_matrices_model_prepare(DRWCallState *st)
     invert_m3(st->normalview);
     transpose_m3(st->normalview);
   }
-  /* Non view dependent */
-  if (st->matflag & DRW_CALL_NORMALWORLD) {
-    copy_m3_m4(st->normalworld, st->model);
-    invert_m3(st->normalworld);
-    transpose_m3(st->normalworld);
-    st->matflag &= ~DRW_CALL_NORMALWORLD;
-  }
 }
 
 static void draw_geometry_prepare(DRWShadingGroup *shgroup, DRWCall *call)
@@ -847,10 +840,6 @@ static void draw_geometry_prepare(DRWShadingGroup *shgroup, DRWCall *call)
       GPU_shader_uniform_vector(
           shgroup->shader, shgroup->normalview, 9, 1, (float *)state->normalview);
     }
-    if (shgroup->normalworld != -1) {
-      GPU_shader_uniform_vector(
-          shgroup->shader, shgroup->normalworld, 9, 1, (float *)state->normalworld);
-    }
     if (shgroup->objectinfo != -1) {
       float objectinfo[4];
       objectinfo[0] = state->objectinfo[0];
@@ -865,7 +854,7 @@ static void draw_geometry_prepare(DRWShadingGroup *shgroup, DRWCall *call)
     }
   }
   else {
-    BLI_assert((shgroup->normalview == -1) && (shgroup->normalworld == -1));
+    BLI_assert((shgroup->normalview == -1));
     /* For instancing and batching. */
     float unitmat[4][4];
     unit_m4(unitmat);
index 25aa8e1..50d6760 100644 (file)
@@ -17,5 +17,8 @@ layout(std140) uniform viewBlock
 /* Transform shortcuts. */
 #define transform_normal_object_to_world(nor) (transpose(mat3(ModelMatrixInverse)) * nor)
 #define transform_normal_world_to_object(nor) (transpose(mat3(ModelMatrix)) * nor)
+#define transform_normal_world_to_view(nor) (transpose(mat3(ViewMatrixInverse)) * nor)
+#define transform_normal_object_to_view(nor) \
+  (transpose(mat3(ViewMatrixInverse)) * (transpose(mat3(ModelMatrixInverse)) * nor))
 #define transform_point_view_to_object(point) \
   ((ModelMatrixInverse * (ViewMatrixInverse * vec4(point, 1.0))).xyz)
index 1b10de4..fc7d9e2 100644 (file)
@@ -45,7 +45,6 @@ typedef enum {
   GPU_UNIFORM_VIEWPROJECTION_INV, /* mat4 ViewProjectionMatrixInverse */
 
   GPU_UNIFORM_NORMAL,      /* mat3 NormalMatrix */
-  GPU_UNIFORM_WORLDNORMAL, /* mat3 WorldNormalMatrix */
   GPU_UNIFORM_CAMERATEXCO, /* vec4 CameraTexCoFactors */
   GPU_UNIFORM_ORCO,        /* vec3 OrcoTexCoFactors[] */
 
index 207a218..97dbb80 100644 (file)
@@ -61,7 +61,6 @@ static const char *BuiltinUniform_name(GPUUniformBuiltin u)
       [GPU_UNIFORM_VIEWPROJECTION_INV] = "ViewProjectionMatrixInverse",
 
       [GPU_UNIFORM_NORMAL] = "NormalMatrix",
-      [GPU_UNIFORM_WORLDNORMAL] = "WorldNormalMatrix",
       [GPU_UNIFORM_CAMERATEXCO] = "CameraTexCoFactors",
       [GPU_UNIFORM_ORCO] = "OrcoTexCoFactors",
 
index ca05a9b..f03e30b 100644 (file)
@@ -1,7 +1,6 @@
 
 uniform mat4 ModelViewMatrix;
 uniform mat4 ModelViewMatrixInverse;
-uniform mat3 NormalMatrix;
 
 #ifndef USE_ATTR
 uniform mat4 ModelMatrix;