ShadowMap :(

Hello!
I want to add shadows and lighting to my game, but my problem is I don’t know how to get depth component from a perspective other than main one. I thought ok, that’s easy, an FBO and render, but I realized something, this is stupid, redrawing the entire scene just for a FBO? It makes no sense at all, there must be a clever way. What I have found until now is multiple target render, but it is just making colors different, vertices are the same.

So my question is: I have a viewmatrix, how I can extract depth component out of that viewmatrix, without redrawing the entire texture? If I’m not asking for to much I would like code sample.

Think about it this way. Your camera sees a particular view of the scene. The light (which casts shadows into your scene) “sees” a different set of objects. Those sets often have overlap, but they aren’t identical to each other. Besides that, the “frustums” associated with each are very different, and often different types entirely. So rasterizing the scene from different perspectives for each purpose makes sense.

[QUOTE=DirtyBlasion;1290029]
I want to add shadows and lighting to my game, but my problem is I don’t know how to get depth component from a perspective other than main one. I thought ok, that’s easy, an FBO and render, but I realized something, this is stupid, redrawing the entire scene just for a FBO? It makes no sense at all, there must be a clever way. What I have found until now is multiple target render, but it is just making colors different, vertices are the same.

So my question is: I have a viewmatrix, how I can extract depth component out of that viewmatrix, without redrawing the entire texture? If I’m not asking for to much I would like code sample.[/QUOTE]
You can’t avoid redrawing for each view. Even if the same primitive occurs in multiple views, the set of fragments which it covers will differ. Thus, rasterisation must be performed separately for each viewpoint.

If you’re rendering the same geometry with multiple view-projection transformations, there might be some redundant calculations in the vertex shader, in which case you can use transform-feedback mode to pre-process the vertices and use the results for each view. But that’s unlikely to be of any use for rendering shadow maps, as the vertex shader typically does nothing but transform the vertex position.

Bear in mind that rendering shadow maps requires far less computation than normal rendering, there are no texture lookups, and the hardware doesn’t even need to perform a divide per fragment (as depth is affine to screen space, and there aren’t any other interpolated variables).