Simple shadow

Hi to all!

This is a way that I find to make a simple drop shadow, and I like to know if it’s more expensive than other methods.

def CreateShadow(np):
			sh = np.getParent().attachNewNode("shadow")
			sh.setScale(1,1,.01)
			sh.setTransparency(TransparencyAttrib.MAlpha)      
			sh.setColor(0,0,0,.4) 
			np.instanceTo(sh)   
			return sh

Nice idea. I don’t quite get it though, I tried integrating it into my own code. Why do you set the Y-scale of the drop shadow to 1%? Surely the scale of the drop shadow should be (1,1,1), but it’s position should be something like (.1,0,.1)? Also, you attach the drop shadow to the same parent node as the node it’s shadowing, surely you want the drop shadow to be parented to the node it’s shadowing, so that it moves with the node?

I might be confused, I’m thinking of drop-shadows behind flat 2D objects, like the drop shadows on the windows on your desktop (if you have such an effect). Maybe yours is a different kind of shadow for 3D objects. Then your Y-scale would make sense.

Yes, it’s for 3D objects.
This creates a instance of the object and reduces the Z scale to make it flat,
simulating a shadow from a light above at 90º.

It’s a fine approach, and elegantly simple. It’s probably a little faster than most other approaches. It works perfectly as long as your avatar is walking almost entirely on flat terrain.

David