Commit: 6dbc6dfc14e749f929be93a5025b255d41c30941
Author: Clément Foucault
Date:   Wed Feb 22 12:46:27 2017 +0100
Branches: blender2.8
https://developer.blender.org/rB6dbc6dfc14e749f929be93a5025b255d41c30941

Clay Engine: Prepare for Armature drawing.

- Added runtime display matrices to EditBone and bPoseChannel
- Added Object space instance vertex shader and modified the simple lighting 
shader accordingly

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

M       source/blender/editors/include/ED_armature.h
M       source/blender/gpu/CMakeLists.txt
M       source/blender/gpu/GPU_shader.h
M       source/blender/gpu/intern/gpu_shader.c
A       
source/blender/gpu/shaders/gpu_shader_instance_objectspace_variying_color_vert.glsl
M       source/blender/gpu/shaders/gpu_shader_simple_lighting_frag.glsl
M       source/blender/makesdna/DNA_action_types.h

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

diff --git a/source/blender/editors/include/ED_armature.h 
b/source/blender/editors/include/ED_armature.h
index 3bde01a1bd..867e85487e 100644
--- a/source/blender/editors/include/ED_armature.h
+++ b/source/blender/editors/include/ED_armature.h
@@ -83,6 +83,12 @@ typedef struct EditBone {
        
        short segments;
 
+       /* Used for display */
+       float disp_mat[4][4];  /*  in Armature space, rest pos matrix */
+       float disp_tail_mat[4][4];  /*  in Armature space, rest pos matrix */
+       /* 32 == MAX_BBONE_SUBDIV */
+       float disp_bbone_mat[32][4][4]; /*  in Armature space, rest pos matrix 
*/
+
        /* Used to store temporary data */
        union {
                struct EditBone *ebone;
diff --git a/source/blender/gpu/CMakeLists.txt 
b/source/blender/gpu/CMakeLists.txt
index a59971610e..2249f19881 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -158,6 +158,7 @@ 
data_to_c_simple(shaders/gpu_shader_3D_passthrough_vert.glsl SRC)
 
 data_to_c_simple(shaders/gpu_shader_instance_vert.glsl SRC)
 
data_to_c_simple(shaders/gpu_shader_instance_variying_size_variying_color_vert.glsl
 SRC)
+data_to_c_simple(shaders/gpu_shader_instance_objectspace_variying_color_vert.glsl
 SRC)
 
data_to_c_simple(shaders/gpu_shader_instance_screenspace_variying_color_vert.glsl
 SRC)
 data_to_c_simple(shaders/gpu_shader_instance_screenspace_axis_name_vert.glsl 
SRC)
 
diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h
index 2ebbbba2cc..f77fd3b6dc 100644
--- a/source/blender/gpu/GPU_shader.h
+++ b/source/blender/gpu/GPU_shader.h
@@ -139,6 +139,9 @@ typedef enum GPUBuiltinShader {
        GPU_SHADER_3D_GROUNDPOINT,
        GPU_SHADER_3D_GROUNDLINE,
        GPU_SHADER_3D_SCREENSPACE_VARIYING_COLOR,
+       /* bone drawing */
+       GPU_SHADER_3D_OBJECTSPACE_VARIYING_COLOR,
+       GPU_SHADER_3D_OBJECTSPACE_SIMPLE_LIGHTING_VARIYING_COLOR,
        /* axis name */
        GPU_SHADER_3D_SCREENSPACE_AXIS,
        /* instance */
diff --git a/source/blender/gpu/intern/gpu_shader.c 
b/source/blender/gpu/intern/gpu_shader.c
index 8cae197408..a9d85838ac 100644
--- a/source/blender/gpu/intern/gpu_shader.c
+++ b/source/blender/gpu/intern/gpu_shader.c
@@ -75,6 +75,7 @@ extern char datatoc_gpu_shader_3D_passthrough_vert_glsl[];
 
 extern char datatoc_gpu_shader_instance_vert_glsl[];
 extern char 
datatoc_gpu_shader_instance_variying_size_variying_color_vert_glsl[];
+extern char datatoc_gpu_shader_instance_objectspace_variying_color_vert_glsl[];
 extern char datatoc_gpu_shader_instance_screenspace_variying_color_vert_glsl[];
 extern char datatoc_gpu_shader_instance_screenspace_axis_name_vert_glsl[];
 
@@ -701,6 +702,11 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader 
shader)
                                               
datatoc_gpu_shader_uniform_color_frag_glsl,
                                               
datatoc_gpu_shader_3D_groundline_geom_glsl },
 
+               [GPU_SHADER_3D_OBJECTSPACE_SIMPLE_LIGHTING_VARIYING_COLOR] =
+                   { 
datatoc_gpu_shader_instance_objectspace_variying_color_vert_glsl,
+                     datatoc_gpu_shader_simple_lighting_frag_glsl},
+               [GPU_SHADER_3D_OBJECTSPACE_VARIYING_COLOR] = { 
datatoc_gpu_shader_instance_objectspace_variying_color_vert_glsl,
+                                                              
datatoc_gpu_shader_flat_color_frag_glsl},
                [GPU_SHADER_3D_SCREENSPACE_VARIYING_COLOR] = { 
datatoc_gpu_shader_instance_screenspace_variying_color_vert_glsl,
                                                               
datatoc_gpu_shader_flat_color_frag_glsl},
                [GPU_SHADER_3D_SCREENSPACE_AXIS] = { 
datatoc_gpu_shader_instance_screenspace_axis_name_vert_glsl,
@@ -745,7 +751,8 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader 
shader)
        if (builtin_shaders[shader] == NULL) {
                /* just a few special cases */
                const char *defines = (shader == GPU_SHADER_SMOKE_COBA) ? 
"#define USE_COBA;\n" :
-                                     (shader == GPU_SHADER_SIMPLE_LIGHTING) ? 
"#define USE_NORMALS;\n" : NULL;
+                                     (shader == GPU_SHADER_SIMPLE_LIGHTING) ? 
"#define USE_NORMALS;\n" :
+                                     (shader == 
GPU_SHADER_3D_OBJECTSPACE_SIMPLE_LIGHTING_VARIYING_COLOR) ? "#define 
USE_INSTANCE_COLOR;\n" : NULL;
 
                const GPUShaderStages *stages = builtin_shader_stages + shader;
 
@@ -757,14 +764,6 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader 
shader)
                        stages = &legacy_fancy_edges;
                }
 
