Geometry Shader beginner question (interpolation)

thomas.goepfer's icon

Hi everyone,

I'm jumping into the extra dimension of geometry shader...
There is some useful (and accessible) resources on the net like this one:
https://learnopengl.com/Advanced-OpenGL/Geometry-Shader
First step is to build houses based on points. Like this :

After translation from version 330 to version 120 (not an easy step...), I manage to have houses, but with a very different snow effect:

Inside the geometry shader, there is the function to create new vertice and change the color for the roof:

void build_house(vec4 position)
{
gl_FrontColor = gl_FrontColorIn[0];
gl_Position = position + vec4(-0.2, -0.2, 0.0, 0.0);
EmitVertex();
gl_Position = position + vec4( 0.2, -0.2, 0.0, 0.0);
EmitVertex();
gl_Position = position + vec4(-0.2, 0.2, 0.0, 0.0);
EmitVertex();
gl_Position = position + vec4( 0.2, 0.2, 0.0, 0.0);
EmitVertex();
gl_Position = position + vec4( 0.0, 0.4, 0.0, 0.0);
gl_FrontColor = vec4(1.0);
EmitVertex();
EndPrimitive();
}

What I understand is: for the first 4 vertices, color is related to the gl_FrontColor. For the last one, the color is white. Because of the shader system, the color has to interpolate from gl_FrontColor to white, is that right ?
What am I missing ?!

gm.tg_house.jxs.zip
application/zip 2.80 KB

thomas.goepfer's icon

...
Adding the attribute "@smooth_shading 1" into jit.gl.mesh object is far better...!


quat's icon

Sorry to hijack your thread, but I'm also jumping into geometry shaders and am not able to recreate your results. I'm on OSX-- any idea why I get a blank screen? Nothing in the console.

Rob Ramirez's icon

post your patch and your shader if you want help debugging

quat's icon

they're attached in the original post. thanks!

Roland Sproll's icon

With gl3, after translation to version 330 I have the same result - no gradient in the roof despite activated smooth_shading. But back on gl2 it works (with version 120). Any ideas?

Rob Ramirez's icon

would need to see your updated patch and gl3 shader file to offer help

Roland Sproll's icon

Of course, thanks!

houses_gl3.zip
application/x-zip-compressed 2.79 KB

Roland Sproll's icon

Rob, is something wrong with my files?

Rob Ramirez's icon

just remove the "flat" type qualifier from the color input/output variables in each of your programs so that the shader will interpolate the color across the pixels.

with the removal of fixed function pipeline in gl3, attributes like smooth_shading will have no effect when used with custom shaders.

Roland Sproll's icon

That's it, thanks!