Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2018-04-27 17:27:47 +0300
committerClément Foucault <foucault.clem@gmail.com>2018-05-02 21:49:38 +0300
commit8c2a6f957ada6cca4b870c094979f9c3e6d43fa7 (patch)
treebfb4e9f8d5d13db5b13741fe0c112d94cc36de79 /source/blender/draw/intern/draw_common.c
parenta56561dcd28d5a8ee45948afb62cc7296c212a44 (diff)
Armature: "Raytrace" bones endpoint spheres.
Here is how it works: We render a high poly disc that we orient & scale towards the camera so that it covers the same pixel of the sphere it's supposed to represent. Then the pixel shader raytrace the sphere (effectively starting from the poly disc depth) and outputs the depth to gl_FragDepth. This approach has many benefit: - high quality obviously: per pixel accurate depth! - compatible with MSAA: since the sphere horizon is delimited by polygons, we get the coverage computed by the rasterizer. However we still gets aliasing if the sphere intersect directly other meshes. - virtually no overdraw: there is no backface to shade but we still get overdraw because by little triangle [gpus rasterize pixel by groups of 4]. - allows early depth test: since the poly disc is set at the nearest depth we can output, we can use GL_ARB_conservative_depth to enable early depth test and discard pixels that are already behind geometry. - can draw outline pretty easily without geometry shader.
Diffstat (limited to 'source/blender/draw/intern/draw_common.c')
-rw-r--r--source/blender/draw/intern/draw_common.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/source/blender/draw/intern/draw_common.c b/source/blender/draw/intern/draw_common.c
index 3a2aa970a9b..6d684b1c9fb 100644
--- a/source/blender/draw/intern/draw_common.c
+++ b/source/blender/draw/intern/draw_common.c
@@ -156,12 +156,17 @@ void DRW_globals_update(void)
/* ********************************* SHGROUP ************************************* */
+extern char datatoc_armature_sphere_vert_glsl[];
+extern char datatoc_armature_sphere_frag_glsl[];
+extern char datatoc_armature_sphere_outline_vert_glsl[];
extern char datatoc_armature_shape_outline_vert_glsl[];
extern char datatoc_armature_shape_outline_geom_glsl[];
extern char datatoc_gpu_shader_flat_color_frag_glsl[];
static struct {
struct GPUShader *shape_outline;
+ struct GPUShader *bone_sphere;
+ struct GPUShader *bone_sphere_outline;
} g_armature_shaders = {NULL};
static struct {
@@ -491,6 +496,47 @@ DRWShadingGroup *shgroup_instance_armature_shape_outline(DRWPass *pass, struct G
return grp;
}
+DRWShadingGroup *shgroup_instance_armature_sphere(DRWPass *pass)
+{
+ if (g_armature_shaders.bone_sphere == NULL) {
+ g_armature_shaders.bone_sphere = DRW_shader_create(
+ datatoc_armature_sphere_vert_glsl, NULL,
+ datatoc_armature_sphere_frag_glsl, NULL);
+ }
+
+ /* TODO own format? */
+ DRW_shgroup_instance_format(g_formats.instance_color, {
+ {"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16},
+ {"color" , DRW_ATTRIB_FLOAT, 4}
+ });
+
+ DRWShadingGroup *grp = DRW_shgroup_instance_create(g_armature_shaders.bone_sphere,
+ pass, DRW_cache_bone_point_get(), g_formats.instance_color);
+
+ return grp;
+}
+
+DRWShadingGroup *shgroup_instance_armature_sphere_outline(DRWPass *pass)
+{
+ if (g_armature_shaders.bone_sphere_outline == NULL) {
+ g_armature_shaders.bone_sphere_outline = DRW_shader_create(
+ datatoc_armature_sphere_outline_vert_glsl, NULL,
+ datatoc_gpu_shader_flat_color_frag_glsl, NULL);
+ }
+
+ /* TODO own format? */
+ DRW_shgroup_instance_format(g_formats.instance_color, {
+ {"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16},
+ {"color" , DRW_ATTRIB_FLOAT, 4}
+ });
+
+ DRWShadingGroup *grp = DRW_shgroup_instance_create(g_armature_shaders.bone_sphere_outline,
+ pass, DRW_cache_bone_point_wire_outline_get(),
+ g_formats.instance_color);
+ DRW_shgroup_uniform_vec2(grp, "viewportSize", DRW_viewport_size_get(), 1);
+
+ return grp;
+}