X-Ray: Added a slider for the alpha
authorJeroen Bakker <j.bakker@atmind.nl>
Fri, 1 Jun 2018 15:06:25 +0000 (17:06 +0200)
committerJeroen Bakker <j.bakker@atmind.nl>
Fri, 1 Jun 2018 15:15:35 +0000 (17:15 +0200)
- will not render when set to 0.0 for speed reasons. so when user sets
transparency to hide everything the bigger passes will be skipped.

release/scripts/startup/bl_ui/space_view3d.py
source/blender/blenloader/intern/versioning_280.c
source/blender/draw/engines/workbench/shaders/workbench_forward_composite_frag.glsl
source/blender/draw/engines/workbench/shaders/workbench_forward_transparent_accum_frag.glsl
source/blender/draw/engines/workbench/shaders/workbench_forward_transparent_revealage_frag.glsl
source/blender/draw/engines/workbench/workbench_forward.c
source/blender/editors/space_view3d/space_view3d.c
source/blender/makesdna/DNA_view3d_types.h
source/blender/makesrna/intern/rna_space.c

index 6010b1e..4f3396c 100644 (file)
@@ -3538,6 +3538,9 @@ class VIEW3D_PT_shading(Panel):
 
             row = col.row()
             row.prop(shading, "show_xray")
+            sub = row.row()
+            sub.active = shading.show_xray
+            sub.prop(shading, "xray_alpha", text="")
 
             row = col.row()
             row.active = not shading.show_xray
index 50ed9bf..ffc078c 100644 (file)
@@ -1522,5 +1522,18 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *main)
                                }
                        }
                }
+
+               if (!DNA_struct_elem_find(fd->filesdna, "View3DShading", "float", "xray_alpha")) {
+                       for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
+                               for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
+                                       for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
+                                               if (sl->spacetype == SPACE_VIEW3D) {
+                                                       View3D *v3d = (View3D *)sl;
+                                                       v3d->shading.xray_alpha = 0.5f;
+                                               }
+                                       }
+                               }
+                       }
+               }
        }
 }
index 12d6296..f335e1a 100644 (file)
@@ -21,18 +21,20 @@ void main()
        float transparent_revealage = texelFetch(transparentRevealage, texel, 0).r;
 #endif
        vec4 color;
+       vec4 bg_color;
 
 #ifdef V3D_SHADING_OBJECT_OUTLINE
        float outline = calculate_object_outline(objectId, texel, object_id);
 #else /* V3D_SHADING_OBJECT_OUTLINE */
        float outline = 1.0;
 #endif /* V3D_SHADING_OBJECT_OUTLINE */
-
+       bg_color = vec4(background_color(world_data, uv_viewport.y), 0.0);
        if (object_id == NO_OBJECT_ID) {
-               color = vec4(background_color(world_data, uv_viewport.y), 0.0);
+               color = bg_color;
        } else {
 #ifdef WORKBENCH_REVEALAGE_ENABLED
                color = vec4((transparent_accum.xyz / max(transparent_accum.a, EPSILON)) * (1.0 - transparent_revealage), 1.0);
+               color = mix(bg_color, color, clamp(1.0 - transparent_revealage, 0.0, 1.0));
 #else
                color = vec4(transparent_accum.xyz / max(transparent_accum.a, EPSILON), 1.0);
 #endif
index 88b32cb..3f271ec 100644 (file)
@@ -2,6 +2,7 @@
 uniform sampler2D image;
 #endif
 uniform mat3 normalWorldMatrix;
+uniform float alpha = 0.5;
 
 #ifdef NORMAL_VIEWPORT_PASS_ENABLED
 in vec3 normal_viewport;
@@ -53,7 +54,6 @@ void main()
 
 #endif /* V3D_LIGHTING_STUDIO */
 
-       float alpha = 0.5       ;
        vec4 premultiplied = vec4(shaded_color.rgb * alpha, alpha);
        transparentAccum = calculate_transparent_accum(premultiplied);
 }
index 279e6a7..50cf567 100644 (file)
@@ -178,6 +178,7 @@ static WORKBENCH_MaterialData *get_or_create_material_data(
                        drawtype == OB_SOLID ? wpd->transparent_accum_sh : wpd->transparent_accum_texture_sh,
                        psl->transparent_accum_pass);
                DRW_shgroup_uniform_block(grp, "world_block", wpd->world_ubo);
