Where is my Geometry Shader broken?

Started by
3 comments, last by Chris Burrows 7 years, 5 months ago

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);
}
Advertisement

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.

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.

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?

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

This topic is closed to new replies.

Advertisement