diff options
Diffstat (limited to 'source/blender/draw/modes/shaders/overlay_face_wireframe_geom.glsl')
-rw-r--r-- | source/blender/draw/modes/shaders/overlay_face_wireframe_geom.glsl | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/source/blender/draw/modes/shaders/overlay_face_wireframe_geom.glsl b/source/blender/draw/modes/shaders/overlay_face_wireframe_geom.glsl index 1cea418419e..8f5712cca03 100644 --- a/source/blender/draw/modes/shaders/overlay_face_wireframe_geom.glsl +++ b/source/blender/draw/modes/shaders/overlay_face_wireframe_geom.glsl @@ -1,7 +1,12 @@ +/* This shader is only used for intel GPU where the Geom shader is faster + * than doing everything thrice in the vertex shader. */ + layout(triangles) in; layout(triangle_strip, max_vertices = 3) out; +uniform vec2 wireStepParam; + in vec2 ssPos[]; in float facingOut[]; @@ -10,8 +15,16 @@ flat out vec3 ssVec1; flat out vec3 ssVec2; out float facing; +#ifdef LIGHT_EDGES +in vec3 obPos[]; +in vec3 edgeAdj[]; + +flat out vec3 edgeSharpness; +#endif + #define NO_EDGE vec3(10000.0); +/* TODO(fclem) remove code duplication. */ vec3 compute_vec(vec2 v0, vec2 v1) { vec2 v = normalize(v1 - v0); @@ -19,6 +32,13 @@ vec3 compute_vec(vec2 v0, vec2 v1) return vec3(v, -dot(v, v0)); } +float get_edge_sharpness(vec3 e0, vec3 e1, vec3 e2) +{ + vec3 n0 = normalize(cross(e0, e1)); + vec3 n1 = normalize(cross(e1, e2)); + return dot(n0, n1); +} + void main(void) { vec3 facings = vec3(facingOut[0], facingOut[1], facingOut[2]); @@ -29,6 +49,20 @@ void main(void) ssVec1 = do_edge.y ? compute_vec(ssPos[1], ssPos[2]) : NO_EDGE; ssVec2 = do_edge.z ? compute_vec(ssPos[2], ssPos[0]) : NO_EDGE; +#ifdef LIGHT_EDGES + vec3 edges[3]; + edges[0] = obPos[1] - obPos[0]; + edges[1] = obPos[2] - obPos[1]; + edges[2] = obPos[0] - obPos[2]; + + edgeSharpness.x = get_edge_sharpness(edgeAdj[0] - obPos[0], edges[0], -edges[2]); + edgeSharpness.y = get_edge_sharpness(edgeAdj[1] - obPos[1], edges[1], -edges[0]); + edgeSharpness.z = get_edge_sharpness(edgeAdj[2] - obPos[2], edges[2], -edges[1]); + + /* Easy to adjust parameters. */ + edgeSharpness = smoothstep(wireStepParam.xxx, wireStepParam.yyy, edgeSharpness); +#endif + gl_Position = gl_in[0].gl_Position; facing = facings.x; EmitVertex(); |