shadows (pre 1.7)

Because of the great new Buildbot, i was able to try out the newest 1.7 build (tooo stupid to compile my own ^^

So i wanna try the new implemented shadowmaping, but i cant figure out how it works…
i read somewhere that i just have to write:

light.node().setShadowCaster(True)

to enable shadows…but i see no change/no shadow. Do i have todo something else to get the shadows working? Or are they still in progress?

grettingz

You need to invoke setShaderAuto on the scene that receives the shadows.

More info can be found at the bottom of this page:
panda3d.org/manual/index.php/Lighting

thanks allot for that fast reply,

Got it working with a spotlight! Great!

But was not succesfull with the directional Light, i think the lens has to be tweaked like mentioned in the docs. But i dont know how to Access/“get” the lens of a light. Or do i have to manually make my own lens and assign it (like when setting up a spotlight?) like that:

    lens = PerspectiveLens()
    light.setLens(lens) 

and then modify that lens further? Never ever touched a Lens before :blush:

Another two Question:
-is there a way to change the opacity of the shadow and/or the [b]softness/b?
-how can i change the spread of a spotlight, do i have to manipulate the lens?

Thanks for your time rdb!

edit: btw. panda throws following error, but runs fine…what does this mean?

:display:gsg:glgsg(error): c:\buildslave\dev_win32\build\panda3d\panda\src\glstuff\glGraphicsBuffer_src.cxx, line 989: GL error 1282

Try getLens(), this will return the lens object.
ATM soft shadows are not supported. It wouldn’t make sense to change the opacity of the shadows, but perhaps you mean to create an ambient light too?
You can change the FOV (I assume thats what you mean by ‘spread’) in the lens properties.

thanks again rdb, the FOV was what i was looking for but…

still no luck with the directional light, getLens() works and i see the panda-model in the buffer-view when i activate it, but it casts/recieves no shadows…

the odd thing is how the model reacts when i view it and move the camera around: if it reaches the upper part of my window it gets completly shadowed/black, in the bottom part of my window it looks normal, but without shadow…something is completly going wrong here :frowning:

but the spotlight works perfect…

any ideas whats wrong with my directional-light? heres a sample:

from pandac.PandaModules import *
from direct.directbase import DirectStart
from direct.actor import Actor

base.accept("v", base.bufferViewer.toggleEnable)
base.accept("V", base.bufferViewer.toggleEnable)
    # Make a way out of here!
base.accept("escape", exit)

#DIRECTIONAL not working
light = DirectionalLight('dlight')
light.setColor(VBase4(1, 1, 1, 1))
light.getLens().setFilmSize(10,10)
light.getLens().setFar(30)
light.setShadowCaster(True,512,512)
    
#SPOT working!       
#light = Spotlight('slight')
#light.setColor(VBase4(1, 1, 1, 1))
#lens = PerspectiveLens()
#light.setExponent (0)
#light.setLens(lens)


light.setShadowCaster(True,512,512)
lnp = render.attachNewNode(light)
lnp.setPos(-8, 0, 12)
lnp.lookAt(0,0,0)
render.setLight(lnp)

#ambientlight
alight = AmbientLight('alight')
alnp = render.attachNewNode(alight)
alight.setColor(Vec4(0.2, 0.2, 0.2, 1))
render.setLight(alnp)

#some pandas
pandaActor = Actor.Actor("models/panda-model",{"walk":"models/panda-walk4"})
pandaActor.setScale(0.005,0.005,0.005)
pandaActor.reparentTo(render)
pandaActor.loop("walk")
pandaActor.setShaderAuto()
pandaActor.reparentTo(render)
pandaModel2=Actor.Actor('panda-model',{'walk':'panda-walk4'})
pandaModel2.setScale(0.002,0.002,0.002)
pandaModel2.setPos(0,-0.8,2.5)
pandaModel2.setShaderAuto()
pandaModel2.reparentTo(render)

base.cam.setPos(0,-10,2)
run()

for me the smaller panda does not cast shadows on the other panda but if i comment the directionallight part and uncomment the spotlightpart, it works…

thanks for looking ^^

Try calling showFrustum() on the light, this will generate a box where it is rendering. Then try to find it in your scene and adjust your settings to change the position / rendering area.

Note that directional lights are not well suited for shadows, you’re better off with spotlights.

This is great! I was able to get reasonably good-looking sun shadows with a spotlight positioned very far away and a 2048x2048 shadow buffer.

However, I did run into one problem: I can’t get the shadow buffer to render before the main camera. No matter how many different setSort() calls I make, the shadows always lag behind by a frame. Same with reflections and frame buffer distortions.

ok, still no luck with directionlalight, so i stick with the spotlight…

I don´t have et1337´s problem with the shadow lagging behind first, but when i try to turn shadows off via guielements, calling: light.setShadowCaster(False),
the shadow still shows and is lagging behind my animated model, like et1337 discribed…
Also if i enable shadows again nothing changes (shadow still laging behind).
When i setup my scene without shadows enabled and then call light.setShadowCaster(True,512,512) while runtime, nothing changes, no shadows visible…what am i doing wrong…

Is there a way to turn shadows on/off inside a runnig application?