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-20 16:59:27 +0300
committerClément Foucault <foucault.clem@gmail.com>2017-03-20 17:19:03 +0300
commit9ca0e082369eb2ea7cc3ba529805ecd085136398 (patch)
treed21819e2688a2762ef5958dac3a1d3a87f3de0e6 /source/blender/draw/modes/shaders/object_outline_expand_frag.glsl
parentfc72a2ff4b470b1563d8480d231ca5b1b03a7983 (diff)
Object Mode Engine: New outline method.
We render selected meshes into another buffer and use a screen space shader to expand the color out of the mesh silouhette. Pros: only one additionnal render pass is needed (like old outline code), and we have occluded informations. Cons: memory usage is a problem. This method needs 2 color buffer to ping pong when expanding the outline and 1 depth buffer to test occluded fragments. This gives a 88 bits/pix memory footprint. Idea: Since we don't need all color range but only some uniform colors (theme colors) we could manipulate only the color ID instead of the whole color this could cut the color buffer size and lower the memory footprint to 58 bits/pix.
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.glsl69
1 files changed, 69 insertions, 0 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
new file mode 100644
index 00000000000..73b9e7f1f0c
--- /dev/null
+++ b/source/blender/draw/modes/shaders/object_outline_expand_frag.glsl
@@ -0,0 +1,69 @@
+
+in vec4 uvcoordsvar;
+
+out vec4 FragColor;
+
+uniform sampler2D outlineColor;
+#ifdef DEPTH_TEST
+uniform sampler2D outlineDepth;
+uniform sampler2D sceneDepth;
+#endif
+
+uniform float alpha;
+
+#define ALPHA_OCCLU 0.4
+
+void search_outline(ivec2 uv, ivec2 offset, inout float weight, inout vec4 col_accum)
+{
+ 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;
+ }
+#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;
+
+ 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
+ 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);
+
+ /* We Hit something ! */
+ if (weight != 0.0) {
+ FragColor = col / weight;
+ FragColor.a *= alpha;
+ }
+ else {
+ FragColor = vec4(0.0);
+ }
+}