Workbench: Use common_view_lib and remove NormalMatrix usage
authorClément Foucault <foucault.clem@gmail.com>
Wed, 8 May 2019 20:08:20 +0000 (22:08 +0200)
committerClément Foucault <foucault.clem@gmail.com>
Wed, 8 May 2019 20:08:20 +0000 (22:08 +0200)
This is in order to lower the number of matrices to compute.

source/blender/draw/engines/workbench/shaders/workbench_deferred_composite_frag.glsl
source/blender/draw/engines/workbench/shaders/workbench_forward_transparent_accum_frag.glsl
source/blender/draw/engines/workbench/shaders/workbench_prepass_vert.glsl
source/blender/draw/engines/workbench/workbench_deferred.c
source/blender/draw/engines/workbench/workbench_forward.c

index 65196c1..a1f8044 100644 (file)
@@ -1,8 +1,5 @@
 out vec4 fragColor;
 
-uniform mat4 ProjectionMatrix;
-uniform mat4 ViewMatrixInverse;
-
 uniform usampler2D objectId;
 uniform sampler2D materialBuffer;
 uniform sampler2D normalBuffer;
index 5eff0b4..3224378 100644 (file)
@@ -4,8 +4,6 @@ uniform sampler2D image;
 uniform bool imageSrgb;
 uniform bool imageNearest;
 
-uniform mat4 ProjectionMatrix;
-uniform mat4 ViewMatrixInverse;
 uniform float alpha = 0.5;
 uniform vec2 invertedViewportSize;
 uniform vec4 viewvecs[3];
index f2c684c..1de6121 100644 (file)
@@ -1,10 +1,7 @@
-uniform mat4 ModelViewProjectionMatrix;
 uniform mat4 ModelMatrix;
 uniform mat4 ModelMatrixInverse;
-uniform mat4 ProjectionMatrix;
-uniform mat4 ViewProjectionMatrix;
-uniform mat4 ViewMatrixInverse;
-uniform mat3 NormalMatrix;
+
+uniform mat4 ModelViewProjectionMatrix;
 
 #ifndef HAIR_SHADER
 in vec3 pos;
@@ -91,7 +88,7 @@ void main()
 #endif
 
 #ifdef NORMAL_VIEWPORT_PASS_ENABLED
-  normal_viewport = NormalMatrix * nor;
+  normal_viewport = transform_normal_object_to_view(nor);
 #  ifndef HAIR_SHADER
   normal_viewport = normalize(normal_viewport);
 #  endif
index 64b00a0..e0bf8da 100644 (file)
@@ -91,6 +91,7 @@ static struct {
 
 /* Shaders */
 extern char datatoc_common_hair_lib_glsl[];
+extern char datatoc_common_view_lib_glsl[];
 
 extern char datatoc_workbench_prepass_vert_glsl[];
 extern char datatoc_workbench_prepass_frag_glsl[];
@@ -119,6 +120,7 @@ static char *workbench_build_composite_frag(WORKBENCH_PrivateData *wpd)
 {
   DynStr *ds = BLI_dynstr_new();
 
+  BLI_dynstr_append(ds, datatoc_common_view_lib_glsl);
   BLI_dynstr_append(ds, datatoc_workbench_data_lib_glsl);
   BLI_dynstr_append(ds, datatoc_workbench_common_lib_glsl);
   BLI_dynstr_append(ds, datatoc_workbench_background_lib_glsl);
@@ -159,6 +161,7 @@ static char *workbench_build_prepass_vert(bool is_hair)
   if (is_hair) {
     BLI_dynstr_append(ds, datatoc_common_hair_lib_glsl);
   }
+  BLI_dynstr_append(ds, datatoc_common_view_lib_glsl);
   BLI_dynstr_append(ds, datatoc_workbench_prepass_vert_glsl);
   char *str = BLI_dynstr_get_cstring(ds);
   BLI_dynstr_free(ds);
index fe3e057..25f95f0 100644 (file)
@@ -68,6 +68,7 @@ static struct {
 
 /* Shaders */
 extern char datatoc_common_hair_lib_glsl[];
+extern char datatoc_common_view_lib_glsl[];
 
 extern char datatoc_workbench_forward_composite_frag_glsl[];
 extern char datatoc_workbench_forward_depth_frag_glsl[];
@@ -88,6 +89,7 @@ static char *workbench_build_forward_vert(bool is_hair)
   if (is_hair) {
     BLI_dynstr_append(ds, datatoc_common_hair_lib_glsl);
   }
+  BLI_dynstr_append(ds, datatoc_common_view_lib_glsl);
   BLI_dynstr_append(ds, datatoc_workbench_prepass_vert_glsl);
 
   char *str = BLI_dynstr_get_cstring(ds);
@@ -99,6 +101,7 @@ static char *workbench_build_forward_transparent_accum_frag(void)
 {
   DynStr *ds = BLI_dynstr_new();
 
+  BLI_dynstr_append(ds, datatoc_common_view_lib_glsl);
   BLI_dynstr_append(ds, datatoc_workbench_data_lib_glsl);
   BLI_dynstr_append(ds, datatoc_workbench_common_lib_glsl);
   BLI_dynstr_append(ds, datatoc_workbench_world_light_lib_glsl);