Jump to content
  • Advertisement
Sign in to follow this  
Yours3!f

geometry shader viewport redirect doesn't work

This topic is 1662 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 there,

 

I'm trying to implement cascaded shadow mapping. For a start I tried to render the same shadow map four times next to each other in a texture using the geometry shader to redirect the rendering to four different viewports. However only the first is drawn correctly the second flickers...

 

shadow gen, vertex shader:

#version 430 core

layout(location=0) in vec4 in_vertex;

void main()
{
	gl_Position = in_vertex;
}

shadow gen, geometry shader:

#version 430

layout(triangles, invocations = 4) in; // 4 viewports
layout(triangle_strip, max_vertices = 3) out; // we're working with tris

uniform mat4 mvp[4];

void main()
{
	for( int c = 0; c < gl_in.length(); ++c ) //loop over input triangle
	{
    gl_Position = mvp[gl_InvocationID] * gl_in[c].gl_Position;
    gl_ViewportIndex = gl_InvocationID;
    EmitVertex();
	}
  EndPrimitive();
}

shadow gen, pixel_shader:

#version 430 core

layout(location=0) out vec4 color;

void main()
{
	color = vec4(1); // nothing is written out anyways
}

set up the shadow texture:
 

//set up shadow tex & fbo
  GLuint shadow_tex;
  glGenTextures( 1, &shadow_tex );
  glBindTexture( GL_TEXTURE_2D, shadow_tex );

  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE );

  uvec2 texsize( 1024 );

  glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, texsize.x * 4, texsize.y, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0 );

  GLuint shadow_fbo;
  glGenFramebuffers( 1, &shadow_fbo );
  glBindFramebuffer( GL_FRAMEBUFFER, shadow_fbo );

  //attach depth cubemap to fbo's depth attachment
  glFramebufferTexture( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, shadow_tex, 0 );

  //no color textures attached
  glDrawBuffer( GL_NONE );

  frm.check_fbo_status();

rendering the shadow map:

//render to shadow map
    glEnable( GL_DEPTH_TEST );
    glDepthMask( GL_TRUE );

    //glViewport( 0, 0, texsize.x, texsize.y );
    glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );

    //render shadow map
    glBindFramebuffer( GL_FRAMEBUFFER, shadow_fbo );
    glClear( GL_DEPTH_BUFFER_BIT );

    glUseProgram( shadow_shader );

    vec4 viewports[4];
    for( int c = 0; c < 4; ++c )
      viewports[c] = vec4(texsize.x * c, 0, texsize.x, texsize.y);

    //glViewportIndexedf();
    glViewportArrayv(0, 4, &viewports[0].x);
    glUniformMatrix4fv( shadow_mvp_mat_loc, 4, false, &light_mvp[0][0].x );

    for( auto& c : scene )
      c.render();

then I just output the shadow map in a trivial way.

 

here's how it looks:

http://i.imgur.com/fFivc0M.png

 

any idea what's wrong?

 

Best regards,

Yours3!f

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!