Commit: 7870bde275a23b78198dc9d943e8dfe7a05a8b01 Author: Clément Foucault Date: Tue Mar 21 19:29:58 2017 +0100 Branches: blender2.8 https://developer.blender.org/rB7870bde275a23b78198dc9d943e8dfe7a05a8b01
Object Outline: trying something new =================================================================== M source/blender/draw/CMakeLists.txt M source/blender/draw/modes/object_mode.c A source/blender/draw/modes/shaders/object_outline_detect_frag.glsl M source/blender/draw/modes/shaders/object_outline_resolve_frag.glsl =================================================================== diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt index ced4aa01e2..f8f1408f94 100644 --- a/source/blender/draw/CMakeLists.txt +++ b/source/blender/draw/CMakeLists.txt @@ -117,6 +117,7 @@ data_to_c_simple(modes/shaders/edit_normals_vert.glsl SRC) data_to_c_simple(modes/shaders/edit_normals_geom.glsl SRC) data_to_c_simple(modes/shaders/object_outline_resolve_frag.glsl SRC) data_to_c_simple(modes/shaders/object_outline_expand_frag.glsl SRC) +data_to_c_simple(modes/shaders/object_outline_detect_frag.glsl SRC) list(APPEND INC ) diff --git a/source/blender/draw/modes/object_mode.c b/source/blender/draw/modes/object_mode.c index 33ecde5fd7..aee443895b 100644 --- a/source/blender/draw/modes/object_mode.c +++ b/source/blender/draw/modes/object_mode.c @@ -45,6 +45,7 @@ extern GlobalsUboStorage ts; extern char datatoc_object_outline_resolve_frag_glsl[]; +extern char datatoc_object_outline_detect_frag_glsl[]; extern char datatoc_object_outline_expand_frag_glsl[]; /* *********** LISTS *********** */ @@ -178,7 +179,7 @@ static void OBJECT_engine_init(void) } if (!e_data.outline_expand_sh) { - e_data.outline_expand_sh = DRW_shader_create_fullscreen(datatoc_object_outline_expand_frag_glsl, "#define DEPTH_TEST"); + e_data.outline_expand_sh = DRW_shader_create_fullscreen(datatoc_object_outline_detect_frag_glsl, NULL); } if (!e_data.outline_fade_sh) { @@ -235,7 +236,7 @@ static void OBJECT_cache_init(void) psl->outlines_expand = DRW_pass_create("Outlines Expand Pass", state); struct Batch *quad = DRW_cache_fullscreen_quad_get(); - static float one = 1.0f; + static float alphaOcclu = 0.35f; static float alphaNear = 0.75f; static float alphaFar = 0.5f; @@ -243,7 +244,7 @@ static void OBJECT_cache_init(void) DRW_shgroup_uniform_buffer(grp, "outlineColor", &txl->outlines_color_tx, 0); DRW_shgroup_uniform_buffer(grp, "outlineDepth", &txl->outlines_depth_tx, 1); DRW_shgroup_uniform_buffer(grp, "sceneDepth", &dtxl->depth, 2); - DRW_shgroup_uniform_float(grp, "alpha", &one, 1); + DRW_shgroup_uniform_float(grp, "alphaOcclu", &alphaOcclu, 1); DRW_shgroup_call_add(grp, quad, NULL); psl->outlines_blur1 = DRW_pass_create("Outlines Blur 1 Pass", state); @@ -743,7 +744,6 @@ static void OBJECT_draw_scene(void) OBJECT_PassList *psl = ved->psl; OBJECT_FramebufferList *fbl = ved->fbl; DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get(); - DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); float clearcol[4] = {0.0f, 0.0f, 0.0f, 0.0f}; DRW_draw_pass(psl->bone_wire); @@ -767,11 +767,11 @@ static void OBJECT_draw_scene(void) DRW_framebuffer_bind(fbl->blur); DRW_draw_pass(psl->outlines_blur2); - DRW_framebuffer_bind(fbl->outlines); - DRW_draw_pass(psl->outlines_blur3); + // DRW_framebuffer_bind(fbl->outlines); + // DRW_draw_pass(psl->outlines_blur3); - DRW_framebuffer_bind(fbl->blur); - DRW_draw_pass(psl->outlines_blur4); + // DRW_framebuffer_bind(fbl->blur); + // DRW_draw_pass(psl->outlines_blur4); /* Combine with scene buffer */ DRW_framebuffer_bind(dfbl->default_fb); diff --git a/source/blender/draw/modes/shaders/object_outline_detect_frag.glsl b/source/blender/draw/modes/shaders/object_outline_detect_frag.glsl new file mode 100644 index 0000000000..fc40a7dd1d --- /dev/null +++ b/source/blender/draw/modes/shaders/object_outline_detect_frag.glsl @@ -0,0 +1,48 @@ + +in vec4 uvcoordsvar; + +out vec4 FragColor; + +uniform sampler2D outlineColor; +uniform sampler2D outlineDepth; +uniform sampler2D sceneDepth; + +uniform float alphaOcclu; + +void search_outline(ivec2 uv, ivec2 offset, vec4 ref_col, inout bool outline) +{ + if (!outline) { + vec4 color = texelFetchOffset(outlineColor, uv, 0, offset).rgba; + if (color != ref_col) { + outline = true; + } + } +} + +void main() +{ + ivec2 uv = ivec2(gl_FragCoord.xy); + vec4 ref_col = texelFetch(outlineColor, uv, 0).rgba; + + bool outline = false; + + search_outline(uv, ivec2( 1, 0), ref_col, outline); + search_outline(uv, ivec2( 0, 1), ref_col, outline); + search_outline(uv, ivec2(-1, 0), ref_col, outline); + search_outline(uv, ivec2( 0, -1), ref_col, outline); + + /* We Hit something ! */ + if (outline) { + FragColor = ref_col; + /* Modulate color if occluded */ + float depth = texelFetch(outlineDepth, uv, 0).r; + float scene_depth = texelFetch(sceneDepth, uv, 0).r; + /* TODO bias in linear depth not exponential */ + if (depth > scene_depth) { + FragColor.a *= alphaOcclu; + } + } + else { + FragColor = vec4(0.0); + } +} diff --git a/source/blender/draw/modes/shaders/object_outline_resolve_frag.glsl b/source/blender/draw/modes/shaders/object_outline_resolve_frag.glsl index 9c1ecbbdc9..12f375369b 100644 --- a/source/blender/draw/modes/shaders/object_outline_resolve_frag.glsl +++ b/source/blender/draw/modes/shaders/object_outline_resolve_frag.glsl @@ -11,7 +11,7 @@ void main() FragColor = texture(outlineBluredColor, uvcoordsvar.st).rgba; /* Modulate fill color */ - float depth = texture(outlineDepth, uvcoordsvar.st).r; - if (depth != 1.0) - FragColor.a *= 0.1; + // float depth = texture(outlineDepth, uvcoordsvar.st).r; + // if (depth != 1.0) + // FragColor.a *= 0.1; } _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs