[Bf-blender-cvs] [70761211754] tmp-drw-callbatching: Cleanup: GPU: Avoid implicit matrix multiplication

Clément Foucault noreply at git.blender.org
Sat Aug 17 14:49:45 CEST 2019


Commit: 70761211754fb58b42adc5adbf4c1fe8c051cabd
Author: Clément Foucault
Date:   Sun Jun 2 11:55:17 2019 +0200
Branches: tmp-drw-callbatching
https://developer.blender.org/rB70761211754fb58b42adc5adbf4c1fe8c051cabd

Cleanup: GPU: Avoid implicit matrix multiplication

===================================================================

M	source/blender/gpu/shaders/gpu_shader_instance_camera_vert.glsl
M	source/blender/gpu/shaders/gpu_shader_instance_distance_line_vert.glsl
M	source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_color_vert.glsl
M	source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_id_vert.glsl
M	source/blender/gpu/shaders/gpu_shader_instance_vert.glsl

===================================================================

diff --git a/source/blender/gpu/shaders/gpu_shader_instance_camera_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_camera_vert.glsl
index 31b359dbe6d..f32c47bcec3 100644
--- a/source/blender/gpu/shaders/gpu_shader_instance_camera_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_instance_camera_vert.glsl
@@ -1,8 +1,5 @@
 
 uniform mat4 ViewProjectionMatrix;
-#ifdef USE_WORLD_CLIP_PLANES
-uniform mat4 ModelMatrix;
-#endif
 
 /* ---- Instantiated Attrs ---- */
 in float pos;
@@ -47,11 +44,12 @@ void main()
     pPos = vec3(0.0);
   }
 
-  gl_Position = ViewProjectionMatrix * InstanceModelMatrix * vec4(pPos, 1.0);
+  vec4 wPos = InstanceModelMatrix * vec4(pPos, 1.0);
+  gl_Position = ViewProjectionMatrix * wPos;
 
   finalColor = vec4(color, 1.0);
 
 #ifdef USE_WORLD_CLIP_PLANES
-  world_clip_planes_calc_clip_distance((ModelMatrix * InstanceModelMatrix * vec4(pPos, 1.0)).xyz);
+  world_clip_planes_calc_clip_distance(wPos.xyz);
 #endif
 }
diff --git a/source/blender/gpu/shaders/gpu_shader_instance_distance_line_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_distance_line_vert.glsl
index d9a0ffbbdac..5bd29c55e42 100644
--- a/source/blender/gpu/shaders/gpu_shader_instance_distance_line_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_instance_distance_line_vert.glsl
@@ -18,13 +18,14 @@ void main()
 {
   float len = end - start;
   vec3 sta = vec3(0.0, 0.0, -start);
-  vec4 pos_4d = vec4(pos * -len + sta, 1.0);
 
-  gl_Position = ViewProjectionMatrix * InstanceModelMatrix * pos_4d;
+  vec4 wPos = InstanceModelMatrix * vec4(pos * -len + sta, 1.0);
+
+  gl_Position = ViewProjectionMatrix * wPos;
   gl_PointSize = size;
   finalColor = vec4(color, 1.0);
 
 #ifdef USE_WORLD_CLIP_PLANES
-  world_clip_planes_calc_clip_distance((InstanceModelMatrix * pos_4d).xyz);
+  world_clip_planes_calc_clip_distance(wPos.xyz);
 #endif
 }
diff --git a/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_color_vert.glsl
index 3e52e43beae..10228a1e985 100644
--- a/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_color_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_color_vert.glsl
@@ -1,6 +1,5 @@
 
 uniform mat4 ViewProjectionMatrix;
-uniform mat4 ModelMatrix;
 
 /* ---- Instantiated Attrs ---- */
 in vec3 pos;
@@ -20,10 +19,10 @@ void main()
 {
   finalColor = color;
 
-  vec4 pos_4d = vec4(pos * size, 1.0);
-  gl_Position = ViewProjectionMatrix * InstanceModelMatrix * pos_4d;
+  vec4 wPos = InstanceModelMatrix * vec4(pos * size, 1.0);
+  gl_Position = ViewProjectionMatrix * wPos;
 
 #ifdef USE_WORLD_CLIP_PLANES
-  world_clip_planes_calc_clip_distance((ModelMatrix * InstanceModelMatrix * pos_4d).xyz);
+  world_clip_planes_calc_clip_distance(wPos.xyz);
 #endif
 }
diff --git a/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_id_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_id_vert.glsl
index 130f46e1e33..32db8d17572 100644
--- a/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_id_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_id_vert.glsl
@@ -1,8 +1,6 @@
 
 uniform mat4 ViewProjectionMatrix;
-#ifdef USE_WORLD_CLIP_PLANES
-uniform mat4 ModelMatrix;
-#endif
+
 uniform int baseId;
 
 /* ---- Instantiated Attrs ---- */
@@ -21,11 +19,11 @@ flat out uint finalId;
 
 void main()
 {
-  vec4 pos_4d = vec4(pos * size, 1.0);
-  gl_Position = ViewProjectionMatrix * InstanceModelMatrix * pos_4d;
+  vec4 wPos = InstanceModelMatrix * vec4(pos * size, 1.0);
+  gl_Position = ViewProjectionMatrix * wPos;
   finalId = uint(baseId + callId);
 
 #ifdef USE_WORLD_CLIP_PLANES
-  world_clip_planes_calc_clip_distance((ModelMatrix * InstanceModelMatrix * pos_4d).xyz);
+  world_clip_planes_calc_clip_distance(wPos.xyz);
 #endif
 }
diff --git a/source/blender/gpu/shaders/gpu_shader_instance_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_vert.glsl
index eeca6e972fa..b8d31f5540a 100644
--- a/source/blender/gpu/shaders/gpu_shader_instance_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_instance_vert.glsl
@@ -9,5 +9,5 @@ in mat4 InstanceModelMatrix;
 
 void main()
 {
-  gl_Position = ViewProjectionMatrix * InstanceModelMatrix * vec4(pos, 1.0);
+  gl_Position = ViewProjectionMatrix * (InstanceModelMatrix * vec4(pos, 1.0));
 }



More information about the Bf-blender-cvs mailing list