Skip to main content
added 28 characters in body
Source Link
Charlie
  • 342
  • 2
  • 20
#version 400

layout(triangles) in;
layout(triangle_strip, max_vertices = 3) out;

in vec2 fUV[]; //uv coordinates
out vec2 gUV;

noperspective out vec3 GEdgeDistance;

void main()
{
    float a = length(gl_in[1].gl_Position.xyz - gl_in[2].gl_Position.xyz);
    float b = length(gl_in[2].gl_Position.xyz - gl_in[0].gl_Position.xyz);
    float c = length(gl_in[1].gl_Position.xyz - gl_in[0].gl_Position.xyz);

    float alpha = acos( (b*b + c*c - a*a) / (2.0*b*c) );
    float beta = acos( (a*a + c*c - b*b) / (2.0*a*c) );
    float ha = abs( c * sin( beta ) );
    float hb = abs( c * sin( alpha ) );
    float hc = abs( b * sin( alpha ) );

    gUV=fUV[0];
    GEdgeDistance = vec3( ha, 0, 0 );
    gl_Position = gl_in[0].gl_Position;
    EmitVertex();

    gUV=fUV[1];
    GEdgeDistance = vec3( 0, hb, 0 );
    gl_Position = gl_in[1].gl_Position;
    EmitVertex();

    gUV=fUV[2];
    GEdgeDistance = vec3( 0, 0, hc );
    gl_Position = gl_in[2].gl_Position;
    EmitVertex();
}
#version 400

in vec2 gUV;

uniform sampler2D png_tex;
uniform float wire_thickness;

noperspective in vec3 GEdgeDistance;

void main()
{
//base fragment color off of which edge is closest
float distance = min(GEdgeDistance[0],min(GEdgeDistance[1],GEdgeDistance[2]));

//draw the each side with different color, displaying the barymetric concept
//if (distance==GEdgeDistance[0])gl_FragColor=vec4(0.52,0,0,1);
//else if (distance==GEdgeDistance[1])gl_FragColor=vec4(0,0.52,0,1);
//else if (distance==GEdgeDistance[2])gl_FragColor=vec4(0,0,0.52,1);

if (distance<wire_thickness)gl_FragColor=vec4(1); //draw fragment if close to edge
else if (distance>=wire_thickness)discard; //discard if not
}
#version 400

layout(triangles) in;
layout(triangle_strip, max_vertices = 3) out;

in vec2 fUV[]; //uv coordinates
out vec2 gUV;

out vec3 GEdgeDistance;

void main()
{
    float a = length(gl_in[1].gl_Position.xyz - gl_in[2].gl_Position.xyz);
    float b = length(gl_in[2].gl_Position.xyz - gl_in[0].gl_Position.xyz);
    float c = length(gl_in[1].gl_Position.xyz - gl_in[0].gl_Position.xyz);

    float alpha = acos( (b*b + c*c - a*a) / (2.0*b*c) );
    float beta = acos( (a*a + c*c - b*b) / (2.0*a*c) );
    float ha = abs( c * sin( beta ) );
    float hb = abs( c * sin( alpha ) );
    float hc = abs( b * sin( alpha ) );

    gUV=fUV[0];
    GEdgeDistance = vec3( ha, 0, 0 );
    gl_Position = gl_in[0].gl_Position;
    EmitVertex();

    gUV=fUV[1];
    GEdgeDistance = vec3( 0, hb, 0 );
    gl_Position = gl_in[1].gl_Position;
    EmitVertex();

    gUV=fUV[2];
    GEdgeDistance = vec3( 0, 0, hc );
    gl_Position = gl_in[2].gl_Position;
    EmitVertex();
}
#version 400

in vec2 gUV;

uniform sampler2D png_tex;
uniform float wire_thickness;

in vec3 GEdgeDistance;

void main()
{
//base fragment color off of which edge is closest
float distance = min(GEdgeDistance[0],min(GEdgeDistance[1],GEdgeDistance[2]));

//draw the each side with different color, displaying the barymetric concept
//if (distance==GEdgeDistance[0])gl_FragColor=vec4(0.52,0,0,1);
//else if (distance==GEdgeDistance[1])gl_FragColor=vec4(0,0.52,0,1);
//else if (distance==GEdgeDistance[2])gl_FragColor=vec4(0,0,0.52,1);

if (distance<wire_thickness)gl_FragColor=vec4(1); //draw fragment if close to edge
else if (distance>=wire_thickness)discard; //discard if not
}
#version 400