+               DRW_shgroup_uniform_float(grp, "alpha", &wpd->shading.xray_alpha, 1);
                workbench_material_set_normal_world_matrix(grp, wpd, e_data.normal_world_matrix);
                material->object_id = engine_object_data->object_id;
                copy_v4_v4(material->material_data.diffuse_color, material_template.material_data.diffuse_color);
@@ -343,6 +344,7 @@ void workbench_forward_engine_init(WORKBENCH_Data *vedata)
                int state = DRW_STATE_WRITE_COLOR | DRW_STATE_TRANSPARENT_REVEALAGE;
                psl->transparent_revealage_pass = DRW_pass_create("Transparent Revealage", state);
                grp = DRW_shgroup_create(e_data.transparent_revealage_sh, psl->transparent_revealage_pass);
+               DRW_shgroup_uniform_float(grp, "alpha", &wpd->shading.xray_alpha, 1);
                wpd->transparent_revealage_shgrp = grp;
        }
 #endif
@@ -546,14 +548,17 @@ void workbench_forward_draw_scene(WORKBENCH_Data *vedata)
        /* Write Depth + Object ID */
        GPU_framebuffer_bind(fbl->object_outline_fb);
        DRW_draw_pass(psl->object_outline_pass);
-
-       /* Shade */
-       GPU_framebuffer_bind(fbl->transparent_accum_fb);
-       DRW_draw_pass(psl->transparent_accum_pass);
+       
+       if (wpd->shading.xray_alpha > 0.0) {
+               /* Shade */
+               GPU_framebuffer_bind(fbl->transparent_accum_fb);
+               DRW_draw_pass(psl->transparent_accum_pass);
 #ifdef WORKBENCH_REVEALAGE_ENABLED
-       GPU_framebuffer_bind(fbl->transparent_revealage_fb);
-       DRW_draw_pass(psl->transparent_revealage_pass);
+               GPU_framebuffer_bind(fbl->transparent_revealage_fb);
+               DRW_draw_pass(psl->transparent_revealage_pass);
 #endif
+       }
+
        /* Composite */
        GPU_framebuffer_bind(fbl->composite_fb);
        DRW_draw_pass(psl->composite_pass);
index fcea40d..605e678 100644 (file)
@@ -325,7 +325,8 @@ static SpaceLink *view3d_new(const ScrArea *UNUSED(sa), const Scene *scene)
        v3d->drawtype = OB_SOLID;
        v3d->shading.flag = V3D_SHADING_SPECULAR_HIGHLIGHT;
        v3d->shading.light = V3D_LIGHTING_STUDIO;
-       v3d->shading.shadow_intensity = 0.5;
+       v3d->shading.shadow_intensity = 0.5f;
+       v3d->shading.xray_alpha = 0.5f;
        copy_v3_fl(v3d->shading.single_color, 0.8f);
 
        v3d->overlay.flag = V3D_OVERLAY_LOOK_DEV;
index 2ef5350..7bb2ce7 100644 (file)
@@ -148,7 +148,7 @@ typedef struct View3DShading {
        float studiolight_background;
 
        float object_outline_color[3];
-       float pad2;
+       float xray_alpha;
 } View3DShading;
 
 /* 3D Viewport Overlay setings */
index a4b9f07..b360143 100644 (file)
@@ -2342,6 +2342,15 @@ static void rna_def_space_view3d_shading(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "X-Ray", "Show whole scene transparent");
        RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
 
+       prop = RNA_def_property(srna, "xray_alpha", PROP_FLOAT, PROP_FACTOR);
+       RNA_def_property_float_sdna(prop, NULL, "shading.xray_alpha");
+       RNA_def_property_float_default(prop, 0.5);
+       RNA_def_property_ui_text(prop, "X-Ray Alpha", "Amount of alpha to use");
+       RNA_def_property_range(prop, 0.0f, 1.0f);
+       RNA_def_property_ui_range(prop, 0.04f, 1.0f, 1, 1);
+       RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
        prop = RNA_def_property(srna, "use_scene_light", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "shading.flag", V3D_SHADING_SCENE_LIGHT);
        RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);