shadows...

So, Ive been told that there is a solution to my problem. I rewrote my previous code and am posting it here:

from panda3d.core import *
loadPrcFileData("", "prefer-parasite-buffer #f")
import direct.directbase.DirectStart

# setup scene
scene = loader.loadModel('environment')
scene.reparentTo(render)
panda = loader.loadModel('panda')
panda.reparentTo(render)
panda.setY(30)
#panda.setShaderAuto(BitMask32.allOn() & ~BitMask32.bit(Shader.BitAutoShaderShadow))

# setup lights, shadow
light = render.attachNewNode(DirectionalLight("Spot"))
light.node().setScene(render)
light.node().setShadowCaster(True)
light.node().showFrustum()
light.node().getLens().setFov(70)
light.node().getLens().setNearFar(10, 500)
light.node().getLens().setFilmSize(100, 100)
render.setLight(light)
light.setP(-45)

alight = render.attachNewNode(AmbientLight("Ambient"))
alight.node().setColor(Vec4(0.6, 0.6, 0.6, 1))
render.setLight(alight)

render.setShaderAuto()
run()

example:

BTW, is that a vertex color bug for the hat and glasses?

PS. How would you go in using this shadows in a large open area? i tried attaching it to the player node, but when moving there is a noticeable jitter on the edges of the hard shadow

Zoom out, observe the very wide and long frustum, decrease the far distance and the film size dramatically, and see if it’s any better.

As for the weird artifact near the chin, I think that’s one of the artifacts that is caused by the fact that you’re using a directional light. I don’t think there’s much to fix about that, besides switching to a spot light (which generates better quality shadows in general).

I thought you said there was more to it than that… (the low resoltion isnt the issue)

Directional lights have a linear depth buffer, which means that in order to get the best precision (not talking about resolution), you need to set the near/far clip as narrow as you can. Properly configured spotlights don’t suffer from this because they have a perspective lens, which is better suited for shadow maps.

The other cause for the artifact could be just that because of the orthogonal lens, there can be certain angles at which there can be streaks of shadow over a certain face, when the face is (almost) exactly perpendicular to the frustum. This is actually behaviour that makes sense and is to be expected, although it’s usually not desired.
I don’t know of any way to eliminate this, except for just using a spotlight. You might be able to mask it by tweaking the light properties to attenuate it away near orthogonal angles.

Note that setFov on a directional light has no effect. An orthogonal lens has no field of view.

Yeah, but spotlights are used only in very few scenes.
Wouldnt it be batter to allow lens nodes to cast shadows, not lights?

It’s perfectly acceptable to use spotlights in an outdoor scene, and use it for shadowing only (not shading), and add a point light in the same location for the shading.

Lights are lens nodes, indirectly.

hm, how can you set up a light to not shade anything but cast shadows?
just wondering, can you just use a lens node then?

So how to do it?

You enable a light to illuminate when you do something like render.setLight(myLight). If you never do that, then your light won’t illuminate anything. But it can still cast shadows.

David

Actually, it won’t, if you don’t call setLight. You should just tweak the attenuation settings so that there’s no shading.

hm, sounds hacky. is there a plan to use different shadow technique in the future for directional (and point) lights?

I dont know much about attenuation and its values.

I mean I dont know what the 3 values for the attenuation work. Even if it would seem to be set correctly in my test scenes, it wouldn’t mean it is right and would work in other scenes.

I still don’t get what “constant, linear and quadratic attenuation” mean. Can you just tell me what value you would use? Unless I can divide by 0.

developer.valvesoftware.com/wiki … ic_Falloff

To be honest, its a bit confusing, but I dont want to learn all that anyway. Ive never needed to modify the attenuation value. So Ill ask again, can you guys please just tell me what values to use? This isnt it

light.node().setAttenuation(Point3(0,0,0))

I just want that answered :confused: Nothing else

What makes you sure there’s a universal correct value for all possible cases? I don’t know, maybe there is, but it’s VERY rarely so.

Why aren’t you willing to experiment a little bit? Or to at least read about that stuff? Eventually, you will need that knowledge to make your scenes look their best, why not learn it now?

Depending on the forum, even this great one, to answer all of your questions and give you all the knowledge you need on a silver platter is really not a way to go… At least from my perspective…

Sorry for the OT…

In this case, just (0, 0, 0) will probably work, to disable attenuation altogether. I do want to point out that these are fundamental mathematical concepts that you should be able to understand.

well…

I did read it, maybe I should read it again, because I dont think that answers my question, as from what I understood, setting all the values to 0,0,0 would disable shading altogether, but it doesnt seem so, more on that below.

Well, I have many things I want and think I’ll need to learn in the future, like the Bullet physics engine, GLSL and maybe even C++. But I have very little free time and I have priorities. Maybe I will need to learn how attenuation works in the future (though by reading other’s sourcecode of their games, I haven’t really came across it so much), but I don’t need it now, so you don’t have to give me “knowledge on a silver platter”, but you shouldn’t try to force-feed me what I don’t wish to learn either.

As for the issue:

from panda3d.core import *
loadPrcFileData("", "prefer-parasite-buffer #f")
import direct.directbase.DirectStart

# setup scene
scene = loader.loadModel('environment')
scene.reparentTo(render)
panda = loader.loadModel('panda')
panda.reparentTo(render)
panda.setY(30)
#panda.setShaderAuto(BitMask32.allOn() & ~BitMask32.bit(Shader.BitAutoShaderShadow))

# setup lights, shadow
light = render.attachNewNode(Spotlight("Spot"))
light.node().setScene(render)
render.setLight(light)
light.setP(-45)
light.setZ(20)
light.node().setShadowCaster(True)
light.node().setAttenuation(Point3(0,0,0))
light.node().showFrustum()
light.node().getLens().setFov(70)
light.node().getLens().setNearFar(10, 500)
light.node().getLens().setFilmSize(100, 100)

# the light which is actually used
dlight = render.attachNewNode(DirectionalLight("Directional"))
dlight.node().setScene(render)
render.setLight(dlight)

alight = render.attachNewNode(AmbientLight("Ambient"))
alight.node().setColor(Vec4(0.2, 0.2, 0.2, 1))
render.setLight(alight)

render.setShaderAuto()
run() 

There you go. No shading! Only shadows.