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-08-10 00:51:00 +0300
committerClément Foucault <foucault.clem@gmail.com>2017-08-10 16:43:48 +0300
commit2ba11d72a2cfcdb7639de1e8a20a6ec587d38a1f (patch)
treebb0e627affe5e3df4fc68693df12757a8e859882 /source/blender/draw/modes/shaders/object_outline_expand_frag.glsl
parent7641f92710a09ea089748896bbad0bf5383ba349 (diff)
Object Mode Engine: Optimize outline passes.
Group texture fetches to hide latency. 3.2ms -> 2.2ms (constant time improvement, not depending on scene complexity) Could optimize further with textureGather (require OpenGL 4.0).
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.glsl43
1 files changed, 18 insertions, 25 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 e0568d1157a..c753e3ab39c 100644
--- a/source/blender/draw/modes/shaders/object_outline_expand_frag.glsl
+++ b/source/blender/draw/modes/shaders/object_outline_expand_frag.glsl
@@ -9,37 +9,30 @@ uniform sampler2D outlineDepth;
uniform float alpha;
uniform bool doExpand;
-void search_outline(ivec2 uv, inout bool found_edge)
-{
- if (!found_edge) {
- vec4 color = texelFetch(outlineColor, uv, 0).rgba;
- if (color.a != 0.0) {
- if (doExpand || color.a != 1.0) {
- FragColor = color;
- found_edge = true;
- }
- }
- }
-}
-
void main()
{
ivec2 uv = ivec2(gl_FragCoord.xy);
FragColor = texelFetch(outlineColor, uv, 0).rgba;
float depth = texelFetch(outlineDepth, uv, 0).r;
- if (FragColor.a != 0.0 || (depth == 1.0 && !doExpand))
- return;
+ vec4 color[4];
+ color[0] = texelFetchOffset(outlineColor, uv, 0, ivec2( 1, 0)).rgba;
+ color[1] = texelFetchOffset(outlineColor, uv, 0, ivec2( 0, 1)).rgba;
+ color[2] = texelFetchOffset(outlineColor, uv, 0, ivec2(-1, 0)).rgba;
+ color[3] = texelFetchOffset(outlineColor, uv, 0, ivec2( 0, -1)).rgba;
+
+ vec4 values = vec4(color[0].a, color[1].a, color[2].a, color[3].a);
+
+ bool is_blank_pixel = !(FragColor.a != 0.0 || (depth == 1.0 && !doExpand));
+ vec4 tests = vec4(is_blank_pixel);
+ tests *= step(vec4(1e-6), values); /* (color.a != 0.0) */
+ tests *= (doExpand) ? vec4(1.0) : step(values, vec4(0.999)); /* (doExpand || color.a != 1.0) */
+ bvec4 btests = equal(tests, vec4(1.0));
- 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);
+ FragColor = (btests.x) ? color[0] : FragColor;
+ FragColor = (btests.y) ? color[1] : FragColor;
+ FragColor = (btests.z) ? color[2] : FragColor;
+ FragColor = (btests.w) ? color[3] : FragColor;
- /* We Hit something ! */
- if (found_edge) {
- /* only change alpha */
- FragColor.a *= alpha;
- }
+ FragColor *= (is_blank_pixel) ? alpha : 1.0;
}