• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Yours3!f

simple geometry shader

6 posts in this topic

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:
[CODE]
#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;
}
[/CODE]

geometry shader:
[CODE]
#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();
}
}
[/CODE]

pixel shader:
[CODE]
#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);
}
[/CODE]

Best regards,
Yours3!f
0

Share this post


Link to post
Share on other sites
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):
[CODE]
#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);
}
[/CODE]

Cheers!
0

Share this post


Link to post
Share on other sites
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):
[CODE]
[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);
}
[/CODE]
0

Share this post


Link to post
Share on other sites
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.

[CODE]
[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);
}
[/CODE]
0

Share this post


Link to post
Share on other sites
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:
[CODE]
[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);
}

[/CODE]


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

Share this post


Link to post
Share on other sites
[quote name='Yours3!f' timestamp='1330801176' post='4918932']
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...
[/quote]
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):
[code]
struct varyings_gs_fs
{
vec3 normal;
};
in varying_gs_fs gs_fs;
[/code]
In this case the names of the variables must match.

And if you do it they way you did, the type must match.
[code]
in varyings_gs_fs
{
vec3 normal;
} gs_fs;
[/code]
Good to know that there is a difference, so thanks for letting me see this. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

[quote name='Yours3!f' timestamp='1330801176' post='4918932']
yours still didn't because of the type mismatch...
[/quote]
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. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img])

Cheers!
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0