Shadow map techniques

Hi,

I’m having some issues getting shadowmaps working with instances and deferred lighting.

When I apply a shadow shader to a camera like this:

lci = NodePath(PandaNode("lightCameraInitializer"))
        lci.setShader(loader.loadShader("shaders/shadow.sha"), 1)
        self.shadowcam.node().setInitialState(lci.getState())

        # Set the shader inputs
        render.setShaderInput("light", self.castercam)
        render.setShaderInput("depthmap", self.depthmap)

But my shadowmap ends up not rendering my instanced geometry, basically because the shadow.sha shader isn’t aware of it.

The only way I can think of around this is to make everything that receives shadows an instance - which honestly sounds like a pain. (And I don’t want to start going down that way unless its really needed)

To get around this would anybody know of any techniques for rendering shadowmaps just with two depth map buffers (View and Light) and a fullscreen quad pass (or 2)?

I’m trying to decouple shadowmapping from other scene rendering, and almost make it a post-process - but not sure if thats realistic at all?

Anybody been down this path?

Hmm. I’m thinking another way would be to put an if statement into my vertex shader.

So, checking if we have an instance id:

if(!sign(l_id)){
  normal position shader stuff
}
else
{
  handle instances
}

If statements in shaders is bad, but I think that might be a solution?

Edit: Alright - that worked :slight_smile: - but my framerate has dropped considerably, presumably just because I’m now calculating shadows for many more objects.