2024-04-11 20:40:28 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
#include <string>
|
|
|
|
const std::string shader_2d_line_vert = R"("
|
2024-04-12 00:10:29 -04:00
|
|
|
#version 460
|
2024-04-11 20:40:28 -04:00
|
|
|
|
2024-04-12 00:10:29 -04:00
|
|
|
layout(std430, binding = 0) buffer TVertex
|
|
|
|
{
|
|
|
|
vec4 vertex[];
|
|
|
|
};
|
2024-04-11 20:40:28 -04:00
|
|
|
|
|
|
|
layout (std140) uniform GlobalMatrices
|
|
|
|
{
|
|
|
|
mat4 projection;
|
|
|
|
mat4 ortho;
|
|
|
|
mat4 view;
|
|
|
|
mat4 pvm;
|
|
|
|
mat4 ovm;
|
|
|
|
};
|
2024-04-12 00:10:29 -04:00
|
|
|
uniform vec2 u_resolution;
|
|
|
|
uniform float u_thickness;
|
2024-04-11 20:40:28 -04:00
|
|
|
|
2024-04-12 00:10:29 -04:00
|
|
|
void main()
|
|
|
|
{
|
|
|
|
int line_i = gl_VertexID / 6;
|
|
|
|
int tri_i = gl_VertexID % 6;
|
2024-04-11 20:40:28 -04:00
|
|
|
|
2024-04-12 00:10:29 -04:00
|
|
|
vec4 va[4];
|
|
|
|
for (int i=0; i<4; ++i)
|
|
|
|
{
|
|
|
|
va[i] = ovm * vertex[line_i+i];
|
|
|
|
va[i].xyz /= va[i].w;
|
|
|
|
va[i].xy = (va[i].xy + 1.0) * 0.5 * u_resolution;
|
|
|
|
}
|
2024-04-11 20:40:28 -04:00
|
|
|
|
2024-04-12 00:10:29 -04:00
|
|
|
vec2 v_line = normalize(va[2].xy - va[1].xy);
|
|
|
|
vec2 nv_line = vec2(-v_line.y, v_line.x);
|
|
|
|
|
|
|
|
vec4 pos;
|
|
|
|
if (tri_i == 0 || tri_i == 1 || tri_i == 3)
|
|
|
|
{
|
|
|
|
vec2 v_pred = normalize(va[1].xy - va[0].xy);
|
|
|
|
vec2 v_miter = normalize(nv_line + vec2(-v_pred.y, v_pred.x));
|
|
|
|
|
|
|
|
pos = va[1];
|
|
|
|
pos.xy += v_miter * u_thickness * (tri_i == 1 ? -0.5 : 0.5) / dot(v_miter, nv_line);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
vec2 v_succ = normalize(va[3].xy - va[2].xy);
|
|
|
|
vec2 v_miter = normalize(nv_line + vec2(-v_succ.y, v_succ.x));
|
|
|
|
|
|
|
|
pos = va[2];
|
|
|
|
pos.xy += v_miter * u_thickness * (tri_i == 5 ? 0.5 : -0.5) / dot(v_miter, nv_line);
|
|
|
|
}
|
|
|
|
|
|
|
|
pos.xy = pos.xy / u_resolution * 2.0 - 1.0;
|
|
|
|
pos.xyz *= pos.w;
|
|
|
|
gl_Position = pos;
|
|
|
|
}
|
2024-04-11 20:40:28 -04:00
|
|
|
")";
|
|
|
|
#endif
|