This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/source/blender/draw/modes/shaders/object_outline_detect_frag.glsl

62 lines
1.3 KiB
GLSL
Raw Normal View History

2017-03-21 19:29:58 +01:00
in vec4 uvcoordsvar;
out vec4 FragColor;
uniform sampler2D outlineColor;
uniform sampler2D outlineDepth;
uniform sampler2D sceneDepth;
uniform float alphaOcclu;
uniform vec2 viewportSize;
2017-03-21 19:29:58 +01:00
2017-03-28 00:05:41 +02:00
void search_outline(ivec2 uv, vec4 ref_col, inout bool ref_occlu, inout bool outline)
2017-03-21 19:29:58 +01:00
{
if (!outline) {
2017-03-28 00:05:41 +02:00
vec4 color = texelFetch(outlineColor, uv, 0).rgba;
2017-03-21 19:29:58 +01:00
if (color != ref_col) {
outline = true;
}
else {
2017-03-28 00:05:41 +02:00
float depth = texelFetch(outlineDepth, uv, 0).r;
float scene_depth = texelFetch(sceneDepth, uv, 0).r;
bool occlu = (depth > scene_depth);
if (occlu != ref_occlu && !ref_occlu) {
outline = true;
}
}
2017-03-21 19:29:58 +01:00
}
}
void main()
{
ivec2 uv = ivec2(gl_FragCoord.xy);
vec4 ref_col = texelFetch(outlineColor, uv, 0).rgba;
float depth = texelFetch(outlineDepth, uv, 0).r;
/* Modulate color if occluded */
float scene_depth = texelFetch(sceneDepth, uv, 0).r;
bool ref_occlu = (depth > scene_depth);
2017-03-21 19:29:58 +01:00
bool outline = false;
2017-03-28 00:05:41 +02:00
search_outline(uv + ivec2( 1, 0), ref_col, ref_occlu, outline);
search_outline(uv + ivec2( 0, 1), ref_col, ref_occlu, outline);
search_outline(uv + ivec2(-1, 0), ref_col, ref_occlu, outline);
search_outline(uv + ivec2( 0, -1), ref_col, ref_occlu, outline);
FragColor = ref_col;
2017-03-21 19:29:58 +01:00
/* We Hit something ! */
if (outline) {
if (ref_occlu) {
2017-03-21 19:29:58 +01:00
FragColor.a *= alphaOcclu;
}
}
else {
FragColor.a = 0.0;
2017-03-21 19:29:58 +01:00
}
}