Commit: 9f03718a5bdf77137c308a3c76c83254b33f7cca
Author: Clément Foucault
Date:   Wed Feb 15 02:54:52 2017 +0100
Branches: blender2.8
https://developer.blender.org/rB9f03718a5bdf77137c308a3c76c83254b33f7cca

Clay Engine: drawaxis names drawn with shaders & instance

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

M       source/blender/draw/intern/draw_cache.c
M       source/blender/draw/intern/draw_cache.h
M       source/blender/draw/intern/draw_mode_pass.c
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_screenspace_axis_name_vert.glsl

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

diff --git a/source/blender/draw/intern/draw_cache.c 
b/source/blender/draw/intern/draw_cache.c
index dfb7ff2263..6ebb9008b6 100644
--- a/source/blender/draw/intern/draw_cache.c
+++ b/source/blender/draw/intern/draw_cache.c
@@ -48,6 +48,7 @@ static struct DRWShapeCache{
        Batch *drw_empty_sphere;
        Batch *drw_empty_cone;
        Batch *drw_arrows;
+       Batch *drw_axis_names;
        Batch *drw_lamp;
        Batch *drw_lamp_sunrays;
 } SHC = {NULL};
@@ -74,6 +75,8 @@ void DRW_shape_cache_free(void)
                Batch_discard_all(SHC.drw_empty_cone);
        if (SHC.drw_arrows)
                Batch_discard_all(SHC.drw_arrows);
+       if (SHC.drw_axis_names)
+               Batch_discard_all(SHC.drw_axis_names);
        if (SHC.drw_lamp)
                Batch_discard_all(SHC.drw_lamp);
        if (SHC.drw_lamp_sunrays)
@@ -420,6 +423,67 @@ Batch *DRW_cache_arrows_get(void)
        return SHC.drw_arrows;
 }
 
