This is the unification of all overlays into one overlay engine as described in T65347. I went over all the code making it more future proof with less hacks and removing old / not relevent parts. Goals / Acheivements: - Remove internal shader usage (only drw shaders) - Remove viewportSize and viewportSizeInv and put them in gloabl ubo - Fixed some drawing issues: Missing probe option and Missing Alt+B clipping of some shader - Remove old (legacy) shaders dependancy (not using view UBO). - Less shader variation (less compilation time at first load and less patching needed for vulkan) - removed some geom shaders when I could - Remove static e_data (except shaders storage where it is OK) - Clear the way to fix some anoying limitations (dithered transparency, background image compositing etc...) - Wireframe drawing now uses the same batching capabilities as workbench & eevee (indirect drawing). - Reduced complexity, removed ~3000 Lines of code in draw (also removed a lot of unused shader in GPU). - Post AA to avoid complexity and cost of MSAA. Remaining issues: - ~~Armature edits, overlay toggles, (... others?) are not refreshing viewport after AA is complete~~ - FXAA is not the best for wires, maybe investigate SMAA - Maybe do something more temporally stable for AA. - ~~Paint overlays are not working with AA.~~ - ~~infront objects are difficult to select.~~ - ~~the infront wires sometimes goes through they solid counterpart (missing clear maybe?) (toggle overlays on-off when using infront+wireframe overlay in solid shading)~~ Note: I made some decision to change slightly the appearance of some objects to simplify their drawing. Namely the empty arrows end (which is now hollow/wire) and distance points of the cameras/spots being done by lines. Reviewed By: jbakker Differential Revision: https://developer.blender.org/D6296
47 lines
1.5 KiB
GLSL
47 lines
1.5 KiB
GLSL
|
|
#define M_1_SQRTPI 0.5641895835477563 /* 1/sqrt(pi) */
|
|
|
|
/**
|
|
* We want to know how much a pixel is covered by a line.
|
|
* We replace the square pixel with acircle of the same area and try to find the intersection area.
|
|
* The area we search is the circular segment. https://en.wikipedia.org/wiki/Circular_segment
|
|
* The formula for the area uses inverse trig function and is quite complexe. Instead,
|
|
* we approximate it by using the smoothstep function and a 1.05 factor to the disc radius.
|
|
*/
|
|
#define DISC_RADIUS (M_1_SQRTPI * 1.05)
|
|
#define GRID_LINE_SMOOTH_START (0.5 - DISC_RADIUS)
|
|
#define GRID_LINE_SMOOTH_END (0.5 + DISC_RADIUS)
|
|
|
|
uniform sampler2D depthTex;
|
|
uniform float alpha = 1.0;
|
|
|
|
flat in vec4 finalColorOuter_f;
|
|
in vec4 finalColor_f;
|
|
noperspective in float edgeCoord_f;
|
|
|
|
out vec4 FragColor;
|
|
|
|
bool test_occlusion()
|
|
{
|
|
return gl_FragCoord.z > texelFetch(depthTex, ivec2(gl_FragCoord.xy), 0).r;
|
|
}
|
|
|
|
void main()
|
|
{
|
|
float dist = abs(edgeCoord_f) - max(sizeEdge - 0.5, 0.0);
|
|
float dist_outer = dist - max(sizeEdge, 1.0);
|
|
#ifdef USE_SMOOTH_WIRE
|
|
float mix_w = smoothstep(GRID_LINE_SMOOTH_START, GRID_LINE_SMOOTH_END, dist);
|
|
float mix_w_outer = smoothstep(GRID_LINE_SMOOTH_START, GRID_LINE_SMOOTH_END, dist_outer);
|
|
#else
|
|
float mix_w = step(0.5, dist);
|
|
float mix_w_outer = step(0.5, dist_outer);
|
|
#endif
|
|
/* Line color & alpha. */
|
|
FragColor = mix(finalColorOuter_f, finalColor_f, 1.0 - mix_w * finalColorOuter_f.a);
|
|
/* Line edges shape. */
|
|
FragColor.a *= 1.0 - (finalColorOuter_f.a > 0.0 ? mix_w_outer : mix_w);
|
|
|
|
FragColor.a *= test_occlusion() ? alpha : 1.0;
|
|
}
|