Skyboxes Cast Shadows by Default

I’ve just spent 2 days debugging why my shadows weren’t working. Turned out the skybox (which is more like a sphere when it comes to geometry) didn’t have it’s shadow mode set to off even though all I did with the sky was create it through SkyFactory and attach it to the scene.
Now I’d like to know if there’s a reason why SkyFactory is implemented this way or can I go and make a PR which fixes this in order to save others some headaches?

1 Like

I think you can also collide with skyboxes, I dont remember if we can disable that though.
Might be worth doing that though, because it’s a sphere at 0,0,0

Yes, as remy pointed out to me, set its position to some crazy number (1000,1000,1000), to avoid hitting it.

Collision is very useful when you want to get the direction the sun is shining, for example, when you use an image with the sun in it for the skybox.

That sounds more like a hack to me though and like collision with a sphere, idk if some simple logic couldn’t do that well.

And I remember, we don’t have a collision hint, I wished for it but the answer was basically: You can also use a depth/breadth search to fill a list and use that with collideWith.

In theory we could also use a custom Mesh here jmonkeyengine/Mesh.java at master · jMonkeyEngine/jmonkeyengine · GitHub (that’s the only one), or make every user filter for the SkyBox (which is what my code needs to do)

So you added the sky box to a node that was already set to cast shadows?

…that seems like a mistake.

I think in general we try to avoid forcing presets onto nodes like this. For example, for a long time BitmapText preset its bucket to Gui even though if you add it to the guiNode this is automatic. Then folks like me would try to add it to the scene and wonder why it didn’t work.

Thanks for the response, objections like this are exactly why I made this topic :slight_smile:

Yes. Since it was a simple scene with no stuff that shouldn’t cast/receive shadows, I didn’t bother with having separate sub nodes and just attached everything to the root node (which had its shadow mode set to CastAndReceive). Might not work in a bigger game, but for small experiments and I strongly suspect that also for beginner users’ projects, this would be the way it’s done.

While I understand where you’re coming from, I’d have to disagree this is a good idea. While it might have been an automatic process for BitmapText, that certainly isn’t the case for SkyBox (otherwise we wouldn’t be having this conversation :grinning_face_with_smiling_eyes:). And should 95% of users who use it as intended really suffer from often hard to find bugs, just so the 5% of users using the nodes in unintended ways don’t get hit by the same (or similar) bug? In my personal opinion, if one is bold enough to use a node like this in an unintended way, it’s on them to figure out the weirdness that might result from it.

I’d love to get a perspective from someone relatively new to jme, as we’re both experienced users. But I’m not sure how many of those read the “development” section of the forum :frowning:

I always feel really uncomfortable setting things like this on the root node. Since as far as I know, there is no way to override it further down in the scene graph like other things… so it’s like saying “everything will always cast and receive shadows forever… even fire, even grass, even particle effects, even the floating text…” (Edit: I guess you can just set the mode to something else.)

Where as it’s super common to:
load model
add physics
set shadow mode (cast or cast and receive)
etc.
attach to scene

I even stopped setting scale on the root node and gui nodes since I got in trouble so many times where a month down the line something wasn’t working right and I couldn’t figure out why.

As far as I understand it, the shadow mode can always be overriden by the children, so sometimes an opt-out approach is faster to use than an opt-in one.

The entire idea of having to set shadow mode for every single model loaded is wrong in my opinion. We should in my personal opinion have a default that allows the user not to care about it in most cases. And having to set the shadow mode on almost every model certainly doesn’t fit with thay idea.