+Batch *DRW_cache_axis_names_get(void)
+{
+       if (!SHC.drw_axis_names) {
+               const float size = 0.1f;
+               float v1[3], v2[3];
+
+               /* Position Only 3D format */
+               static VertexFormat format = { 0 };
+               static unsigned pos_id;
+               if (format.attrib_ct == 0) {
+                       /* Using 3rd component as axis indicator */
+                       pos_id = add_attrib(&format, "pos", GL_FLOAT, 3, 
KEEP_FLOAT);
+               }
+
+               /* Line */
+               VertexBuffer *vbo = VertexBuffer_create_with_format(&format);
+               VertexBuffer_allocate_data(vbo, 14);
+
+               /* X */
+               copy_v3_fl3(v1, -size,  size, 0.0f);
+               copy_v3_fl3(v2,  size, -size, 0.0f);
+               setAttrib(vbo, pos_id, 0, v1);
+               setAttrib(vbo, pos_id, 1, v2);
+
+               copy_v3_fl3(v1,  size,  size, 0.0f);
+               copy_v3_fl3(v2, -size, -size, 0.0f);
+               setAttrib(vbo, pos_id, 2, v1);
+               setAttrib(vbo, pos_id, 3, v2);
+
+               /* Y */
+               copy_v3_fl3(v1, -size + 0.25f * size,  size, 1.0f);
+               copy_v3_fl3(v2,  0.0f,  0.0f, 1.0f);
+               setAttrib(vbo, pos_id, 4, v1);
+               setAttrib(vbo, pos_id, 5, v2);
+
+               copy_v3_fl3(v1,  size - 0.25f * size,  size, 1.0f);
+               copy_v3_fl3(v2, -size + 0.25f * size, -size, 1.0f);
+               setAttrib(vbo, pos_id, 6, v1);
+               setAttrib(vbo, pos_id, 7, v2);
+
+               /* Z */
+               copy_v3_fl3(v1, -size,  size, 2.0f);
+               copy_v3_fl3(v2,  size,  size, 2.0f);
+               setAttrib(vbo, pos_id, 8, v1);
+               setAttrib(vbo, pos_id, 9, v2);
+
+               copy_v3_fl3(v1,  size,  size, 2.0f);
+               copy_v3_fl3(v2, -size, -size, 2.0f);
+               setAttrib(vbo, pos_id, 10, v1);
+               setAttrib(vbo, pos_id, 11, v2);
+
+               copy_v3_fl3(v1, -size, -size, 2.0f);
+               copy_v3_fl3(v2,  size, -size, 2.0f);
+               setAttrib(vbo, pos_id, 12, v1);
+               setAttrib(vbo, pos_id, 13, v2);
+
+               SHC.drw_axis_names = Batch_create(GL_LINES, vbo, NULL);
+       }
+       return SHC.drw_axis_names;
+}
+
 /* Lamps */
 Batch *DRW_cache_lamp_get(void)
 {
diff --git a/source/blender/draw/intern/draw_cache.h 
b/source/blender/draw/intern/draw_cache.h
index 0e467bddbf..b101b00473 100644
--- a/source/blender/draw/intern/draw_cache.h
+++ b/source/blender/draw/intern/draw_cache.h
@@ -44,6 +44,7 @@ struct Batch *DRW_cache_circle_get(void);
 struct Batch *DRW_cache_empty_sphere_get(void);
 struct Batch *DRW_cache_empty_cone_get(void);
 struct Batch *DRW_cache_arrows_get(void);
+struct Batch *DRW_cache_axis_names_get(void);
 
 /* Lamps */
 struct Batch *DRW_cache_lamp_get(void);
diff --git a/source/blender/draw/intern/draw_mode_pass.c 
b/source/blender/draw/intern/draw_mode_pass.c
index e1a6ff34c1..7ad00fffcd 100644
--- a/source/blender/draw/intern/draw_mode_pass.c
+++ b/source/blender/draw/intern/draw_mode_pass.c
@@ -48,6 +48,7 @@ static DRWShadingGroup *cone;
 static DRWShadingGroup *single_arrow;
 static DRWShadingGroup *single_arrow_line;
 static DRWShadingGroup *arrows;
+static DRWShadingGroup *axis_names;
 
 /* Lamps */
 static DRWShadingGroup *lamp_center;
@@ -130,6 +131,19 @@ static DRWShadingGroup 
*shgroup_instance_screenspace(DRWPass *pass, struct Batch
        return grp;
 }
 
+static DRWShadingGroup *shgroup_instance_axis_names(DRWPass *pass, struct 
Batch *geom)
+{
+       GPUShader *sh = 
GPU_shader_get_builtin_shader(GPU_SHADER_3D_SCREENSPACE_AXIS);
+
+       DRWShadingGroup *grp = DRW_shgroup_instance_create(sh, pass, geom);
+       DRW_shgroup_attrib_float(grp, "color", 3);
+       DRW_shgroup_attrib_float(grp, "size", 1);
+       DRW_shgroup_attrib_float(grp, "InstanceModelMatrix", 16);
+       DRW_shgroup_uniform_vec3(grp, "screen_vecs", 
DRW_viewport_screenvecs_get(), 2);
+
+       return grp;
+}
+
 static DRWShadingGroup *shgroup_instance(DRWPass *pass, struct Batch *geom)
 {
        GPUShader *sh_inst = 
GPU_shader_get_builtin_shader(GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SIZE);
@@ -211,6 +225,9 @@ void DRW_pass_setup_common(DRWPass **wire_overlay, DRWPass 
**wire_outline, DRWPa
                geom = DRW_cache_arrows_get();
                arrows = shgroup_instance(*non_meshes, geom);
 
+               geom = DRW_cache_axis_names_get();
+               axis_names = shgroup_instance_axis_names(*non_meshes, geom);
+
                /* Lamps */
                lampCenterSize = (U.obcenter_dia + 1.5f) * U.pixelsize;
                lampCircleRad = U.pixelsize * 9.0f;
@@ -231,16 +248,6 @@ void DRW_pass_setup_common(DRWPass **wire_overlay, DRWPass 
**wire_outline, DRWPa
                lamp_groundline = 
shgroup_groundlines_uniform_color(*non_meshes, colorLamp);
                lamp_groundpoint = 
shgroup_groundpoints_uniform_color(*non_meshes, colorLamp);
 
-               /* Stipple Wires */
-               grp = DRW_shgroup_create(sh, *non_meshes);
-               DRW_shgroup_state_set(grp, DRW_STATE_STIPPLE_2);
-
-               grp = DRW_shgroup_create(sh, *non_meshes);
-               DRW_shgroup_state_set(grp, DRW_STATE_STIPPLE_3);
-
-               grp = DRW_shgroup_create(sh, *non_meshes);
-               DRW_shgroup_state_set(grp, DRW_STATE_STIPPLE_4);
-
                /* Relationship Lines */
                relationship_lines = 
shgroup_dynlines_uniform_color(*non_meshes, colorWire);
                DRW_shgroup_state_set(relationship_lines, DRW_STATE_STIPPLE_3);
@@ -502,6 +509,7 @@ static void DRW_draw_empty(Object *ob)
                        break;
                case OB_ARROWS:
                        DRW_shgroup_dynamic_call_add(arrows, color, 
&ob->empty_drawsize, ob->obmat);
+                       DRW_shgroup_dynamic_call_add(axis_names, color, 
&ob->empty_drawsize, ob->obmat);
                        /* TODO Missing axes names */
                        break;
        }
diff --git a/source/blender/gpu/CMakeLists.txt 
b/source/blender/gpu/CMakeLists.txt
index 8709446bc7..805dcb57c4 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_screenspace_variying_color_vert.glsl
 SRC)
+data_to_c_simple(shaders/gpu_shader_instance_screenspace_axis_name_vert.glsl 
SRC)
 
 data_to_c_simple(shaders/gpu_shader_3D_groundline_geom.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_3D_groundpoint_vert.glsl SRC)
diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h
index 0aa93e7322..12b76a2bee 100644
--- a/source/blender/gpu/GPU_shader.h
+++ b/source/blender/gpu/GPU_shader.h
@@ -138,6 +138,8 @@ typedef enum GPUBuiltinShader {
        GPU_SHADER_3D_GROUNDPOINT,
        GPU_SHADER_3D_GROUNDLINE,
        GPU_SHADER_3D_SCREENSPACE_VARIYING_COLOR,
+       /* axis name */
+       GPU_SHADER_3D_SCREENSPACE_AXIS,
        /* instance */
        GPU_SHADER_INSTANCE_UNIFORM_COLOR,
        GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SIZE,
diff --git a/source/blender/gpu/intern/gpu_shader.c 
b/source/blender/gpu/intern/gpu_shader.c
index cc58050dc5..f2b026a5ad 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_screenspace_variying_color_vert_glsl[];
+extern char datatoc_gpu_shader_instance_screenspace_axis_name_vert_glsl[];
 
 extern char datatoc_gpu_shader_3D_groundpoint_vert_glsl[];
 extern char datatoc_gpu_shader_3D_groundline_geom_glsl[];
@@ -699,6 +700,8 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader 
shader)
 
                [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,
+                                                    
datatoc_gpu_shader_flat_color_frag_glsl},
 
                [GPU_SHADER_2D_POINT_FIXED_SIZE_UNIFORM_COLOR] =
                        { datatoc_gpu_shader_2D_vert_glsl, 
datatoc_gpu_shader_point_uniform_color_frag_glsl },
diff --git 
a/source/blender/gpu/shaders/gpu_shader_instance_screenspace_axis_name_vert.glsl
 
b/source/blender/gpu/shaders/gpu_shader_instance_screenspace_axis_name_vert.glsl
new file mode 100644
index 0000000000..a7accd9c3e
--- /dev/null
+++ 
b/source/blender/gpu/shaders/gpu_shader_instance_screenspace_axis_name_vert.glsl
@@ -0,0 +1,29 @@
+
+uniform mat4 ViewProjectionMatrix;
+uniform vec3 screen_vecs[2];
+
+/* ---- Instanciated Attribs ---- */
+in vec3 pos; /* using Z as axis id */
+
+/* ---- Per instance Attribs ---- */
+in mat4 InstanceModelMatrix;
+in vec3 color;
+in float size;
+
+flat out vec4 finalColor;
+
+void main()
+{
+       vec3 offset;
+
+       if (pos.z == 0.0)
+               offset = vec3(1.125, 0.0, 0.0);
+       else if (pos.z == 1.0)
+               offset = vec3(0.0, 1.125, 0.0);
+       else
+               offset = vec3(0.0, 0.0, 1.125);
+
+       vec3 screen_pos = screen_vecs[0].xyz * pos.x + screen_vecs[1].xyz * 
pos.y;
+       gl_Position = ViewProjectionMatrix * InstanceModelMatrix * 
vec4((screen_pos + offset) * size, 1.0);
+       finalColor = vec4(color, 1.0);
+}

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to