Jump to content

  • Log In with Google      Sign In   
  • Create Account


simple geometry shader


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 Yours3!f   Members   -  Reputation: 1252

Like
0Likes
Like

Posted 03 March 2012 - 08:13 AM

Hi,

I'm trying to make a simple pass-through geometry shader, but if I actually use it nothing shows up on the screen. Without the geometry shader I do get the desired output. (I followed the lighthouse3d tutorial)

Any idea what am I doing wrong?

vertex shader:
#version 410
uniform mat4 m4_p, m4_mv;
in vec4 v4_vertex;
in vec2 v2_texture;
smooth out vec2 v2_texture_coords;
void main()
{
  v2_texture_coords = v2_texture;
  gl_Position = m4_p * m4_mv * v4_vertex;
}

geometry shader:
#version 410

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

in vertex_input
{
	vec2 tex_coord;
} in_vertices[3];
out vertex_output
{
	vec2 tex_coord;
} out_vertex;

void main()
{
  for(int c = 0; c < gl_VerticesIn; c++)
  {
	gl_Position = gl_in[c].gl_Position;
	out_vertex.tex_coord = in_vertices[c].tex_coord;
	EmitVertex();
  }
}

pixel shader:
#version 410
uniform sampler2D texture0;
smooth in vec2 v2_texture_coords;
out vec4 v4_color;
void main()
{
  v4_color = texture(texture0, v2_texture_coords.st);
}

Best regards,
Yours3!f

Sponsor:

#2 Tsus   Members   -  Reputation: 987

Like
0Likes
Like

Posted 03 March 2012 - 08:45 AM

Hi!

The names of the input to the fragment shader must match the names of the output of the geometry shader.
So, your pixel shader should more look like this (not tested):
#version 410
uniform sampler2D texture0;
//smooth in vec2 v2_texture_coords; // Thats how it was called when it came out of the vertex shader.
in vertex_output
{
	vec2 tex_coord;
} out_vertex;

out vec4 v4_color;
void main()
{
  v4_color = texture(texture0, out_vertex.tex_coord.st);
}

Cheers!

Acagamics e.V. – IGDA Student Game Development Club (University of Magdeburg, Germany)


#3 Yours3!f   Members   -  Reputation: 1252

Like
0Likes
Like

Posted 03 March 2012 - 09:27 AM

thanks for the reply Tsus,

EDIT: I attached the desired picture as well

I tried outputting the texture coordinates but I get strange results (see attached picture):
[vertex shader]
#version 410
uniform mat4 m4_p, m4_mv;
in vec4 v4_vertex;
in vec2 v2_texture;
smooth out vec2 v2_texture_coords;
void main()
{
  v2_texture_coords = v2_texture;
  gl_Position = m4_p * m4_mv * v4_vertex;
}
[geometry shader]
#version 410

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

in vertex_input
{
	vec2 v2_texture_coords;
} in_vertices[3];
out vertex_output
{
	vec2 v2_texture_coords;
} out_vertex;

void main()
{
  for(int c = 0; c < gl_VerticesIn; c++)
  {
	gl_Position = gl_in[c].gl_Position;
	out_vertex.v2_texture_coords = in_vertices[c].v2_texture_coords;
	EmitVertex();
  }
}
[pixel shader]
#version 410
uniform sampler2D texture0;
in vertex_output
{
	vec2 v2_texture_coords;
} out_vertex;
out vec4 v4_color;
void main()
{
  //v4_color = texture(texture0, out_vertex.v2_texture_coords.st);
  v4_color = vec4(out_vertex.v2_texture_coords.st, 0.0, 1.0);
}

Attached Thumbnails

  • tex_coords.png
  • good_tex_coords.png


#4 Tsus   Members   -  Reputation: 987

Like
0Likes
Like

Posted 03 March 2012 - 12:16 PM

Hi,

sorry, I should have seen that earlier. The names of the varyings passed from the vertex shader to the geometry shader do not match either.

[vertex shader]
#version 410
uniform mat4 m4_p, m4_mv;
in vec4 v4_vertex;
in vec2 v2_texture;
smooth out vec2 v2_texture_coords;
void main()
{
  v2_texture_coords = v2_texture;
  gl_Position = m4_p * m4_mv * v4_vertex;
}
[geometry shader]
#version 410

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

// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//in vertex_input
//{
//	vec2 v2_texture_coords;
//} in_vertices[3];

in vec2 v2_texture_coords[3];    // Edit: Added the in modifier.
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

out vertex_output
{
	vec2 v2_texture_coords;
} out_vertex;

void main()
{
  for(int c = 0; c < gl_VerticesIn; c++)
  {
	gl_Position = gl_in[c].gl_Position;
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//	out_vertex.v2_texture_coords = in_vertices[c].v2_texture_coords;
	out_vertex.v2_texture_coords = v2_texture_coords[c];
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
	EmitVertex();
  }
}
[pixel shader]
#version 410
uniform sampler2D texture0;
in vertex_output
{
	vec2 v2_texture_coords;
} out_vertex;
out vec4 v4_color;
void main()
{
  //v4_color = texture(texture0, out_vertex.v2_texture_coords.st);
  v4_color = vec4(out_vertex.v2_texture_coords.st, 0.0, 1.0);
}

Acagamics e.V. – IGDA Student Game Development Club (University of Magdeburg, Germany)


#5 Yours3!f   Members   -  Reputation: 1252

Like
0Likes
Like

Posted 03 March 2012 - 12:59 PM

so vertex ouput has to be the same type as geometry input and geometry output has to be the same type as pixel input, right? As I noticed the names can be different...

so I rewrote it a little bit,
now using cross_shader_data as type
and voila:
[vertex shader]
#version 410
uniform mat4 m4_p, m4_mv;
in vec4 v4_vertex;
in vec2 v2_texture;
out cross_shader_data
{
  vec2 v2_texture_coords;
} vertex_output;
void main()
{
  vertex_output.v2_texture_coords = v2_texture;
  gl_Position = m4_p * m4_mv * v4_vertex;
}
[geometry shader]
#version 410

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

in cross_shader_data
{
  vec2 v2_texture_coords;
} geometry_input[3];
out cross_shader_data
{
  vec2 v2_texture_coords;
} geometry_output;

void main()
{
  for(int c = 0; c < gl_VerticesIn; c++)
  {
    gl_Position = gl_in[c].gl_Position;
    geometry_output.v2_texture_coords = geometry_input[c].v2_texture_coords;
    EmitVertex();
  }
}
[pixel shader]
#version 410
uniform sampler2D texture4; //geometry buffer
uniform sampler2D texture5; //input color buffer
in cross_shader_data
{
  vec2 v2_texture_coords;
} pixel_input;
out vec4 v4_color;
void main()
{
  v4_color = texture(texture5, pixel_input.v2_texture_coords.st);
  //v4_color = vec4(pixel_input.v2_texture_coords.st, 0.0, 1.0);
}



now this works xD, yours still didn't because of the type mismatch... So thank you for the help!!!

#6 Tsus   Members   -  Reputation: 987

Like
0Likes
Like

Posted 03 March 2012 - 01:52 PM

so vertex ouput has to be the same type as geometry input and geometry output has to be the same type as pixel input, right? As I noticed the names can be different...

Well, I just tested this a bit and it turns out that it depends on how you declare the varying variable that is passed.

Usually I define a struct like this (only available since 4.1, though):
struct varyings_gs_fs
{
   vec3 normal;
};
in varying_gs_fs gs_fs;
In this case the names of the variables must match.

And if you do it they way you did, the type must match.
in varyings_gs_fs
{
  vec3 normal;
} gs_fs;
Good to know that there is a difference, so thanks for letting me see this. Posted Image

yours still didn't because of the type mismatch...

I tested it on another machine and during transcripting I missed the in modifier. (I think that was the problem, because the types actually already did match. Unless I made another typo. Posted Image)

Cheers!

Acagamics e.V. – IGDA Student Game Development Club (University of Magdeburg, Germany)


#7 Yours3!f   Members   -  Reputation: 1252

Like
0Likes
Like

Posted 04 March 2012 - 12:50 AM

I'm planning to use tue latest OGL only, so I guess that doesn't matter.

Thanks for clarifying :) This part of OGL is a little bit confusing.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS