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>2017-03-22 04:14:23 +0300
committerClément Foucault <foucault.clem@gmail.com>2017-03-22 04:17:16 +0300
commit4e92ed87ac7350d0818cf79cb0591d671297d91a (patch)
treec94bb7def1412e2fc56f55d3e7a5c1b7382afd4c /source/blender/draw/modes/shaders/object_outline_expand_frag.glsl
parentc2f3ec437800d78528f00900b56bcd73f38026d8 (diff)
Object Mode Outline: Changed algorithm a bit.
First pass find outline pixel. Second pass expand it by 1px in each direction. Subsequent passes fade the occluded outlines inward.
Diffstat (limited to 'source/blender/draw/modes/shaders/object_outline_expand_frag.glsl')
-rw-r--r--source/blender/draw/modes/shaders/object_outline_expand_frag.glsl60
1 files changed, 18 insertions, 42 deletions
diff --git a/source/blender/draw/modes/shaders/object_outline_expand_frag.glsl b/source/blender/draw/modes/shaders/object_outline_expand_frag.glsl
index 73b9e7f1f0c..b57c4f5ea0e 100644
--- a/source/blender/draw/modes/shaders/object_outline_expand_frag.glsl
+++ b/source/blender/draw/modes/shaders/object_outline_expand_frag.glsl
@@ -4,66 +4,42 @@ in vec4 uvcoordsvar;
out vec4 FragColor;
uniform sampler2D outlineColor;
-#ifdef DEPTH_TEST
uniform sampler2D outlineDepth;
-uniform sampler2D sceneDepth;
-#endif
uniform float alpha;
+uniform bool doExpand;
-#define ALPHA_OCCLU 0.4
-
-void search_outline(ivec2 uv, ivec2 offset, inout float weight, inout vec4 col_accum)
+void search_outline(ivec2 uv, ivec2 offset, inout bool found_edge)
{
- vec4 color = texelFetchOffset(outlineColor, uv, 0, offset).rgba;
- if (color.a != 0.0) {
-#ifdef DEPTH_TEST
- /* Modulate color if occluded */
- /* TODO bias in linear depth not exponential */
- float depth = texelFetchOffset(outlineDepth, uv, 0, offset).r;
- float scene_depth = texelFetchOffset(sceneDepth, uv, 0, offset).r;
- if (depth > scene_depth) {
- color *= ALPHA_OCCLU;
+ if (!found_edge) {
+ vec4 color = texelFetchOffset(outlineColor, uv, 0, offset).rgba;
+ if (color.a != 0.0) {
+ if (doExpand || color.a != 1.0) {
+ FragColor = color;
+ found_edge = true;
+ }
}
-#endif
- col_accum += color;
- weight += 1.0;
}
}
void main()
{
ivec2 uv = ivec2(gl_FragCoord.xy);
- // vec2 uv = uvcoordsvar.xy + 0.5 / viewportSize;
FragColor = texelFetch(outlineColor, uv, 0).rgba;
+ float depth = texelFetch(outlineDepth, uv, 0).r;
- if (FragColor.a != 0.0){
-#ifdef DEPTH_TEST
- /* 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 *= ALPHA_OCCLU;
- }
-#endif
+ if (FragColor.a != 0.0 || (depth == 1.0 && !doExpand))
return;
- }
- float weight = 0.0;
- vec4 col = vec4(0.0);
-
- search_outline(uv, ivec2( 1, 0), weight, col);
- search_outline(uv, ivec2( 0, 1), weight, col);
- search_outline(uv, ivec2(-1, 0), weight, col);
- search_outline(uv, ivec2( 0, -1), weight, col);
+ bool found_edge = false;
+ search_outline(uv, ivec2( 1, 0), found_edge);
+ search_outline(uv, ivec2( 0, 1), found_edge);
+ search_outline(uv, ivec2(-1, 0), found_edge);
+ search_outline(uv, ivec2( 0, -1), found_edge);
/* We Hit something ! */
- if (weight != 0.0) {
- FragColor = col / weight;
+ if (found_edge) {
+ /* only change alpha */
FragColor.a *= alpha;
}
- else {
- FragColor = vec4(0.0);
- }
}