-               if (shader == GPU_SHADER_EDGES_FRONT_BACK_PERSP && 
!GLEW_VERSION_3_2) {
-                       /* TODO: remove after switch to core profile (maybe) */
-                       static const GPUShaderStages legacy_fancy_edges =
-                               { 
datatoc_gpu_shader_edges_front_back_persp_legacy_vert_glsl,
-                                 
datatoc_gpu_shader_flat_color_alpha_test_0_frag_glsl };
-                       stages = &legacy_fancy_edges;
-               }
-
                /* common case */
                builtin_shaders[shader] = GPU_shader_create(stages->vert, 
stages->frag, stages->geom,
                                                            NULL, defines, 0, 
0, 0);
diff --git 
a/source/blender/gpu/shaders/gpu_shader_instance_objectspace_variying_color_vert.glsl
 
b/source/blender/gpu/shaders/gpu_shader_instance_objectspace_variying_color_vert.glsl
new file mode 100644
index 0000000000..ce82dc6af2
--- /dev/null
+++ 
b/source/blender/gpu/shaders/gpu_shader_instance_objectspace_variying_color_vert.glsl
@@ -0,0 +1,29 @@
+
+uniform mat4 ViewMatrix;
+uniform mat4 ViewProjectionMatrix;
+uniform mat4 ModelMatrix;
+
+/* ---- Instanciated Attribs ---- */
+in vec3 pos;
+in vec3 nor;
+
+/* ---- Per instance Attribs ---- */
+in mat4 InstanceModelMatrix;
+in vec4 color;
+
+out vec3 normal;
+flat out vec4 finalColor;
+
+void main()
+{
+       mat4 FinalModelMatrix = ModelMatrix * InstanceModelMatrix;
+       mat4 ModelViewProjectionMatrix = ViewProjectionMatrix * 
FinalModelMatrix;
+       /* This is slow and run per vertex, but it's still faster than
+        * doing it per instance on CPU and sending it on via instance attrib */
+       mat3 NormalMatrix = transpose(inverse(mat3(ViewMatrix * 
FinalModelMatrix)));
+
+       gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+       normal = NormalMatrix * nor;
+
+       finalColor = color;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_simple_lighting_frag.glsl 
b/source/blender/gpu/shaders/gpu_shader_simple_lighting_frag.glsl
index 9828787fb0..4eacd08d5a 100644
--- a/source/blender/gpu/shaders/gpu_shader_simple_lighting_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_simple_lighting_frag.glsl
@@ -1,12 +1,21 @@
 
+#ifndef USE_INSTANCE_COLOR
 uniform vec4 color;
+#endif
 uniform vec3 light;
 
 #if __VERSION__ == 120
   varying vec3 normal;
+#ifdef USE_INSTANCE_COLOR
+  varying vec4 finalColor;
+#endif
   #define fragColor gl_FragColor
 #else
   in vec3 normal;
+#ifdef USE_INSTANCE_COLOR
+  flat in vec4 finalColor;
+  #define color finalColor
+#endif
   out vec4 fragColor;
 #endif
 
diff --git a/source/blender/makesdna/DNA_action_types.h 
b/source/blender/makesdna/DNA_action_types.h
index 1083400ece..cc64ce9288 100644
--- a/source/blender/makesdna/DNA_action_types.h
+++ b/source/blender/makesdna/DNA_action_types.h
@@ -238,6 +238,8 @@ typedef struct bPoseChannel {
        float chan_mat[4][4];           /* matrix result of loc/quat/size, and 
where we put deform in, see next line */
        float pose_mat[4][4];           /* constraints accumulate here. in the 
end, pose_mat = bone->arm_mat * chan_mat
                                         * this matrix is object space */
+       float disp_mat[4][4];           /* for display, pose_mat with bone 
length applied */
+       float disp_tail_mat[4][4];      /* for display, pose_mat with bone 
length applied and translated to tail*/
        float constinv[4][4];           /* inverse result of constraints.
                                         * doesn't include effect of 
restposition, parent, and local transform*/

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to