Overlay: Add antialiasing to particle sprites

This commit is contained in:
Clément Foucault 2020-03-09 17:09:01 +01:00
parent 3912a2a227
commit 29b405a327
2 changed files with 10 additions and 3 deletions

View File

@ -1246,7 +1246,7 @@ GPUShader *OVERLAY_shader_particle_dot(void)
datatoc_common_view_lib_glsl,
datatoc_particle_vert_glsl,
NULL},
.frag = (const char *[]){datatoc_particle_frag_glsl, NULL},
.frag = (const char *[]){datatoc_common_view_lib_glsl, datatoc_particle_frag_glsl, NULL},
.defs = (const char *[]){sh_cfg->def, "#define USE_DOTS\n", NULL},
});
}

View File

@ -6,7 +6,8 @@ layout(location = 1) out vec4 lineOutput;
void main()
{
float dist = length(gl_PointCoord - vec2(0.5));
vec2 uv = gl_PointCoord - vec2(0.5);
float dist = length(uv);
if (dist > 0.5) {
discard;
@ -15,5 +16,11 @@ void main()
float intensity = sqrt(1.0 - dist * 2.0) * 0.5 + 0.5;
fragColor = finalColor * vec4(intensity, intensity, intensity, 1.0);
lineOutput = vec4(0.0);
/* The default value of GL_POINT_SPRITE_COORD_ORIGIN is GL_UPPER_LEFT. Need to reverse the Y. */
uv.y = -uv.y;
/* Subtract distance to outer edge of the circle. (0.75 is manually tweaked to look better) */
vec2 edge_pos = gl_FragCoord.xy - uv * (0.75 / (dist + 1e-9));
vec2 edge_start = edge_pos + vec2(-uv.y, uv.x);
lineOutput = pack_line_data(gl_FragCoord.xy, edge_start, edge_pos);
}