Sign in to follow this  

Where is my Geometry Shader broken?

This topic is 418 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

I've successfully implemented shadow mapping and would like to incorporate a geometry shader for optimisation. It works fine without the geometry shader, but with it, it breaks, and nothing meaningful is drawn to the cubemap. At this point, the geometry shader doesn't even do anything, it simply passes the values from the vertex shader to the fragment. I suspect the geom_v_position or frag_v_position values aren't being passed across the stages correctly. I've been going over this for some while and can't find the problem. Any help would be amazing. Thanks in advance! ^_^

Vertex Shader

#version 330
 
precision lowp float;
 
layout(location = 0) in vec3 in_position;
 
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform mat4 modelMatrix;
 
out vec4 geom_position;
 
void main() 
{
	gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(in_position, 1.0);
	geom_v_position  = viewMatrix * modelMatrix * vec4(in_position, 1.0);
}

Geometry Shader

#version 330
 
layout(triangles) in;
layout(triangle_strip, max_vertices=3) out;
 
in vec4 geom_v_position[];
out vec4 frag_v_position;
 
void main()
{	
	for(int i=0; i<3; i++)
	{
		frag_v_position = geom_v_position[i];
		gl_Position = gl_in[i].gl_Position;
		EmitVertex();
	}
	EndPrimitive();
}

Fragment Shader

#version 330
 
precision lowp float;
 
in vec4 frag_v_position;
 
layout (location = 0) out vec4 outColor;
 
void main() {
	float depth = length( vec3(frag_v_position) ) / 20;
 
	float moment1 = depth;
	float moment2 = depth * depth;
 
	float dx = dFdx(depth);
	float dy = dFdy(depth);
	moment2 += 0.25*(dx*dx+dy*dy);
 
	outColor = vec4( moment1, moment2, 0.0, 0.0);
}
Edited by Chris Burrows

Share this post


Link to post
Share on other sites

precision lowp float;
 
layout(location = 0) in vec3 in_position;
 
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform mat4 modelMatrix;
 
out vec4 geom_position; <-- geom_position != geom_v_position
 
void main() 
{
	gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(in_position, 1.0);
	geom_v_position  = viewMatrix * modelMatrix * vec4(in_position, 1.0); <-- geom_v_position != geom_position
}


Is that a typo in the post or in your code? If this is in your code, you need to be checking for shader errors while compiling the shaders. Edited by MarkS

Share this post


Link to post
Share on other sites

I changed the code in the post to make it more readable, so it could have been either. I ended up re-writing the shaders from scratch and that fixed it. Thanks heaps for taking a look.


Care to elaborate for those looking for the same answer?

Share this post


Link to post
Share on other sites

I have shader error checking, some things slip through you know.

 

Ah sure. What I did was delete all my shader code, and then re-write it from my mind. It's hard to say where the error was and since then the code has changed too much to compare it to my original post. There's really nothing more I can say about it.

 

That geometry shader above doesn't even do anything, it simply passes the same values from the vertex shader to the fragment. But since getting that working, I enhanced it to render all my shadow maps in a single pass which marks a huge breakthrough for me, 32 shadow casting point lights running at 60fps.

 

Ixjj_O.jpg

Share this post


Link to post
Share on other sites

This topic is 418 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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