• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Anfractu0us

Scene rendering entirely shadowed with shadow maps

6 posts in this topic

After quite a bit of tinkering, I finally got an accurate depth image rendered to my FBO/into a texture. However, I can't seem to get the actual shadows to cast. I'm using http://fabiensanglard.net/shadowmapping/index.php as a reference.

 

[attachment=12969:depth_shadow.png]

 

This is my depth map as drawn from the lights POV, as per gDebugger after adjusting the slider to represent roughly .50 out of 1.0.  Here is how my scene looks after rendering.

 

[attachment=12970:scene.png]

 

I've got my matrices, shaders, etc. setup exactly as presented in Fabien Sanglards tutorial. I'm not necessarily looking for answer, but rather a point in to what would be causing my entire scene to be gray, rather than have shadows applied.

 

The only thing I can think of is how I have my perspective established:

       //set pers settings
       this->r_cam->perspective(CAMERA_FOVX,
       (800.0f) / (600.0f),10.0f,40000.0f);
       //load pers into matrix
	glLoadMatrixf(&this->r_cam->getProjectionMatrix()[0][0]);

Perhaps my zNear(10.0f) is too small? Or perhaps zFar(40000.0f) is too large? The depthmap shown in gDebugger looks alright to me, though. I'm using VBOs and AssImp if that affects anything; I can post my final scene rendering code(or any requested portion tongue.png) if that would aid in determining what's going on; I didn't want to clutter my first post too much tongue.png Thank you!

Edited by Anfractu0us
0

Share this post


Link to post
Share on other sites

The shadow map looks good so thats a good start!

 

The smaller the zNear/far range the better when it comes to shadow maps. If you can reduce that range then it will improve your shadow map quality by reducing precision errors...but this shouldn't be causing the issues your having atm.

 

Judging from those two images, the light producing the shadow is in the same position as the camera? btw, that's not an issue, just determining how your scene is set up :)

0

Share this post


Link to post
Share on other sites

[quote name='Nyssa' timestamp='1356515907' post='5014371']
same position as the camera
[/quote]

Wouldn't that mean that the shadows would never be visible? Since all shadowed parts are behind the objects that cast the shadows.

0

Share this post


Link to post
Share on other sites

Actually, I think I had the camera opposite of the light when I took the shot; the giant gray mass stays as a giant gray mass though, no matter where i put my camera :P

0

Share this post


Link to post
Share on other sites
Wouldn't that mean that the shadows would never be visible? Since all shadowed parts are behind the objects that cast the shadows.

 

Yep :) ...behind the camera I should have asked.

 

The reason I was asking...When I'm debugging these kind of issues I'd first make sure the shadow map looks the way it should from the lights perspective. So I'd put the light into an easy position for you to judge this. Once you've determined the shadow map creation is fine you can rule that out that stage being the problem.

 

Without seeing your code It's hard to say what the issue is exactly. If your not sure how shadow mapping works I'll explain it briefly below. Sometimes fully understanding the technique can help in nailing down the problem. If you already understand it then skip it :)

 

The first render pass is creating the shadow map:

So when you create a shadow map, you are doing it from the lights perspective. I find it easiest to think about the light as a camera in this case. When you render the scene from the lights perspective, you are taking note of the distance from the light to a visible point in the scene. This becomes your depth map from the lights point of view (or shadow map). Remember during shadow map creation you should have depth testing and writing enabled, so if a point is closer then previously stored in the buffer the closer z value will take its place.

 

The second render pass is rendering the final scene and determining the lit value using the shadow map:

Now, when it comes to determining if a point is in shadow or not think about it like this...lets take for example a point behind an object that is casting a shadow on that point. Now we transform that point from its world space into the lights view space and we determine the distance from that point to the light. Next we sample the shadow map for that point and get its depth. So (remember we are still in light space) if the sampled depth is closer than our current point then the point must be behind an object and therefore in shadow. If the point was closer than the sampled distance then the point would be lit. We can make this call because we did z testing and writing when  creating the shadow map.

 

Hope that's not too confusing!

 

Also make sure your shadow map is created AND sampled with:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

Otherwise you can end up with filtering issues.

1

Share this post


Link to post
Share on other sites

Still haven't managed to fix it, but that is defintely one of the better explanations I've come across for the technique! I understand the idea a LOT better.

So, here's a giant wall of code!

While I'm thinking about it, I'm using SDL, GLEW, AssImp, and Bullet. I currently have Bullet disabled while I work on the shiny graphics junk.

static double modelView[16];    
static double projection[16];    
static float tex[16];        
// This is matrix transform every coordinate x,y,z    
// x = x* 0.5 + 0.5    
// y = y* 0.5 + 0.5    
// z = z* 0.5 + 0.5    
// Moving from unit cube [-1,1] to [0,1]      
const GLdouble bias[16] = {            
0.5, 0.0, 0.0, 0.0,        
0.0, 0.5, 0.0, 0.0,        
0.0, 0.0, 0.5, 0.0,    
0.5, 0.5, 0.5, 1.0};        

