We have sprite images that are pre-rendered with proper lighting for normal, fully lit conditions. And we have a minor variant of the sprite shader that allows them to accept (and cast) shadows… but in doing so, they now are using the diffuse lighting model, which we don’t want (because it causes our carefully rendered sprites to look too dark or bright, depending on the light intensity).
We want them to use their standard lighting when not in shadow, but darken where shadows are received.
Apparently 3ds Max and Maya both have materials like this… self-illuminated, but still able to receive shadows.
As long as my sprite isn’t flipped (facing away from the camera or flipX=true or localScale.x=-1), it works great. Shadows fall on my sprite, which otherwise is unlit and supports full alpha blending.
But as soon as I flip my sprite by any means, it no longer works properly. Shadows still show up, but only if there is some geometry behind the sprite that would catch them… and then they show up, on my sprite, in the position & shape that the would appear on that other geometry.
This suggests to me that somehow the flipped sprite is not properly writing to the depth buffer, or some such… but I’m in way over my head here. Anybody have a clue?
Hmm, maybe I should be posting this in the shader forum?
Something is definitely different when the sprite is flipped (or rotated or negative-scaled). My shader’s working so great for a non-flipped sprite… what would be different, in the rendering pipeline, for a flipped one?
Joe I have no answer but hope you find a solution - I do know in 3D Max with a standard 100% self illuminated material shadows will not cast on those objects, so some fine layered shadow rendering and compositing is required to get cast shadows to fall on 100% self illuminated objects.
I know that’s probably not helpful, but thought you might like the funny that hit me while reading your previous post.
Does applying this code to the flipped sprites have better results?
I’m still convinced it has something to do with the depth buffer. Is there a way to visualize the contents of the depth buffer, for debugging purposes?
And it occurs to me that if I’m right, I could probably make a special shader that only writes to the depth buffer, and apply this to a big plane (quad) at same level as the character. I suppose that would mimic the effect of putting something just behind the character to catch the shadows.
But that feels like a hackish work-around, since no such shenanigans are required when the sprite isn’t flipped.
Hey, thank you! I’d never noticed Frame Debugger before. I have a feeling it and I are going to become close friends.
OK, so this shows an important difference right away in the DepthPass job. With sprite facing forward, we get this:
That gray blob on the right is the shape of my sprite (or rather, the mesh around my sprite). Now flip the sprite, and we instead get this:
So, yeah, it’s not drawing to the buffer at all in this case. The info on the right says “Cull Back” which is probably the cause, but I don’t quite understand why that is — my shader has “Cull Off” in both passes.
However, the text above that got cut off (next to the name of the shader) says “pass #3 SHADOWS_DEPTH”. Could it be my shader doesn’t have a pass for this, so it’s falling back on some default behavior, or perhaps the VertexLit shader specified as the FallBack at the bottom?
Jeez, I wish I could move this thread over to the Shaders sub-forum… but I can’t, and I hate to split it into two threads, so I’ll forge ahead. Looking at the docs for the LightMode tag, maybe I need to create another pass with LightMode = “ShadowCaster”? Or is there some easier way to turn backface culling off for the SHADOWS_DEPTH pass?