Cleanup: GPUShader: Remove unused edge fancy shader
This commit is contained in:
@@ -178,7 +178,6 @@ data_to_c_simple(shaders/gpu_shader_3D_image_vert.glsl SRC)
|
|||||||
data_to_c_simple(shaders/gpu_shader_3D_vert.glsl SRC)
|
data_to_c_simple(shaders/gpu_shader_3D_vert.glsl SRC)
|
||||||
data_to_c_simple(shaders/gpu_shader_3D_normal_vert.glsl SRC)
|
data_to_c_simple(shaders/gpu_shader_3D_normal_vert.glsl SRC)
|
||||||
data_to_c_simple(shaders/gpu_shader_3D_flat_color_vert.glsl SRC)
|
data_to_c_simple(shaders/gpu_shader_3D_flat_color_vert.glsl SRC)
|
||||||
data_to_c_simple(shaders/gpu_shader_3D_line_dashed_uniform_color_legacy_vert.glsl SRC)
|
|
||||||
data_to_c_simple(shaders/gpu_shader_3D_line_dashed_uniform_color_vert.glsl SRC)
|
data_to_c_simple(shaders/gpu_shader_3D_line_dashed_uniform_color_vert.glsl SRC)
|
||||||
data_to_c_simple(shaders/gpu_shader_3D_smooth_color_vert.glsl SRC)
|
data_to_c_simple(shaders/gpu_shader_3D_smooth_color_vert.glsl SRC)
|
||||||
data_to_c_simple(shaders/gpu_shader_3D_normal_smooth_color_vert.glsl SRC)
|
data_to_c_simple(shaders/gpu_shader_3D_normal_smooth_color_vert.glsl SRC)
|
||||||
@@ -225,14 +224,6 @@ data_to_c_simple(shaders/gpu_shader_2D_edituvs_stretch_vert.glsl SRC)
|
|||||||
data_to_c_simple(shaders/gpu_shader_3D_selection_id_vert.glsl SRC)
|
data_to_c_simple(shaders/gpu_shader_3D_selection_id_vert.glsl SRC)
|
||||||
data_to_c_simple(shaders/gpu_shader_selection_id_frag.glsl SRC)
|
data_to_c_simple(shaders/gpu_shader_selection_id_frag.glsl SRC)
|
||||||
|
|
||||||
data_to_c_simple(shaders/gpu_shader_edges_front_back_persp_vert.glsl SRC)
|
|
||||||
data_to_c_simple(shaders/gpu_shader_edges_front_back_persp_geom.glsl SRC)
|
|
||||||
data_to_c_simple(shaders/gpu_shader_edges_front_back_persp_legacy_vert.glsl SRC)
|
|
||||||
data_to_c_simple(shaders/gpu_shader_edges_front_back_ortho_vert.glsl SRC)
|
|
||||||
data_to_c_simple(shaders/gpu_shader_edges_overlay_vert.glsl SRC)
|
|
||||||
data_to_c_simple(shaders/gpu_shader_edges_overlay_geom.glsl SRC)
|
|
||||||
data_to_c_simple(shaders/gpu_shader_edges_overlay_simple_geom.glsl SRC)
|
|
||||||
data_to_c_simple(shaders/gpu_shader_edges_overlay_frag.glsl SRC)
|
|
||||||
data_to_c_simple(shaders/gpu_shader_text_simple_vert.glsl SRC)
|
data_to_c_simple(shaders/gpu_shader_text_simple_vert.glsl SRC)
|
||||||
data_to_c_simple(shaders/gpu_shader_text_simple_geom.glsl SRC)
|
data_to_c_simple(shaders/gpu_shader_text_simple_geom.glsl SRC)
|
||||||
data_to_c_simple(shaders/gpu_shader_text_vert.glsl SRC)
|
data_to_c_simple(shaders/gpu_shader_text_vert.glsl SRC)
|
||||||
|
@@ -100,10 +100,6 @@ typedef enum eGPUBuiltinShader {
|
|||||||
/* specialized drawing */
|
/* specialized drawing */
|
||||||
GPU_SHADER_TEXT,
|
GPU_SHADER_TEXT,
|
||||||
GPU_SHADER_TEXT_SIMPLE,
|
GPU_SHADER_TEXT_SIMPLE,
|
||||||
GPU_SHADER_EDGES_FRONT_BACK_PERSP,
|
|
||||||
GPU_SHADER_EDGES_FRONT_BACK_ORTHO,
|
|
||||||
GPU_SHADER_EDGES_OVERLAY_SIMPLE,
|
|
||||||
GPU_SHADER_EDGES_OVERLAY,
|
|
||||||
GPU_SHADER_KEYFRAME_DIAMOND,
|
GPU_SHADER_KEYFRAME_DIAMOND,
|
||||||
GPU_SHADER_SIMPLE_LIGHTING,
|
GPU_SHADER_SIMPLE_LIGHTING,
|
||||||
GPU_SHADER_SIMPLE_LIGHTING_FLAT_COLOR,
|
GPU_SHADER_SIMPLE_LIGHTING_FLAT_COLOR,
|
||||||
|
@@ -145,17 +145,8 @@ extern char datatoc_gpu_shader_selection_id_frag_glsl[];
|
|||||||
extern char datatoc_gpu_shader_2D_line_dashed_uniform_color_vert_glsl[];
|
extern char datatoc_gpu_shader_2D_line_dashed_uniform_color_vert_glsl[];
|
||||||
extern char datatoc_gpu_shader_2D_line_dashed_frag_glsl[];
|
extern char datatoc_gpu_shader_2D_line_dashed_frag_glsl[];
|
||||||
extern char datatoc_gpu_shader_2D_line_dashed_geom_glsl[];
|
extern char datatoc_gpu_shader_2D_line_dashed_geom_glsl[];
|
||||||
extern char datatoc_gpu_shader_3D_line_dashed_uniform_color_legacy_vert_glsl[];
|
|
||||||
extern char datatoc_gpu_shader_3D_line_dashed_uniform_color_vert_glsl[];
|
extern char datatoc_gpu_shader_3D_line_dashed_uniform_color_vert_glsl[];
|
||||||
|
|
||||||
extern char datatoc_gpu_shader_edges_front_back_persp_vert_glsl[];
|
|
||||||
extern char datatoc_gpu_shader_edges_front_back_persp_geom_glsl[];
|
|
||||||
extern char datatoc_gpu_shader_edges_front_back_persp_legacy_vert_glsl[];
|
|
||||||
extern char datatoc_gpu_shader_edges_front_back_ortho_vert_glsl[];
|
|
||||||
extern char datatoc_gpu_shader_edges_overlay_vert_glsl[];
|
|
||||||
extern char datatoc_gpu_shader_edges_overlay_geom_glsl[];
|
|
||||||
extern char datatoc_gpu_shader_edges_overlay_simple_geom_glsl[];
|
|
||||||
extern char datatoc_gpu_shader_edges_overlay_frag_glsl[];
|
|
||||||
extern char datatoc_gpu_shader_text_vert_glsl[];
|
extern char datatoc_gpu_shader_text_vert_glsl[];
|
||||||
extern char datatoc_gpu_shader_text_geom_glsl[];
|
extern char datatoc_gpu_shader_text_geom_glsl[];
|
||||||
extern char datatoc_gpu_shader_text_frag_glsl[];
|
extern char datatoc_gpu_shader_text_frag_glsl[];
|
||||||
@@ -842,30 +833,6 @@ static const GPUShaderStages builtin_shader_stages[GPU_SHADER_BUILTIN_LEN] = {
|
|||||||
.vert = datatoc_gpu_shader_keyframe_diamond_vert_glsl,
|
.vert = datatoc_gpu_shader_keyframe_diamond_vert_glsl,
|
||||||
.frag = datatoc_gpu_shader_keyframe_diamond_frag_glsl,
|
.frag = datatoc_gpu_shader_keyframe_diamond_frag_glsl,
|
||||||
},
|
},
|
||||||
/* This version is magical but slow! */
|
|
||||||
[GPU_SHADER_EDGES_FRONT_BACK_PERSP] =
|
|
||||||
{
|
|
||||||
.vert = datatoc_gpu_shader_edges_front_back_persp_vert_glsl,
|
|
||||||
.geom = datatoc_gpu_shader_edges_front_back_persp_geom_glsl,
|
|
||||||
.frag = datatoc_gpu_shader_flat_color_frag_glsl,
|
|
||||||
},
|
|
||||||
[GPU_SHADER_EDGES_FRONT_BACK_ORTHO] =
|
|
||||||
{
|
|
||||||
.vert = datatoc_gpu_shader_edges_front_back_ortho_vert_glsl,
|
|
||||||
.frag = datatoc_gpu_shader_flat_color_frag_glsl,
|
|
||||||
},
|
|
||||||
[GPU_SHADER_EDGES_OVERLAY_SIMPLE] =
|
|
||||||
{
|
|
||||||
.vert = datatoc_gpu_shader_3D_vert_glsl,
|
|
||||||
.geom = datatoc_gpu_shader_edges_overlay_simple_geom_glsl,
|
|
||||||
.frag = datatoc_gpu_shader_edges_overlay_frag_glsl,
|
|
||||||
},
|
|
||||||
[GPU_SHADER_EDGES_OVERLAY] =
|
|
||||||
{
|
|
||||||
.vert = datatoc_gpu_shader_edges_overlay_vert_glsl,
|
|
||||||
.geom = datatoc_gpu_shader_edges_overlay_geom_glsl,
|
|
||||||
.frag = datatoc_gpu_shader_edges_overlay_frag_glsl,
|
|
||||||
},
|
|
||||||
[GPU_SHADER_SIMPLE_LIGHTING] =
|
[GPU_SHADER_SIMPLE_LIGHTING] =
|
||||||
{
|
{
|
||||||
.vert = datatoc_gpu_shader_3D_normal_vert_glsl,
|
.vert = datatoc_gpu_shader_3D_normal_vert_glsl,
|
||||||
@@ -1332,28 +1299,8 @@ GPUShader *GPU_shader_get_builtin_shader_with_config(eGPUBuiltinShader shader,
|
|||||||
GPUShader **sh_p = &builtin_shaders[sh_cfg][shader];
|
GPUShader **sh_p = &builtin_shaders[sh_cfg][shader];
|
||||||
|
|
||||||
if (*sh_p == NULL) {
|
if (*sh_p == NULL) {
|
||||||
GPUShaderStages stages_legacy = {NULL};
|
|
||||||
const GPUShaderStages *stages = &builtin_shader_stages[shader];
|
const GPUShaderStages *stages = &builtin_shader_stages[shader];
|
||||||
|
|
||||||
if (shader == GPU_SHADER_EDGES_FRONT_BACK_PERSP) {
|
|
||||||
/* TODO: remove after switch to core profile (maybe) */
|
|
||||||
if (!GLEW_VERSION_3_2) {
|
|
||||||
stages_legacy.vert = datatoc_gpu_shader_edges_front_back_persp_legacy_vert_glsl;
|
|
||||||
stages_legacy.frag = datatoc_gpu_shader_flat_color_alpha_test_0_frag_glsl;
|
|
||||||
stages = &stages_legacy;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (shader == GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR) {
|
|
||||||
/* Dashed need geometry shader, which are not supported by legacy OpenGL,
|
|
||||||
* fallback to solid lines. */
|
|
||||||
/* TODO: remove after switch to core profile (maybe) */
|
|
||||||
if (!GLEW_VERSION_3_2) {
|
|
||||||
stages_legacy.vert = datatoc_gpu_shader_3D_line_dashed_uniform_color_legacy_vert_glsl;
|
|
||||||
stages_legacy.frag = datatoc_gpu_shader_2D_line_dashed_frag_glsl;
|
|
||||||
stages = &stages_legacy;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* common case */
|
/* common case */
|
||||||
if (sh_cfg == GPU_SHADER_CFG_DEFAULT) {
|
if (sh_cfg == GPU_SHADER_CFG_DEFAULT) {
|
||||||
*sh_p = GPU_shader_create(
|
*sh_p = GPU_shader_create(
|
||||||
|
@@ -1,54 +0,0 @@
|
|||||||
|
|
||||||
// Draw "fancy" wireframe, displaying front-facing, back-facing and
|
|
||||||
// silhouette lines differently.
|
|
||||||
// Mike Erwin, April 2015
|
|
||||||
|
|
||||||
uniform bool drawFront = true;
|
|
||||||
uniform bool drawBack = true;
|
|
||||||
uniform bool drawSilhouette = true;
|
|
||||||
|
|
||||||
uniform vec4 frontColor;
|
|
||||||
uniform vec4 backColor;
|
|
||||||
uniform vec4 silhouetteColor;
|
|
||||||
|
|
||||||
uniform vec3 eye; // direction we are looking
|
|
||||||
|
|
||||||
uniform mat4 ModelViewProjectionMatrix;
|
|
||||||
|
|
||||||
in vec3 pos;
|
|
||||||
|
|
||||||
// normals of faces this edge joins (object coords)
|
|
||||||
in vec3 N1;
|
|
||||||
in vec3 N2;
|
|
||||||
|
|
||||||
flat out vec4 finalColor;
|
|
||||||
|
|
||||||
// TODO: in float angle; // [-pi .. +pi], + peak, 0 flat, - valley
|
|
||||||
|
|
||||||
// to discard an entire line, set both endpoints to nowhere
|
|
||||||
// and it won't produce any fragments
|
|
||||||
const vec4 nowhere = vec4(vec3(0.0), 1.0);
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
bool face_1_front = dot(N1, eye) > 0.0;
|
|
||||||
bool face_2_front = dot(N2, eye) > 0.0;
|
|
||||||
|
|
||||||
vec4 position = ModelViewProjectionMatrix * vec4(pos, 1.0);
|
|
||||||
|
|
||||||
if (face_1_front && face_2_front) {
|
|
||||||
// front-facing edge
|
|
||||||
gl_Position = drawFront ? position : nowhere;
|
|
||||||
finalColor = frontColor;
|
|
||||||
}
|
|
||||||
else if (face_1_front || face_2_front) {
|
|
||||||
// exactly one face is front-facing, silhouette edge
|
|
||||||
gl_Position = drawSilhouette ? position : nowhere;
|
|
||||||
finalColor = silhouetteColor;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// back-facing edge
|
|
||||||
gl_Position = drawBack ? position : nowhere;
|
|
||||||
finalColor = backColor;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,60 +0,0 @@
|
|||||||
|
|
||||||
// Draw "fancy" wireframe, displaying front-facing, back-facing and
|
|
||||||
// silhouette lines differently.
|
|
||||||
// Mike Erwin, April 2015
|
|
||||||
|
|
||||||
// After working with this shader a while, convinced we should make
|
|
||||||
// separate shaders for perpective & ortho. (Oct 2016)
|
|
||||||
|
|
||||||
// Due to perspective, the line segment's endpoints might disagree on
|
|
||||||
// whether the adjacent faces are front facing. This geometry shader
|
|
||||||
// decides which edge type to use if endpoints disagree.
|
|
||||||
|
|
||||||
uniform mat4 ProjectionMatrix;
|
|
||||||
|
|
||||||
uniform bool drawFront = true;
|
|
||||||
uniform bool drawBack = true;
|
|
||||||
uniform bool drawSilhouette = true;
|
|
||||||
|
|
||||||
uniform vec4 frontColor;
|
|
||||||
uniform vec4 backColor;
|
|
||||||
uniform vec4 silhouetteColor;
|
|
||||||
|
|
||||||
layout(lines) in;
|
|
||||||
layout(line_strip, max_vertices = 2) out;
|
|
||||||
|
|
||||||
in vec4 MV_pos[];
|
|
||||||
in float edgeClass[];
|
|
||||||
|
|
||||||
flat out vec4 finalColor;
|
|
||||||
|
|
||||||
void emitLine(vec4 color)
|
|
||||||
{
|
|
||||||
gl_Position = ProjectionMatrix * MV_pos[0];
|
|
||||||
EmitVertex();
|
|
||||||
gl_Position = ProjectionMatrix * MV_pos[1];
|
|
||||||
finalColor = color;
|
|
||||||
EmitVertex();
|
|
||||||
EndPrimitive();
|
|
||||||
}
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
float finalEdgeClass = max(edgeClass[0], edgeClass[1]);
|
|
||||||
|
|
||||||
if (finalEdgeClass > 0.0f) {
|
|
||||||
// front-facing edge
|
|
||||||
if (drawFront)
|
|
||||||
emitLine(frontColor);
|
|
||||||
}
|
|
||||||
else if (finalEdgeClass < 0.0f) {
|
|
||||||
// back-facing edge
|
|
||||||
if (drawBack)
|
|
||||||
emitLine(backColor);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// exactly one face is front-facing, silhouette edge
|
|
||||||
if (drawSilhouette)
|
|
||||||
emitLine(silhouetteColor);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,68 +0,0 @@
|
|||||||
|
|
||||||
// Draw "fancy" wireframe, displaying front-facing, back-facing and
|
|
||||||
// silhouette lines differently.
|
|
||||||
// Mike Erwin, April 2015
|
|
||||||
|
|
||||||
// After working with this shader a while, convinced we should make
|
|
||||||
// separate shaders for perpective & ortho. (Oct 2016)
|
|
||||||
|
|
||||||
// This shader is an imperfect stepping stone until all platforms are
|
|
||||||
// ready for geometry shaders.
|
|
||||||
|
|
||||||
// Due to perspective, the line segment's endpoints might disagree on
|
|
||||||
// whether the adjacent faces are front facing. Need to use a geometry
|
|
||||||
// shader or pass in an extra position attribute (the other endpoint)
|
|
||||||
// to do this properly.
|
|
||||||
|
|
||||||
uniform bool drawFront = true;
|
|
||||||
uniform bool drawBack = true;
|
|
||||||
uniform bool drawSilhouette = true;
|
|
||||||
|
|
||||||
uniform vec4 frontColor;
|
|
||||||
uniform vec4 backColor;
|
|
||||||
uniform vec4 silhouetteColor;
|
|
||||||
|
|
||||||
uniform mat4 ModelViewMatrix;
|
|
||||||
uniform mat4 ModelViewProjectionMatrix;
|
|
||||||
uniform mat3 NormalMatrix;
|
|
||||||
|
|
||||||
in vec3 pos;
|
|
||||||
|
|
||||||
// normals of faces this edge joins (object coords)
|
|
||||||
in vec3 N1;
|
|
||||||
in vec3 N2;
|
|
||||||
|
|
||||||
flat out vec4 finalColor;
|
|
||||||
|
|
||||||
// TODO: in float angle; // [-pi .. +pi], + peak, 0 flat, - valley
|
|
||||||
|
|
||||||
// to discard an entire line, set its color to invisible
|
|
||||||
// (must have GL_BLEND enabled, or discard in fragment shader)
|
|
||||||
const vec4 invisible = vec4(0.0);
|
|
||||||
|
|
||||||
bool front(vec3 N)
|
|
||||||
{
|
|
||||||
vec4 xformed = ModelViewMatrix * vec4(pos, 1.0);
|
|
||||||
return dot(NormalMatrix * N, normalize(-xformed.xyz)) > 0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
bool face_1_front = front(N1);
|
|
||||||
bool face_2_front = front(N2);
|
|
||||||
|
|
||||||
gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
|
|
||||||
|
|
||||||
if (face_1_front && face_2_front) {
|
|
||||||
// front-facing edge
|
|
||||||
finalColor = drawFront ? frontColor : invisible;
|
|
||||||
}
|
|
||||||
else if (face_1_front || face_2_front) {
|
|
||||||
// exactly one face is front-facing, silhouette edge
|
|
||||||
finalColor = drawSilhouette ? silhouetteColor : invisible;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// back-facing edge
|
|
||||||
finalColor = drawBack ? backColor : invisible;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,44 +0,0 @@
|
|||||||
|
|
||||||
// Draw "fancy" wireframe, displaying front-facing, back-facing and
|
|
||||||
// silhouette lines differently.
|
|
||||||
// Mike Erwin, April 2015
|
|
||||||
|
|
||||||
// After working with this shader a while, convinced we should make
|
|
||||||
// separate shaders for perpective & ortho. (Oct 2016)
|
|
||||||
|
|
||||||
// Due to perspective, the line segment's endpoints might disagree on
|
|
||||||
// whether the adjacent faces are front facing. We use a geometry
|
|
||||||
// shader to resolve this properly.
|
|
||||||
|
|
||||||
uniform mat4 ModelViewMatrix;
|
|
||||||
uniform mat3 NormalMatrix;
|
|
||||||
|
|
||||||
in vec3 pos;
|
|
||||||
in vec3 N1, N2; // normals of faces this edge joins (object coords)
|
|
||||||
|
|
||||||
out vec4 MV_pos;
|
|
||||||
out float edgeClass;
|
|
||||||
|
|
||||||
// TODO: in float angle; // [-pi .. +pi], + peak, 0 flat, - valley
|
|
||||||
|
|
||||||
bool front(vec3 N, vec3 eye)
|
|
||||||
{
|
|
||||||
return dot(NormalMatrix * N, eye) > 0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
MV_pos = ModelViewMatrix * vec4(pos, 1.0);
|
|
||||||
|
|
||||||
vec3 eye = normalize(-MV_pos.xyz);
|
|
||||||
|
|
||||||
bool face_1_front = front(N1, eye);
|
|
||||||
bool face_2_front = front(N2, eye);
|
|
||||||
|
|
||||||
if (face_1_front && face_2_front)
|
|
||||||
edgeClass = 1.0; // front-facing edge
|
|
||||||
else if (face_1_front || face_2_front)
|
|
||||||
edgeClass = 0.0; // exactly one face is front-facing, silhouette edge
|
|
||||||
else
|
|
||||||
edgeClass = -1.0; // back-facing edge
|
|
||||||
}
|
|
@@ -1,21 +0,0 @@
|
|||||||
|
|
||||||
#define SMOOTH 1
|
|
||||||
|
|
||||||
const float transitionWidth = 1.0;
|
|
||||||
|
|
||||||
uniform vec4 fillColor = vec4(0);
|
|
||||||
uniform vec4 outlineColor = vec4(0, 0, 0, 1);
|
|
||||||
|
|
||||||
noperspective in vec3 distanceToOutline;
|
|
||||||
|
|
||||||
out vec4 FragColor;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
float edgeness = min(min(distanceToOutline.x, distanceToOutline.y), distanceToOutline.z);
|
|
||||||
#if SMOOTH
|
|
||||||
FragColor = mix(outlineColor, fillColor, smoothstep(0, transitionWidth, edgeness));
|
|
||||||
#else
|
|
||||||
FragColor = (edgeness <= 0) ? outlineColor : fillColor;
|
|
||||||
#endif
|
|
||||||
}
|
|
@@ -1,72 +0,0 @@
|
|||||||
layout(triangles) in;
|
|
||||||
layout(triangle_strip, max_vertices = 3) out;
|
|
||||||
|
|
||||||
uniform float outlineWidth = 1.0;
|
|
||||||
uniform vec2 viewportSize;
|
|
||||||
|
|
||||||
in vec4 pos_xformed[];
|
|
||||||
in float widthModulator[];
|
|
||||||
|
|
||||||
noperspective out vec3 distanceToOutline;
|
|
||||||
|
|
||||||
// project to screen space
|
|
||||||
vec2 proj(int axis)
|
|
||||||
{
|
|
||||||
vec4 pos = pos_xformed[axis];
|
|
||||||
return (0.5 * (pos.xy / pos.w) + 0.5) * viewportSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
float dist(vec2 pos[3], int v)
|
|
||||||
{
|
|
||||||
// current vertex position
|
|
||||||
vec2 vpos = pos[v];
|
|
||||||
// endpoints of opposite edge
|
|
||||||
vec2 e1 = pos[(v + 1) % 3];
|
|
||||||
vec2 e2 = pos[(v + 2) % 3];
|
|
||||||
|
|
||||||
float abs_det = length(cross(vec3(vpos - e1, 0), vec3(vpos - e2, 0))); // could simplify
|
|
||||||
return abs_det / distance(e2, e1);
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 distance[3];
|
|
||||||
|
|
||||||
void clearEdge(int v)
|
|
||||||
{
|
|
||||||
float distant = 10 * outlineWidth;
|
|
||||||
for (int i = 0; i < 3; ++i)
|
|
||||||
distance[i][v] += distant;
|
|
||||||
}
|
|
||||||
|
|
||||||
void modulateEdge(int v)
|
|
||||||
{
|
|
||||||
float offset = min(widthModulator[v], 1) * outlineWidth;
|
|
||||||
for (int i = 0; i < 3; ++i)
|
|
||||||
distance[i][v] -= offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
vec2 pos[3] = vec2[3](proj(0), proj(1), proj(2));
|
|
||||||
|
|
||||||
for (int v = 0; v < 3; ++v)
|
|
||||||
distance[v] = vec3(0);
|
|
||||||
|
|
||||||
for (int v = 0; v < 3; ++v) {
|
|
||||||
if (widthModulator[v] > 0) {
|
|
||||||
distance[v][v] = dist(pos, v);
|
|
||||||
modulateEdge(v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int v = 0; v < 3; ++v)
|
|
||||||
if (widthModulator[v] <= 0)
|
|
||||||
clearEdge(v);
|
|
||||||
|
|
||||||
for (int v = 0; v < 3; ++v) {
|
|
||||||
gl_Position = pos_xformed[v];
|
|
||||||
distanceToOutline = distance[v];
|
|
||||||
EmitVertex();
|
|
||||||
}
|
|
||||||
|
|
||||||
EndPrimitive();
|
|
||||||
}
|
|
@@ -1,56 +0,0 @@
|
|||||||
layout(triangles) in;
|
|
||||||
layout(triangle_strip, max_vertices = 3) out;
|
|
||||||
|
|
||||||
uniform float outlineWidth = 1.0;
|
|
||||||
uniform vec2 viewportSize;
|
|
||||||
|
|
||||||
noperspective out vec3 distanceToOutline;
|
|
||||||
|
|
||||||
// project to screen space
|
|
||||||
vec2 proj(int axis)
|
|
||||||
{
|
|
||||||
vec4 pos = gl_in[axis].gl_Position;
|
|
||||||
return (0.5 * (pos.xy / pos.w) + 0.5) * viewportSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
float dist(vec2 pos[3], int v)
|
|
||||||
{
|
|
||||||
// current vertex position
|
|
||||||
vec2 vpos = pos[v];
|
|
||||||
// endpoints of opposite edge
|
|
||||||
vec2 e1 = pos[(v + 1) % 3];
|
|
||||||
vec2 e2 = pos[(v + 2) % 3];
|
|
||||||
|
|
||||||
float abs_det = length(cross(vec3(vpos - e1, 0), vec3(vpos - e2, 0))); // could simplify
|
|
||||||
return abs_det / distance(e2, e1);
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 distance[3];
|
|
||||||
|
|
||||||
void modulateEdge(int v)
|
|
||||||
{
|
|
||||||
float offset = 0.5 * outlineWidth;
|
|
||||||
for (int i = 0; i < 3; ++i)
|
|
||||||
distance[i][v] -= offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
vec2 pos[3] = vec2[3](proj(0), proj(1), proj(2));
|
|
||||||
|
|
||||||
for (int v = 0; v < 3; ++v)
|
|
||||||
distance[v] = vec3(0);
|
|
||||||
|
|
||||||
for (int v = 0; v < 3; ++v) {
|
|
||||||
distance[v][v] = dist(pos, v);
|
|
||||||
modulateEdge(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int v = 0; v < 3; ++v) {
|
|
||||||
gl_Position = gl_in[v].gl_Position;
|
|
||||||
distanceToOutline = distance[v];
|
|
||||||
EmitVertex();
|
|
||||||
}
|
|
||||||
|
|
||||||
EndPrimitive();
|
|
||||||
}
|
|
@@ -1,14 +0,0 @@
|
|||||||
|
|
||||||
uniform mat4 ModelViewProjectionMatrix;
|
|
||||||
|
|
||||||
in vec3 pos;
|
|
||||||
in float edgeWidthModulator;
|
|
||||||
|
|
||||||
out vec4 pos_xformed;
|
|
||||||
out float widthModulator;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
pos_xformed = ModelViewProjectionMatrix * vec4(pos, 1.0);
|
|
||||||
widthModulator = edgeWidthModulator;
|
|
||||||
}
|
|
Reference in New Issue
Block a user