[Bf-blender-cvs] [9d19ff90760] master: GPUShader: Add selection id shader

Clément Foucault noreply at git.blender.org
Fri Jan 11 16:00:30 CET 2019


Commit: 9d19ff90760755f6dea97a58fa50e5e299ae334e
Author: Clément Foucault
Date:   Sat Dec 22 21:02:30 2018 +0100
Branches: master
https://developer.blender.org/rB9d19ff90760755f6dea97a58fa50e5e299ae334e

GPUShader: Add selection id shader

This is to separate id drawing from standard color drawing.

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

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_3D_selection_id_vert.glsl
A	source/blender/gpu/shaders/gpu_shader_selection_id_frag.glsl

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

diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index 02e5d4ac479..4fc57617d30 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -218,6 +218,9 @@ data_to_c_simple(shaders/gpu_shader_2D_edituvs_edges_vert.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_2D_edituvs_faces_vert.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_2D_edituvs_stretch_vert.glsl SRC)
 
+data_to_c_simple(shaders/gpu_shader_3D_selection_id_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_selection_id_frag.glsl SRC)
+
 data_to_c_simple(shaders/gpu_shader_edges_front_back_persp_vert.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_edges_front_back_persp_geom.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_edges_front_back_persp_legacy_vert.glsl SRC)
diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h
index 8a603f3caf2..eea8f78fe48 100644
--- a/source/blender/gpu/GPU_shader.h
+++ b/source/blender/gpu/GPU_shader.h
@@ -352,6 +352,9 @@ typedef enum GPUBuiltinShader {
 	GPU_SHADER_2D_UV_EDGES_SMOOTH,
 	GPU_SHADER_2D_UV_FACES,
 	GPU_SHADER_2D_UV_FACES_STRETCH,
+	/* Selection */
+	GPU_SHADER_3D_FLAT_SELECT_ID,
+	GPU_SHADER_3D_UNIFORM_SELECT_ID,
 
 	GPU_NUM_BUILTIN_SHADERS /* (not an actual shader) */
 } GPUBuiltinShader;
diff --git a/source/blender/gpu/intern/gpu_shader.c b/source/blender/gpu/intern/gpu_shader.c
index 00646223793..6ad6faf86e1 100644
--- a/source/blender/gpu/intern/gpu_shader.c
+++ b/source/blender/gpu/intern/gpu_shader.c
@@ -146,6 +146,9 @@ extern char datatoc_gpu_shader_2D_edituvs_edges_vert_glsl[];
 extern char datatoc_gpu_shader_2D_edituvs_faces_vert_glsl[];
 extern char datatoc_gpu_shader_2D_edituvs_stretch_vert_glsl[];
 
+extern char datatoc_gpu_shader_3D_selection_id_vert_glsl[];
+extern char datatoc_gpu_shader_selection_id_frag_glsl[];
+
 extern char datatoc_gpu_shader_2D_line_dashed_uniform_color_vert_glsl[];
 extern char datatoc_gpu_shader_2D_line_dashed_frag_glsl[];
 extern char datatoc_gpu_shader_2D_line_dashed_geom_glsl[];
@@ -940,6 +943,13 @@ static const GPUShaderStages builtin_shader_stages[GPU_NUM_BUILTIN_SHADERS] = {
 		{ datatoc_gpu_shader_2D_edituvs_stretch_vert_glsl,
 		  datatoc_gpu_shader_2D_smooth_color_frag_glsl },
 
+	[GPU_SHADER_3D_FLAT_SELECT_ID] =
+		{ datatoc_gpu_shader_3D_selection_id_vert_glsl,
+		  datatoc_gpu_shader_selection_id_frag_glsl },
+	[GPU_SHADER_3D_UNIFORM_SELECT_ID] =
+		{ datatoc_gpu_shader_3D_selection_id_vert_glsl,
+		  datatoc_gpu_shader_selection_id_frag_glsl },
+
 	[GPU_SHADER_GPENCIL_STROKE] =
 		{ datatoc_gpu_shader_gpencil_stroke_vert_glsl,
 		  datatoc_gpu_shader_gpencil_stroke_frag_glsl,
@@ -1007,6 +1017,9 @@ static const char *gpu_shader_get_builtin_shader_defines(
 		case GPU_SHADER_2D_UV_EDGES_SMOOTH:
 			return "#define SMOOTH_COLOR\n";
 
+		case GPU_SHADER_3D_UNIFORM_SELECT_ID:
+			return "#define UNIFORM_ID\n";
+
 		default:
 			return NULL;
 	}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_selection_id_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_selection_id_vert.glsl
new file mode 100644
index 00000000000..9c6be69efce
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_3D_selection_id_vert.glsl
@@ -0,0 +1,24 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+
+in vec3 pos;
+
+#ifndef UNIFORM_ID
+uniform uint offset;
+in uint color;
+
+flat out vec4 id;
+#endif
+
+void main()
+{
+#ifndef UNIFORM_ID
+	id = vec4(
+		(((color + offset)      ) & uint(0xFF)) * (1.0f / 255.0f),
+		(((color + offset) >>  8) & uint(0xFF)) * (1.0f / 255.0f),
+		(((color + offset) >> 16) & uint(0xFF)) * (1.0f / 255.0f),
+		(((color + offset) >> 24)             ) * (1.0f / 255.0f));
+#endif
+
+	gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_selection_id_frag.glsl b/source/blender/gpu/shaders/gpu_shader_selection_id_frag.glsl
new file mode 100644
index 00000000000..29fe9e9d8c7
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_selection_id_frag.glsl
@@ -0,0 +1,21 @@
+
+#ifdef UNIFORM_ID
+uniform uint id;
+#else
+flat in vec4 id;
+#endif
+
+out vec4 fragColor;
+
+void main()
+{
+#ifdef UNIFORM_ID
+	fragColor = vec4(
+		((id      ) & uint(0xFF)) * (1.0f / 255.0f),
+		((id >>  8) & uint(0xFF)) * (1.0f / 255.0f),
+		((id >> 16) & uint(0xFF)) * (1.0f / 255.0f),
+		((id >> 24)             ) * (1.0f / 255.0f));
+#else
+	fragColor = id;
+#endif
+}



More information about the Bf-blender-cvs mailing list