From 9d19ff90760755f6dea97a58fa50e5e299ae334e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Sat, 22 Dec 2018 21:02:30 +0100 Subject: GPUShader: Add selection id shader This is to separate id drawing from standard color drawing. --- .../shaders/gpu_shader_3D_selection_id_vert.glsl | 24 ++++++++++++++++++++++ .../gpu/shaders/gpu_shader_selection_id_frag.glsl | 21 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 source/blender/gpu/shaders/gpu_shader_3D_selection_id_vert.glsl create mode 100644 source/blender/gpu/shaders/gpu_shader_selection_id_frag.glsl (limited to 'source/blender/gpu/shaders') 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 +} -- cgit v1.2.3