Shadow Casting - Possible Bug?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
LunaRebirth
Posts: 385
Joined: Sun May 11, 2014 12:13 am

Shadow Casting - Possible Bug?

Post by LunaRebirth »

I'm really sorry for the amount of posts I post! I always try to get things done as quickly as possible, then run into some nooby mistake.
However, I'm almost positive this is a bug. Unless, of course, I'm doing something wrong?

I'll try to go into as much detail as I can on this problem.

I've got a light which has casting shadows.

Code: Select all

ILightSceneNode* light1 = smgr->addLightSceneNode(0, core::vector3df(0,0,0),
        video::SColorf(server.lightR, server.lightG, server.lightB, server.lightA), 40000.0f);
light1->enableCastShadow( true );
server.lightR,G,B,A change to give a darkness effect. This is online-play, so it comes from the server. This is not, however, the problem.
Notice CastShadow is set to true.

The player model is not a full player model. It's rather pieces of a player, this way you can find clothing and select it from your inventory (I.E. find a hat on the ground, Press A to put it on! The hat attaches to your player's head bone)
Here is a piece of the code -- This is the same concept for each piece of clothing:

Code: Select all

hatNode = smgr->addAnimatedMeshSceneNode(hatMesh);
hatNode->setMaterialTexture(0, driver->getTexture(imgPath));
hatNode->getMaterial(0).Shininess = 0;
hatNode->addShadowVolumeSceneNode();
hatNode->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
hatNode->setParent(headBone);
The problem is not setting the hat, either, as this works.

Can't forget how I'm initializing the device:

Code: Select all

device = createDevice(driverType, core::dimension2d<u32>(640, 480), 16, false, true);
I've also illustrated a picture to show you what I'm talking about:
http://i.imgur.com/X2aBEVH.png

Strangely, mostly everything seems to work fine! Except for hats. When the player faced the sunlight, the entire shadow begins missing.
When not facing the sunlight, it is there.
However, the hat seems to display the shadow rarely. And mostly is distorted???
Keep in mind, the hat is .obj while everything else is .b3d, But I'm not convinced this is the problem. I've also tried converting the hat to .b3d, which changed nothing at all.

Any ideas on the solution to this problem? Has anyone ever had this happen too? Anything I could include to break down the issue?
Please let me know!

Thanks again!!!
LunaRebirth
Posts: 385
Joined: Sun May 11, 2014 12:13 am

Re: Shadow Casting - Possible Bug?

Post by LunaRebirth »

I found that it is possibly because the sunlight is too far from the player?
It is located at 0,15000,0 and the player is near 13231,8020,13238

After placing the lighting at node->getPosition().X,15000,node->getPosition().Z the shadow no longer distorts (Shadow completely under the player), but if I move my camera above the node, the shadow seems to completely remove itself. As if the camera is getting in the way of the sunlight and it diminishes the shadow casting.
Any ideas on fixing that?

EDIT:
This doesn't fix the problem. I think I got over-excited and thought it did until I grabbed the hat just now.
LunaRebirth
Posts: 385
Joined: Sun May 11, 2014 12:13 am

Re: Shadow Casting - Possible Bug?

Post by LunaRebirth »

This is soooo strange.
I'd just got finished redoing the set of hats, and even re-created the hats in .b3d format.
It seems my first hat which is but only a cap has no problems.
But the second Zelda-like hat has the shadow vertices all screwed up!

No longer does it disappear, unless facing the sun, but it is still screwy.

It's kind of hard to explain, but the shadow of the hat looks like there is the base of it, then one vertices above it so when you move the camera around, the shadow looks like the hat is flattening and rotating around.

I'm thinking this might be a problem with front-faces, which Blender exports.
Do you guys think this may be why? Or am I far from the answer..?
kklouzal
Posts: 343
Joined: Sun Mar 28, 2010 8:14 pm
Location: USA - Arizona

Re: Shadow Casting - Possible Bug?

Post by kklouzal »

If I remember correctly blender does not have a native .b3d exporter, so maybe it's an issue with your export script? That's the best I've got sorry.
Dream Big Or Go Home.
Help Me Help You.
LunaRebirth
Posts: 385
Joined: Sun May 11, 2014 12:13 am

Re: Shadow Casting - Possible Bug?

Post by LunaRebirth »

Thank you for the reply!

I don't believe that is the problem, as it happens with the .obj as well.
Thanks!
LunaRebirth
Posts: 385
Joined: Sun May 11, 2014 12:13 am

Re: Shadow Casting - Possible Bug?

Post by LunaRebirth »

This is a very strange (bug?)
The problem with the shadows was that the player hat wasn't triangulated.
However, this problem also happened to weapons I've added in-game, which I downloaded online. So I just made my own and it worked fine. Not sure why this was happening, though.