layout(triangles) in;
layout(triangle_strip, max_vertices = 3) out;

in vec2 fUV[]; //uv coordinates
out vec2 gUV;

noperspective out vec3 GEdgeDistance;

void main()
{
    float a = length(gl_in[1].gl_Position.xyz - gl_in[2].gl_Position.xyz);
    float b = length(gl_in[2].gl_Position.xyz - gl_in[0].gl_Position.xyz);
    float c = length(gl_in[1].gl_Position.xyz - gl_in[0].gl_Position.xyz);

    float alpha = acos( (b*b + c*c - a*a) / (2.0*b*c) );
    float beta = acos( (a*a + c*c - b*b) / (2.0*a*c) );
    float ha = abs( c * sin( beta ) );
    float hb = abs( c * sin( alpha ) );
    float hc = abs( b * sin( alpha ) );

    gUV=fUV[0];
    GEdgeDistance = vec3( ha, 0, 0 );
    gl_Position = gl_in[0].gl_Position;
    EmitVertex();

    gUV=fUV[1];
    GEdgeDistance = vec3( 0, hb, 0 );
    gl_Position = gl_in[1].gl_Position;
    EmitVertex();

    gUV=fUV[2];
    GEdgeDistance = vec3( 0, 0, hc );
    gl_Position = gl_in[2].gl_Position;
    EmitVertex();
}
#version 400

in vec2 gUV;

uniform sampler2D png_tex;
uniform float wire_thickness;

noperspective in vec3 GEdgeDistance;

void main()
{
//base fragment color off of which edge is closest
float distance = min(GEdgeDistance[0],min(GEdgeDistance[1],GEdgeDistance[2]));

//draw the each side with different color, displaying the barymetric concept
//if (distance==GEdgeDistance[0])gl_FragColor=vec4(0.52,0,0,1);
//else if (distance==GEdgeDistance[1])gl_FragColor=vec4(0,0.52,0,1);
//else if (distance==GEdgeDistance[2])gl_FragColor=vec4(0,0,0.52,1);

if (distance<wire_thickness)gl_FragColor=vec4(1); //draw fragment if close to edge
else if (distance>=wire_thickness)discard; //discard if not
}
deleted 76 characters in body
Source Link
Charlie
  • 342
  • 2
  • 20

Either way, if you want to learn more about this, I suggest these links for furtherFurther reading:

Either way, if you want to learn more about this, I suggest these links for further reading:

Further reading:

added 248 characters in body
Source Link
Charlie
  • 342
  • 2
  • 20

TheI suspect the main problem with my approach, as it turns out, isoriginal attempt was thinking in 2D only. Before I was calculating the edge distance as it appears onscreen, when I should be calculating the value in 3dwith 3D space in mind. The solution I reach is not the same outlined here on page 216, but it still seems to be correct. It looks like this using the Stanford bunny:

IfThe main issue now is whether the geometry shader is as efficient as it could be. I'm certain there is a way to do this making use of dot products and less costly operations than sin/cos/tan trigonometry.

Either way, if you want to learn more about this, I suggest these helped me understand the mostlinks for further reading:

The main problem with my approach, as it turns out, is thinking in 2D only. Before I was calculating the edge distance as it appears onscreen, when I should be calculating the value in 3d space. The solution I reach is not the same outlined here on page 216, but it seems to be correct. It looks like this using the Stanford bunny:

If you want to learn more about, these helped me understand the most:

I suspect the main problem with my original attempt was thinking in 2D only. Before I was calculating the edge distance as it appears onscreen, when I should be calculating the value with 3D space in mind. The solution I reach is not the same outlined here on page 216, but it still seems to be correct. It looks like this using the Stanford bunny:

The main issue now is whether the geometry shader is as efficient as it could be. I'm certain there is a way to do this making use of dot products and less costly operations than sin/cos/tan trigonometry.

Either way, if you want to learn more about this, I suggest these links for further reading:

deleted 28 characters in body
Source Link
Charlie
  • 342
  • 2
  • 20
Loading
Source Link
Charlie
  • 342
  • 2
  • 20
Loading