Object Mode: Make point clouds a bit less like uniform blobs
authorClément Foucault <foucault.clem@gmail.com>
Mon, 10 Dec 2018 22:16:03 +0000 (23:16 +0100)
committerClément Foucault <foucault.clem@gmail.com>
Mon, 10 Dec 2018 22:17:20 +0000 (23:17 +0100)
Also this display is optimized. It does not use blending and pixel discard.
Working with scanned data should be more pleasant with this.

A better option would be to use gl_FragDepth to have a better sense of
volume but this discards early depth test.

source/blender/draw/CMakeLists.txt
source/blender/draw/modes/object_mode.c
source/blender/draw/modes/shaders/object_loose_points_frag.glsl [new file with mode: 0644]

index 9c1ca46175ea66059f9ea8b50ac3d3312f29c473..286cf9753e76466ddb2102817318748aff5f12bb 100644 (file)
@@ -306,6 +306,7 @@ data_to_c_simple(modes/shaders/object_mball_handles_vert.glsl SRC)
 data_to_c_simple(modes/shaders/object_particle_prim_vert.glsl SRC)
 data_to_c_simple(modes/shaders/object_particle_dot_vert.glsl SRC)
 data_to_c_simple(modes/shaders/object_particle_dot_frag.glsl SRC)
+data_to_c_simple(modes/shaders/object_loose_points_frag.glsl SRC)
 data_to_c_simple(modes/shaders/paint_texture_frag.glsl SRC)
 data_to_c_simple(modes/shaders/paint_texture_vert.glsl SRC)
 data_to_c_simple(modes/shaders/paint_vertex_frag.glsl SRC)
index 90d499aebd601d6633f0a62aecf4244434a5d005..31314a352321ca8bf77f52a3e4cd903d974e2656 100644 (file)
@@ -93,6 +93,7 @@ extern char datatoc_object_grid_vert_glsl[];
 extern char datatoc_object_empty_image_frag_glsl[];
 extern char datatoc_object_empty_image_vert_glsl[];
 extern char datatoc_object_lightprobe_grid_vert_glsl[];
+extern char datatoc_object_loose_points_frag_glsl[];
 extern char datatoc_object_particle_prim_vert_glsl[];
 extern char datatoc_object_particle_dot_vert_glsl[];
 extern char datatoc_object_particle_dot_frag_glsl[];
@@ -306,6 +307,7 @@ static struct {
        GPUShader *part_prim_sh;
        GPUShader *part_axis_sh;
        GPUShader *lightprobe_grid_sh;
+       GPUShader *loose_points_sh;
        float camera_pos[3];
        float screenvecs[3][4];
        float grid_settings[5];
@@ -457,6 +459,9 @@ static void OBJECT_engine_init(void *vedata)
                /* Lightprobes */
                e_data.lightprobe_grid_sh = DRW_shader_create(
                        datatoc_object_lightprobe_grid_vert_glsl, NULL, datatoc_gpu_shader_flat_id_frag_glsl, NULL);
+
+               /* Loose Points */
+               e_data.loose_points_sh = DRW_shader_create_3D(datatoc_object_loose_points_frag_glsl, NULL);
        }
 
        {
@@ -686,6 +691,7 @@ static void OBJECT_engine_free(void)
        DRW_SHADER_FREE_SAFE(e_data.part_axis_sh);
        DRW_SHADER_FREE_SAFE(e_data.part_dot_sh);
        DRW_SHADER_FREE_SAFE(e_data.lightprobe_grid_sh);
+       DRW_SHADER_FREE_SAFE(e_data.loose_points_sh);
 }
 
 static DRWShadingGroup *shgroup_outline(DRWPass *pass, const int *ofs, GPUShader *sh)
@@ -710,6 +716,7 @@ static DRWShadingGroup *shgroup_points(DRWPass *pass, const float col[4], GPUSha
 {
        DRWShadingGroup *grp = DRW_shgroup_create(sh, pass);
        DRW_shgroup_uniform_vec4(grp, "color", col, 1);
+       DRW_shgroup_uniform_vec4(grp, "innerColor", ts.colorEditMeshMiddle, 1);
 
        return grp;
 }
@@ -1192,11 +1199,15 @@ static void OBJECT_cache_init(void *vedata)
                sgl->wire_active = shgroup_wire(sgl->non_meshes, ts.colorActive, sh);
 
                /* Points (loose points) */
-               sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_POINT_FIXED_SIZE_UNIFORM_COLOR);
+               sh = e_data.loose_points_sh;
                sgl->points = shgroup_points(sgl->non_meshes, ts.colorWire, sh);
                sgl->points_select = shgroup_points(sgl->non_meshes, ts.colorSelect, sh);
                sgl->points_transform = shgroup_points(sgl->non_meshes, ts.colorTransform, sh);
                sgl->points_active = shgroup_points(sgl->non_meshes, ts.colorActive, sh);
+               DRW_shgroup_state_disable(sgl->points, DRW_STATE_BLEND);
+               DRW_shgroup_state_disable(sgl->points_select, DRW_STATE_BLEND);
+               DRW_shgroup_state_disable(sgl->points_transform, DRW_STATE_BLEND);
+               DRW_shgroup_state_disable(sgl->points_active, DRW_STATE_BLEND);
 
                /* Metaballs Handles */
                sgl->mball_handle = shgroup_instance_mball_handles(sgl->non_meshes);
diff --git a/source/blender/draw/modes/shaders/object_loose_points_frag.glsl b/source/blender/draw/modes/shaders/object_loose_points_frag.glsl
new file mode 100644 (file)
index 0000000..66b3091
--- /dev/null
@@ -0,0 +1,19 @@
+
+uniform vec4 color;
+uniform vec4 innerColor;
+
+out vec4 fragColor;
+
+void main()
+{
+       vec2 centered = abs(gl_PointCoord - vec2(0.5));
+       float dist = max(centered.x, centered.y);
+
+       float fac = dist * dist * 4.0;
+       fragColor = mix(innerColor, color, 0.45 + fac * 0.65);
+
+       /* Make the effect more like a fresnel by offsetting
+        * the depth and creating mini-spheres.
+        * Disabled as it has performance impact. */
+       // gl_FragDepth = gl_FragCoord.z + 1e-6 * fac;
+}