Welcome to mirror list, hosted at ThFree Co, Russian Federation.

object_outline_expand_frag.glsl « shaders « modes « draw « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e0568d1157ab63a646b46bfaee3ea59db93ffedc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

in vec4 uvcoordsvar;

out vec4 FragColor;

uniform sampler2D outlineColor;
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;

	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 (found_edge) {
		/* only change alpha */
		FragColor.a *= alpha;
	}
}