Wireframe: Refactor vertex shader to use less matrices

This means less matrices needs to be prepared by the CPU.
This commit is contained in:
Clément Foucault 2019-05-08 17:12:24 +02:00
parent 8d3e2ffa07
commit 8c5c02932f
Notes: blender-bot 2023-02-14 02:43:26 +01:00
Referenced by issue #64399, Blender crashes when trying to enter edit mode on instanced objects
1 changed files with 21 additions and 33 deletions

View File

@ -1,8 +1,10 @@
uniform mat4 ProjectionMatrix;
uniform mat4 ModelViewMatrix;
uniform mat4 ViewMatrix;
uniform mat4 ViewMatrixInverse;
uniform mat4 ModelMatrix;
uniform mat3 NormalMatrix;
uniform mat4 ModelMatrixInverse;
uniform float wireStepParam;
uniform float ofs;
@ -11,57 +13,43 @@ in vec3 pos;
in vec3 nor;
in float wd; /* wiredata */
float get_edge_sharpness(float wd)
{
#ifndef USE_SCULPT
float get_edge_sharpness(float wd)
{
return ((wd == 0.0) ? -1.5 : wd) + wireStepParam;
}
#else
float get_edge_sharpness(float wd)
{
return 1.0;
}
#endif
}
#define transform_normal_to_world(nor) (transpose(mat3(ModelMatrixInverse)) * nor)
/* Geometry shader version */
#if defined(SELECT_EDGES) || defined(USE_GEOM)
out float facing_g;
out float edgeSharpness_g;
void main()
{
edgeSharpness_g = get_edge_sharpness(wd);
mat4 projmat = ProjectionMatrix;
projmat[3][2] -= ofs;
gl_Position = projmat * (ModelViewMatrix * vec4(pos, 1.0));
facing_g = normalize(NormalMatrix * nor).z;
# ifdef USE_WORLD_CLIP_PLANES
world_clip_planes_calc_clip_distance((ModelMatrix * vec4(pos, 1.0)).xyz);
# endif
}
#else /* USE_GEOM */
out float facing;
flat out float edgeSharpness;
# define facing_g facing
# define edgeSharpness_g edgeSharpness
#endif /* SELECT_EDGES */
void main()
{
edgeSharpness = get_edge_sharpness(wd);
mat4 projmat = ProjectionMatrix;
projmat[3][2] -= ofs;
gl_Position = projmat * (ModelViewMatrix * vec4(pos, 1.0));
vec4 wpos = ModelMatrix * vec4(pos, 1.0);
gl_Position = projmat * (ViewMatrix * wpos);
facing = normalize(NormalMatrix * nor).z;
vec3 wnor = normalize(transform_normal_to_world(nor));
facing_g = dot(wnor, ViewMatrixInverse[2].xyz);
edgeSharpness_g = get_edge_sharpness(wd);
# ifdef USE_WORLD_CLIP_PLANES
world_clip_planes_calc_clip_distance((ModelMatrix * vec4(pos, 1.0)).xyz);
# endif
#ifdef USE_WORLD_CLIP_PLANES
world_clip_planes_calc_clip_distance(wpos.xyz);
#endif
}
#endif /* SELECT_EDGES */