PDA

View Full Version : Geometry shader output



Nokturnis
11-12-2016, 05:23 AM
Hi, I have a problem with the following geometry shader. It outputs nothing. If I replace "triangle_strip" with "line_strip", it works just fine. What am I missing? Thank you.

[Vertex Shader]
#version 330

layout(location=0) in vec2 position;

void main()
{
gl_Position=vec4(position.x,0.0,position.y,1.0);
}

[Geometry Shader]
#version 330

layout(points) in;
layout(triangle_strip,max_vertices=6) out;

uniform mat4 proj;
uniform mat4 view;
uniform mat4 model;
uniform float hsize;

void make_tri(in mat4 mvp, in vec3 p1, in vec3 p2, in vec3 p3)
{
gl_Position=mvp*vec4(p1,1.0);
EmitVertex();
gl_Position=mvp*vec4(p2,1.0);
EmitVertex();
gl_Position=mvp*vec4(p3,1.0);
EmitVertex();
EndPrimitive();
}

void main()
{
mat4 mv=view*model;
mat4 mvp=proj*mv;
vec3 p1=vec3(gl_in[0].gl_Position.x-hsize,0.0,gl_in[0].gl_Position.z+hsize);
vec3 p2=vec3(gl_in[0].gl_Position.x-hsize,0.0,gl_in[0].gl_Position.z-hsize);
vec3 p3=vec3(gl_in[0].gl_Position.x+hsize,0.0,gl_in[0].gl_Position.z-hsize);
vec3 p4=vec3(gl_in[0].gl_Position.x+hsize,0.0,gl_in[0].gl_Position.z+hsize);
make_tri(mvp,p1,p2,p3);
make_tri(mvp,p3,p4,p1);
}

[Fragment Shader]
#version 330

out vec4 outcol;

void main()
{
outcol=vec4(1.0);
}

GClements
11-12-2016, 06:20 AM
Hi, I have a problem with the following geometry shader. It outputs nothing. If I replace "triangle_strip" with "line_strip", it works just fine. What am I missing?

Is back-face culling enabled (glEnable(GL_CULL_FACE))?

That will remove back-facing triangles but won't affect points or lines.

Nokturnis
11-12-2016, 07:33 AM
Duh! I'm an idiot. That was it. Thank you.