mlfarrell

05-25-2014, 04:35 PM

Hey guys.

So I got wide lines /almost/ working in my core profile program. I followed the example here http://stackoverflow.com/questions/12758192/wide-lines-in-geometry-shader-behaves-oddly

and ran into the exact same guy the issue has there. Oddly enough, this post is the best example of how to do this that I could find anywhere.

Can someone please answer both me and him, why is this clipping problem happening? And what can i do efficiently in my GS to fix it?

Below in my code, the problem occurs when the 'bad' boolean evaluates to true. Using my fixVertex function doesn't help.

#ifdef GL_ES

//precision mediump float;

#else

#define highp

#define lowp

#define mediump

#endif

uniform vec2 renderTargetSize;

uniform vec4 solidColor;

uniform mat4 modelViewProjectionMatrix;

uniform float lineThickness;

in vec4 vtxColor[2];

flat out vec4 varColor;

layout (lines) in;

layout (triangle_strip, max_vertices = 4) out;

vec3 fixVertex(vec3 vert)

{

//seems like I need to manually clip the lines, otherwise I end up with incorrect lines running across the entire screen

vert.z = clamp(vert.z, 0.0, 1.0);

return vert;

}

void main()

{

vec3 ndc0 = gl_in[0].gl_Position.xyz / gl_in[0].gl_Position.w;

vec3 ndc1 = gl_in[1].gl_Position.xyz / gl_in[1].gl_Position.w;

bool bad = (ndc0.z > 1.0 || ndc1.z > 1.0);

//ndc0 = fixVertex(ndc0);

//ndc1 = fixVertex(ndc1);

vec2 lineScreenForward = normalize(ndc1.xy - ndc0.xy);

vec2 lineScreenRight = vec2(-lineScreenForward.y, lineScreenForward.x);

vec2 lineScreenOffset = (vec2(lineThickness) / renderTargetSize) * lineScreenRight;

gl_Position = vec4(ndc0.xy + lineScreenOffset, ndc0.z, 1.0);

varColor = vtxColor[0];

if(bad)

varColor = vec4(1.0, 0.0, 0.0, 1.0);

EmitVertex();

gl_Position = vec4(ndc0.xy - lineScreenOffset, ndc0.z, 1.0);

varColor = vtxColor[0];

if(bad)

varColor = vec4(1.0, 0.0, 0.0, 1.0);

EmitVertex();

gl_Position = vec4(ndc1.xy + lineScreenOffset, ndc1.z, 1.0);

varColor = vtxColor[1];

if(bad)

varColor = vec4(1.0, 0.0, 0.0, 1.0);

EmitVertex();

gl_Position = vec4(ndc1.xy - lineScreenOffset, ndc1.z, 1.0);

varColor = vtxColor[1];

if(bad)

varColor = vec4(1.0, 0.0, 0.0, 1.0);

EmitVertex();

EndPrimitive();

}

So I got wide lines /almost/ working in my core profile program. I followed the example here http://stackoverflow.com/questions/12758192/wide-lines-in-geometry-shader-behaves-oddly

and ran into the exact same guy the issue has there. Oddly enough, this post is the best example of how to do this that I could find anywhere.

Can someone please answer both me and him, why is this clipping problem happening? And what can i do efficiently in my GS to fix it?

Below in my code, the problem occurs when the 'bad' boolean evaluates to true. Using my fixVertex function doesn't help.

#ifdef GL_ES

//precision mediump float;

#else

#define highp

#define lowp

#define mediump

#endif

uniform vec2 renderTargetSize;

uniform vec4 solidColor;

uniform mat4 modelViewProjectionMatrix;

uniform float lineThickness;

in vec4 vtxColor[2];

flat out vec4 varColor;

layout (lines) in;

layout (triangle_strip, max_vertices = 4) out;

vec3 fixVertex(vec3 vert)

{

//seems like I need to manually clip the lines, otherwise I end up with incorrect lines running across the entire screen

vert.z = clamp(vert.z, 0.0, 1.0);

return vert;

}

void main()

{

vec3 ndc0 = gl_in[0].gl_Position.xyz / gl_in[0].gl_Position.w;

vec3 ndc1 = gl_in[1].gl_Position.xyz / gl_in[1].gl_Position.w;

bool bad = (ndc0.z > 1.0 || ndc1.z > 1.0);

//ndc0 = fixVertex(ndc0);

//ndc1 = fixVertex(ndc1);

vec2 lineScreenForward = normalize(ndc1.xy - ndc0.xy);

vec2 lineScreenRight = vec2(-lineScreenForward.y, lineScreenForward.x);

vec2 lineScreenOffset = (vec2(lineThickness) / renderTargetSize) * lineScreenRight;

gl_Position = vec4(ndc0.xy + lineScreenOffset, ndc0.z, 1.0);

varColor = vtxColor[0];

if(bad)

varColor = vec4(1.0, 0.0, 0.0, 1.0);

EmitVertex();

gl_Position = vec4(ndc0.xy - lineScreenOffset, ndc0.z, 1.0);

varColor = vtxColor[0];

if(bad)

varColor = vec4(1.0, 0.0, 0.0, 1.0);

EmitVertex();

gl_Position = vec4(ndc1.xy + lineScreenOffset, ndc1.z, 1.0);

varColor = vtxColor[1];

if(bad)

varColor = vec4(1.0, 0.0, 0.0, 1.0);

EmitVertex();

gl_Position = vec4(ndc1.xy - lineScreenOffset, ndc1.z, 1.0);

varColor = vtxColor[1];

if(bad)

varColor = vec4(1.0, 0.0, 0.0, 1.0);

EmitVertex();

EndPrimitive();

}