// Grab modelview and transformation matrices    
glGetDoublev(GL_MODELVIEW_MATRIX, modelView);    
glGetDoublev(GL_PROJECTION_MATRIX, projection);        

glActiveTexture(GL_TEXTURE7);    
glMatrixMode(GL_TEXTURE);      

glLoadMatrixd(bias);    
// concatating all matrice into one.    
glMultMatrixd (projection);    
glMultMatrixd (modelView);    
// Go back to normal matrix mode    
glMatrixMode(GL_MODELVIEW);

I swapped the glActiveTexture before the glMatrixMode() call so that the data is actually writing to the appropriate texture matrix unit. Otherwise, in terms of FBO and depthmap generation are entirely identical to what's in the tutorial. I suspect after a whole bunch of goofing around that my issues lie in the values getting pushed to the texture matrix.

if(mode == R_NORM || mode == R_DEBUG)
{
    glEnable(GL_COLOR_MATERIAL);
    glEnable(GL_TEXTURE_2D);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);
    glEnableClientState(GL_VERTEX_ARRAY);
    glBindBuffer(GL_ARRAY_BUFFER,model.t_buff);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,model.i_buff);

    glTexCoordPointer(2, GL_FLOAT,sizeof(vert),BUFFER_OFFSET(0));
    glNormalPointer(GL_FLOAT,sizeof(vert),BUFFER_OFFSET(sizeof(GLfloat)*2));
    glVertexPointer(3, GL_FLOAT,sizeof(vert),BUFFER_OFFSET(sizeof(GLfloat)*5));
    glClientActiveTexture(GL_TEXTURE0+ model.mats.at(0).texid);

    c_render.use_program(model.shaderid);
    int sdw_loc = glGetUniformLocation(model.shaderid,"ShadowMap");
    glUniform1i(sdw_loc,c_render.depth_tex);

    glActiveTexture(GL_TEXTURE0 + model.mats.at(0).texid);
    glBindTexture(GL_TEXTURE_2D, model.mats.at(0).texid);

    glActiveTexture(GL_TEXTURE7);
    glBindTexture(GL_TEXTURE_2D,c_render.depth_tex);

    glDrawElements(GL_TRIANGLES,(model.f_index.size()*3),GL_UNSIGNED_INT,0);

    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
    glActiveTexture(GL_TEXTURE0);
    glClientActiveTexture(GL_TEXTURE0);
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);
    c_render.use_program(0);
    glBindTexture(GL_TEXTURE_2D,0);
    glDisable(GL_TEXTURE_2D);
}
else
if(mode == R_DEPTH)
{
    glEnableClientState(GL_NORMAL_ARRAY);
    glEnableClientState(GL_VERTEX_ARRAY);
    glBindBuffer(GL_ARRAY_BUFFER,model.t_buff);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,model.i_buff);

    glNormalPointer(GL_FLOAT,sizeof(vert),BUFFER_OFFSET(sizeof(GLfloat)*2));
    glVertexPointer(3, GL_FLOAT,sizeof(vert),BUFFER_OFFSET(sizeof(GLfloat)*5));            
    glDrawElements(GL_TRIANGLES,(model.f_index.size())*3,GL_UNSIGNED_INT,0);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);
}

Is my rendering code(cut some of the extra crap out for readibility.) I use the section under R_DEPTH to generate the depth map, which is valid from what I can tell, and then R_NORM/R_DEBUG is what renders the scene.

What leads me to think that perhaps it's a texture matrix issue is that gDebugger spits out values that aren't even remotely clamped to 0,1 - which is what I assume they are supposed to be. He didn't mention in the tutorial but I suppose then that if your scene is of a decent scale/shadow map is of a larger resolution that you have to normalize the light proj/view matrix values?

 

Also, for clarification: the depth map looks like it should from the lights point of view. My texture is indeed initiated with both MIN/MAG filter settings. The one thing that raised a concern for me is that the tutorial code doesn't actually compile and run properly for me; the binary works quite fine but when I tried compiling his code and running it it didn't even create a FBO.

Edited by Anfractu0us
0

Share this post


Link to post
Share on other sites

Had a big post about using the inverse modelview but it doesn't actually appear to affect my output.

 

EDIT: After some goofing, I removed anything that would screw with my texture matrix(including disabling texture coord pointers/arrays.) I would say that my values for the matrix make sense now, but all in all it still doesn't work. I have a proper depth map, valid fbo, and I'm assuming to be decent values for my texture matrix. I'm really at a loss as to why it wouldn't be working, perhaps besides drivers or something silly that I'm overlooking.

 

EDIT2: Got it! For some reason I was sending the texture ID, not the texture UNIT to the shader. :S

[attachment=13233:butts2.png]

Edited by Anfractu0us
0

Share this post


Link to post
Share on other sites

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  
Followers 0