Problem still persists where if the camera is facing the same way the light is going, all shadows don't appear. Same for if the camera can't see the top of buildings or the top of whatever isn't in camera view. I'd really like to get this fixed, if anyone has some suggestions.
LunaRebirth
Posts: 385
Joined: Sun May 11, 2014 12:13 am

Re: Shadow Casting - Possible Bug?

Post by LunaRebirth »

I tried dealing with this bug so many ways.
My search history is FULL of related searches on the Irrlicht forum.
I've found many posts on this bug, and 0 with any answers.
Is this really a problem that cannot be fixed?

Rather than explaining everything, here's an image. Again.
Image

I've tried dealing with putting the light-source above the player completely, but objects in the distance really stand out having this problem and I cannot fix it.

Help please?:o
LunaRebirth
Posts: 385
Joined: Sun May 11, 2014 12:13 am

Re: Shadow Casting - Possible Bug?

Post by LunaRebirth »

Most likely a bug which hasn't been fixed yet.

Anywho, I've tried flipping single-sided faces. I've tried .obj, .md2, and .x files. I've tried with and without normalizing. I've also tried triangulating everything.

No changes, everything is still messed up and I have lost faith about even using shadows at all -- Although it would be nice to have them.
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Shadow Casting - Possible Bug?

Post by mongoose7 »

I know virtually nothing about stencil shadows, but the inversion looks interesting. The stencil works by "counting" the number of times a beam of light crosses a face (I think). Do your objects have internal triangles? Try putting a cube or sphere at the position of your character and see if the shadows are now correct. I think, also, that the shadow zone has to be "capped", so maybe try varying the near and far values of the camera.
LunaRebirth
Posts: 385
Joined: Sun May 11, 2014 12:13 am

Re: Shadow Casting - Possible Bug?

Post by LunaRebirth »

mongoose7 wrote:I know virtually nothing about stencil shadows, but the inversion looks interesting. The stencil works by "counting" the number of times a beam of light crosses a face (I think). Do your objects have internal triangles? Try putting a cube or sphere at the position of your character and see if the shadows are now correct. I think, also, that the shadow zone has to be "capped", so maybe try varying the near and far values of the camera.
Not home right now, just wanted to answer some of the questions.
I'm sure the sphere will work, it's a little strange though.

By internal triangles, do you mean inside-facing faces? No, I've selected all in edit mode in blender and did Ctrl>N so all are outside faces. I've also enabled double-culling.

I know my near value is set to 30, which is directly behind the camera. But my far value is a very far away amount I'd have to check on when I'm back home.

Thanks for the reply! Hoping to get this worked out.:)
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Shadow Casting - Possible Bug?

Post by mongoose7 »

By internal triangles, I mean triangles inside the mesh. This is nothing to do with the orientation of triangles. Imagine a cube into which you put a triangle. Maybe sharing an edge, maybe not.

Don't know what you mean by saying the near value is behind the camera as the near value is *relative* to the camera, and +30 is clearly in front. Your scene must be *huge* to have a near value this large.
LunaRebirth
Posts: 385
Joined: Sun May 11, 2014 12:13 am

Re: Shadow Casting - Possible Bug?

Post by LunaRebirth »

My scene is pretty large. But I'm using objects for my terrain rather than heightmaps and such now.

The near value is set to 30. If I change it to 35, Then I start seeing things disappear from a bit further than camera view.
So 30 is directly behind the camera (for whatever reason). Moving it back doesn't help the problem, either.
The far value is set to 10000. Very huge, I know. Decreasing the size to around 500-2000, this also doesn't solve the problem. In fact, this makes it so if the object is partially outside of the far value, the shadow starts to invert. The further forward you move, the more the shadow inverts until it is diminished completely.

So far, messing with near and far values have not changed the problem

Edit:
Sorry, forgot to mention, no. There are no triangles or faces inside of the object. Only what is visible by standing outside of it.
But it is a building, so there are different angles of vertices. A square bottom, rectangle larger on top of it, then a roof with inset pulled out to look like a more realistic roof.
LunaRebirth
Posts: 385
Joined: Sun May 11, 2014 12:13 am

Re: Shadow Casting - Possible Bug?

Post by LunaRebirth »

Anyone have any other suggestions please??
LunaRebirth
Posts: 385
Joined: Sun May 11, 2014 12:13 am

Re: Shadow Casting - Possible Bug?

Post by LunaRebirth »

Also another thing I need help with..
There are two shadows and one shadow is really fat away from the object. I've seen multiple parts in this but nothing answering it. Is this a problem that can be fixed?
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Shadow Casting - Possible Bug?

Post by mongoose7 »

For this shadow technique, you have the responsibility for preparing your models. I had a brief look at the code and I see that it relies on the winding of the faces. So, you should make sure that all your faces are "naturally" facing outwards. You can't use tricks like disabling backface culling - the vertices really have to be in the right order. (I think the vertices need to be clockwise if you are on the outside.) You can substitute a simpler mesh for calculating the shadow, if this helps.
Post Reply