The shader is way simpler and run way faster on lower end hardware
(2x faster on intel HD5000) but did not notice any improvement on AMD Vega.
This also adds a few changes to the way the wireframes are drawn:
- the slider is more linearly progressive.
- optimize display shows all wires and progressively decrease "inner" wires
intensity. This is subject to change in the future.
- text/surface/metaballs support is pretty rough. More work needs to be done.
This remove the optimization introduced in f1975a4639.
This also removes the GPU side "sharpness" calculation which means that
animated meshes with wireframe display will update slower.
The CPU sharpness calculation has still room for optimization. Also
it is not excluded that GPU calculation can be added back as a
separate preprocessing pass (saving the computation result [compute or
feedback]).
The goal here was to have more speed for static objects and remove
the dependency of having buffer textures with triangle count. This is
preparation work for multithreading the whole DRW manager.
82 lines
1.8 KiB
GLSL
82 lines
1.8 KiB
GLSL
|
|
uniform mat4 ModelViewProjectionMatrix;
|
|
uniform mat3 NormalMatrix;
|
|
|
|
uniform vec2 wireStepParam;
|
|
|
|
vec3 get_edge_sharpness(vec3 wd)
|
|
{
|
|
bvec3 do_edge = greaterThan(wd, vec3(0.0));
|
|
bvec3 force_edge = equal(wd, vec3(1.0));
|
|
wd = clamp(wireStepParam.x * wd + wireStepParam.y, 0.0, 1.0);
|
|
return clamp(wd * vec3(do_edge) + vec3(force_edge), 0.0, 1.0);
|
|
}
|
|
|
|
float get_edge_sharpness(float wd)
|
|
{
|
|
bool do_edge = (wd > 0.0);
|
|
bool force_edge = (wd == 1.0);
|
|
wd = (wireStepParam.x * wd + wireStepParam.y);
|
|
return clamp(wd * float(do_edge) + float(force_edge), 0.0, 1.0);
|
|
}
|
|
|
|
/* Geometry shader version */
|
|
#if defined(SELECT_EDGES) || defined(USE_SCULPT)
|
|
|
|
in vec3 pos;
|
|
in vec3 nor;
|
|
in float wd; /* wiredata */
|
|
|
|
out float facing_g;
|
|
out float edgeSharpness_g;
|
|
|
|
void main()
|
|
{
|
|
# ifndef USE_SCULPT
|
|
edgeSharpness_g = get_edge_sharpness(wd);
|
|
# else
|
|
/* TODO approximation using normals. */
|
|
edgeSharpness_g = 1.0;
|
|
# endif
|
|
|
|
gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
|
|
|
|
facing_g = normalize(NormalMatrix * nor).z;
|
|
}
|
|
|
|
#else /* SELECT_EDGES */
|
|
|
|
/* Consecutive pos of the nth vertex
|
|
* Only valid for first vertex in the triangle.
|
|
* Assuming GL_FRIST_VERTEX_CONVENTION. */
|
|
in vec3 pos0;
|
|
in vec3 pos1;
|
|
in vec3 pos2;
|
|
in float wd0; /* wiredata */
|
|
in float wd1;
|
|
in float wd2;
|
|
in vec3 nor;
|
|
|
|
out float facing;
|
|
out vec3 barycentric;
|
|
flat out vec3 edgeSharpness;
|
|
|
|
void main()
|
|
{
|
|
int v_n = gl_VertexID % 3;
|
|
|
|
barycentric = vec3(equal(ivec3(2, 0, 1), ivec3(v_n)));
|
|
|
|
vec3 wb = vec3(wd0, wd1, wd2);
|
|
edgeSharpness = get_edge_sharpness(wb);
|
|
|
|
/* Don't generate any fragment if there is no edge to draw. */
|
|
vec3 pos = (!any(greaterThan(edgeSharpness, vec3(0.04))) && (v_n == 0)) ? pos1 : pos0;
|
|
|
|
gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
|
|
|
|
facing = normalize(NormalMatrix * nor).z;
|
|
}
|
|
|
|
#endif /* SELECT_EDGES */
|