Yet another shadow topic

I’m trying to use a DirectionalLight as sunlight but I’m getting the same problem as the person in this topic:

[url]Shadows with directional light source: strange behaviour]

where the top half of my scene is dark and the bottom half is bright. I’ve tried everything from setFrameSize to setNearFar to no avail. No matter what I do, I can’t seem to fix this issue.

dLight = DirectionalLight('dLight')
		dLight.setColor(Vec4(0.8,0.8,0.75,1))
		dLightNP = render.attachNewNode(dLight)
		dLightNP.setHpr(30,-60,0)
		dLightNP.setPos(0, -60, 30)
		dLight.setPoint(Point3(0,0,20))
		dLight.setShadowCaster(True, 256, 256)
		dLight.showFrustum() 
		dLight.getLens().setFilmSize(4096, 4096)
		dLight.getLens().setNearFar(0.1, 1000.0)
		render.setLight(dLightNP)
		render.setShaderAuto()

Furthermore, showFrustum doesn’t seem to do anything.

Any help would be greatly appreciated.

I advise setting the near and far a bit less far from each other.

How much more or less? I set it to 10 and that doesn’t seem to make a difference. I still have the top half of the scene shadowed and the bottom not.

Maybe you should increase the vertical film size, then.

I’ve tried just about everything from 1 to 4096 so far and it hasn’t made a visible difference. I just tried setting it to OVER NINE THOUSAAAAAAND!!!1 and it didn’t do anything.

For visual aide

Figured out why my frustum was not showing: its the same color as the bacground. Now that I have it showing, for the directional light it only shows a single line, which I don’t know if that’s all I’m supposed to see. It points in the exact direction I want it to, and it seems to be long enough to cast shadows, yet it isn’t

Switched it to a Spotlight and had it working fine with a spotlight. Its just something about that directional light.

So… I take it that means there isn’t a fix for this?

Ok, seriously? Does ANYONE know how to fix this or what I’m doing wrong? I’d REALLY like to get this thing working.

Yours is not the first report of shadows working with a Spotlight but not with a DirectionalLight. Unfortunately, the people who originally wrote the shadow code are no longer around, so no one here can say definitively whether it’s supposed to work the way you’re using it–but I agree it does seem broken.

If you or anyone else would be interested in researching the problem further, we’d be happy to accept patches.

David

Yeah, Ive also spend many hours trying to get shadows working with other lights properly. They don’t, it’s just how the shadow effect was implemented in Panda. It would be great if someone would write a proper shadow shader to work with most lights and the shader generator. There are many shadow shader examples here, but of course none works with the shader generator. Most people here don’t have any shader programming knowledge or C++ knowledge to do it.
Shadows are a common thing you’ll want from a game. I actually considered switching to PyOgre for my project because of this. I wouldn’t suggest that though, Panda has alot more pros.

Um? raises hand I’m still here…

There’s no reason why DirectionalLight wouldn’t work just like the Spotlight (even though it’s more difficult to set up, and may cause visual artifacts due to the nature of an orthogonal shadow map). It’s just a matter of configuring the frustum correctly to fit around both the objects that receive shadows and cast shadows.

If the frustum is in place properly (and you can verify this using showFrustum), and it’s still not showing up, then it’s probably a bug in your video drivers because the code is so similar to the code for a spot light. There could be a bug in Panda, of course, and I could look into that if you could send me a working small test case that I can reproduce the problem with.

@Anon: I’ve heard you complain many times about the shadow system, but so far I haven’t seen any bug reports on Launchpad from you about it. If it’s really bothering you that much, why not help us resolve the problems by giving us enough information to work with, perhaps a test case?

Oh, oops! I thought this was a CMU student project. My apologies.

I guess it sounds like rant, sorry about that. It’s mainly because every time I encounter this, I try to learn Cg again to solve it myself and fail miserably.

I don’t think it’s a bug,so I don’t think I can post it in Launchpad. There was a topic where I posted my code and issues and was told that the shadow system was meant to be used with spotlights. If you want I can dig up the codes and example screens.

I remember your old topic about the issue. I went back to it a few months after you made it, tried your code and I got it to work flawlessly with just a few tweaks. I didn’t post the results back to the thread because it was so old.

As for why spotlights are preferred: there’s not much to do about that. Perspective cameras (especially with a properly tweaked FOV and near/far ratio) tend to work better with shadow mapping in general because the depth map is not linear and because the frustum is not parallel. If you insist on using directional lights with shadows, it is crucial that the frustum is tweaked as efficiently as possible.

Perhaps I should make a video tutorial explaining how to easily and effectively tweak the shadow system, do you think that would help?

If you only have the time to do that, I’m sure everyone would greatly appreciate it.

If I could use a lens node for shadows, or spotlight which wouldn’t be used as a an actual light, then it works for me. The only reason I want directional light is because my scene is meant to use Directional light (for the sun).

Well that would be great and I think it would be pretty helpful to everyone, but I think I coud understand by an ordinary post.

cant wait to hear more :slight_smile: