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