diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2017-02-15 04:54:52 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2017-02-15 14:28:26 +0300 |
commit | 9f03718a5bdf77137c308a3c76c83254b33f7cca (patch) | |
tree | 02a572bd525ad61df69cd38e6e7713abb8d22518 /source/blender/gpu | |
parent | ee2a71876308c891d19cb7df87ef85e2321d0420 (diff) |
Clay Engine: drawaxis names drawn with shaders & instance
Diffstat (limited to 'source/blender/gpu')
-rw-r--r-- | source/blender/gpu/CMakeLists.txt | 1 | ||||
-rw-r--r-- | source/blender/gpu/GPU_shader.h | 2 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_shader.c | 3 | ||||
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_instance_screenspace_axis_name_vert.glsl | 29 |
4 files changed, 35 insertions, 0 deletions
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index 8709446bc7b..805dcb57c40 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 0aa93e7322b..12b76a2bee1 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 cc58050dc5d..f2b026a5ad1 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 00000000000..a7accd9c3e0 --- /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); +} |