<@include gpu/Config.slh@> <$VERSION_HEADER$> <@include DeferredTransform.slh@> <$declareDeferredFrameTransform()$> <@include Highlight_shared.slh@> uniform highlightParamsBuffer { HighlightParameters params; }; uniform sampler2D sceneDepthMap; uniform sampler2D highlightedDepthMap; in vec2 varTexCoord0; out vec4 outFragColor; const float FAR_Z = 1.0; const float LINEAR_DEPTH_BIAS = 5e-3; const float OPACITY_EPSILON = 5e-3; <@func main(IS_FILLED)@> void main(void) { // We offset by half a texel to be centered on the depth sample. If we don't do this // the blur will have a different width between the left / right sides and top / bottom // sides of the silhouette float highlightedDepth = texture(highlightedDepthMap, varTexCoord0).x; float intensity = 0.0; if (highlightedDepth < FAR_Z) { // We're not on the far plane so we are on the highlighted object, thus no outline to do! <@if IS_FILLED@> // But we need to fill the interior float sceneDepth = texture(sceneDepthMap, varTexCoord0).x; // Transform to linear depth for better precision highlightedDepth = -evalZeyeFromZdb(highlightedDepth); sceneDepth = -evalZeyeFromZdb(sceneDepth); // Are we occluded? intensity = sceneDepth < (highlightedDepth-LINEAR_DEPTH_BIAS) ? params._occludedFillOpacity : params._unoccludedFillOpacity; <@else@> discard; <@endif@> } else { vec2 halfTexel = getInvWidthHeight() / 2; vec2 texCoord0 = varTexCoord0+halfTexel; float weight = 0.0; vec2 deltaUv = params._size / params._blurKernelSize; vec2 lineStartUv = texCoord0 - params._size / 2.0; vec2 uv; int x; int y; for (y=0 ; y=0.0 && uv.y<=1.0) { for (x=0 ; x=0.0 && uv.x<=1.0) { highlightedDepth = texture(highlightedDepthMap, uv).x; intensity += (highlightedDepth < FAR_Z) ? 1.0 : 0.0; weight += 1.0; } uv.x += deltaUv.x; } } } intensity /= weight; if (intensity < OPACITY_EPSILON) { discard; } intensity = min(1.0, intensity / params._threshold) * params._intensity; } outFragColor = vec4(params._color.rgb, intensity); } <@endfunc@>