Shadow casting from a manual object

Problems building or running the engine, queries about how to use features etc.
Post Reply
martinglish
Gnoblar
Posts: 16
Joined: Tue Mar 31, 2009 7:46 pm

Shadow casting from a manual object

Post by martinglish »

Hi,

Can anyone explain why I need to convert a manually created object (createManualObject) to a mesh before it will cast shadows properly?
When I add a manual object to a scene directly I get all sorts of mess in the shadows but if I create a mesh I have no problems.

The issue I think I will have is that the object I am creating is dynamic so can anyone comment on the effect of converting to a mesh over and over again? How do I delete the original manual object, and in what order?

Thanks ever so for any help and guidance....M
User avatar
Gucman
Orc
Posts: 467
Joined: Fri Dec 15, 2006 2:09 pm
Location: Poland, Lodz
x 1

Re: Shadow casting from a manual object

Post by Gucman »

Do you use texture or stencil shadows? I have not much experience with stencil shadows but texture shadows work nice with manual objects.
If you are using stencil shadows I would expect such behaviour in case manual object cannot provide proper shadow volume mesh.
martinglish
Gnoblar
Posts: 16
Joined: Tue Mar 31, 2009 7:46 pm

Re: Shadow casting from a manual object

Post by martinglish »

Thanks for the quick reply. I am trying to use stencil shadows at the moment, but when I tried texture shadows I didn't get any shadows at all.

So, assuming that I have to convert my manual objects to meshes, can anyone point me in the right direction of the sequence of steps needed to update the mesh when I change the manual object?

Thanks.
User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
x 6
Contact:

Re: Shadow casting from a manual object

Post by haffax »

Stencil shadows work with ManualObjects, but only when you use indices. This means you have to use either of the index/triangle/quad methods to build your ManualObject. This is recommended anyway.
team-pantheon programmer
creators of Rastullahs Lockenpracht
martinglish
Gnoblar
Posts: 16
Joined: Tue Mar 31, 2009 7:46 pm

Re: Shadow casting from a manual object

Post by martinglish »

That is the way I am building the geometry by adding points using position(), giving them a texture coordinate using textureCoord() then a normal (which doesn't seem to make any difference to the shadowing). I add three points then create a triangle by index. This loop is repeated until the shape is complete.

Do I need to add all the points first then make the triangle calls after?
User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
x 6
Contact:

Re: Shadow casting from a manual object

Post by haffax »

martinglish wrote:Do I need to add all the points first then make the triangle calls after?
Shouldn't matter.

Things to check:
  • myManualObject->hasEdgeList() should return true. Does it?
  • myManualObject->getEdgeList()->isClosed should be true. Is it?
team-pantheon programmer
creators of Rastullahs Lockenpracht
martinglish
Gnoblar
Posts: 16
Joined: Tue Mar 31, 2009 7:46 pm

Re: Shadow casting from a manual object

Post by martinglish »

hasEdgeList() returns true but getEdgeList()->isClosed returns false.

I simplified the code down to this...

m_roofManualObject->begin("SomeMaterialName");
m_roofManualObject->position(Ogre::Vector3(-5,0,0));
m_roofManualObject->textureCoord(0,0);
m_roofManualObject->normal(Ogre::Vector3::UNIT_Z);

m_roofManualObject->position(Ogre::Vector3(-5,5,0));
m_roofManualObject->textureCoord(0,1);
m_roofManualObject->normal(Ogre::Vector3::UNIT_Z);

m_roofManualObject->position(Ogre::Vector3(5,5,0));
m_roofManualObject->textureCoord(1,1);
m_roofManualObject->normal(Ogre::Vector3::UNIT_Z);

m_roofManualObject->position(Ogre::Vector3(5,0,0));
m_roofManualObject->textureCoord(1,0);
m_roofManualObject->normal(Ogre::Vector3::UNIT_Z);

m_roofManualObject->quad(0,1,2,3);
m_roofManualObject->end();

// this assert is fine
assert(m_roofManualObject->hasEdgeList());
// this assert fails.
assert(m_roofManualObject->getEdgeList()->isClosed);

Thanks for all your suggestions so far...M
User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
x 6
Contact:

Re: Shadow casting from a manual object

Post by haffax »

Stencil shadows don't work with this kind of mesh, whether it is an Entity or ManualObject doesn't matter. Stencil shadows require a closed surface to work properly. A single quad though has four open edges.

Either close the mesh, or use texture shadows, which for most cases are the better choice anyway.
team-pantheon programmer
creators of Rastullahs Lockenpracht
martinglish
Gnoblar
Posts: 16
Joined: Tue Mar 31, 2009 7:46 pm

Re: Shadow casting from a manual object

Post by martinglish »

Thanks again for your help.

OK, stencil shadows are out as the geometry cannot be closed easily.
Now I have a different problem. Using the previously submitted code if I generate the quad so that I can see the shape (anticlockwise winding) then I don't get a shadow. If I reverse the winding order I can't see the shape unless I look at it from the other side by moving the camera, but I can see the shadow. It almost looks like the shadow is being cast on the wrong side of the shape.

I hope that makes sense.
Thanks...M
martinglish
Gnoblar
Posts: 16
Joined: Tue Mar 31, 2009 7:46 pm

Re: Shadow casting from a manual object

Post by martinglish »

Further to my previous post, I'm still trying to get stencil shadows working. I updated my sample code to create a cube as follows.
The two checks for having an edge list and it being a closed shape both pass, and the shape look as I would expect but the shadows are still all over the place.

m_roofManualObject->position(Ogre::Vector3(5,5,-5));
m_roofManualObject->textureCoord(0,0);

m_roofManualObject->position(Ogre::Vector3(5,15,-5));
m_roofManualObject->textureCoord(0,1);

m_roofManualObject->position(Ogre::Vector3(-5,15,-5));
m_roofManualObject->textureCoord(1,1);

m_roofManualObject->position(Ogre::Vector3(-5,5,-5));
m_roofManualObject->textureCoord(1,0);

m_roofManualObject->position(Ogre::Vector3(5,5,5));
m_roofManualObject->textureCoord(0,0);

m_roofManualObject->position(Ogre::Vector3(5,15,5));
m_roofManualObject->textureCoord(0,1);

m_roofManualObject->position(Ogre::Vector3(-5,15,5));
m_roofManualObject->textureCoord(1,1);

m_roofManualObject->position(Ogre::Vector3(-5,5,5));
m_roofManualObject->textureCoord(1,0);

m_roofManualObject->quad(3,2,1,0);
m_roofManualObject->quad(4,5,6,7);
m_roofManualObject->quad(0,1,5,4);
m_roofManualObject->quad(7,6,2,3);
m_roofManualObject->quad(1,2,6,5);
m_roofManualObject->quad(4,7,3,0);

m_roofManualObject->end();

assert(m_roofManualObject->hasEdgeList());
m_roofManualObject->getEdgeList()->log(Ogre::LogManager::getSingleton().getDefaultLog());
assert(m_roofManualObject->getEdgeList()->isClosed);
IPC
Gnoblar
Posts: 11
Joined: Mon Aug 06, 2012 8:46 pm

Re: Shadow casting from a manual object

Post by IPC »

Hello

I have found the solution: http://www.ogre3d.org/forums/viewtopic. ... 86#p478686

Bye
I-PC
Post Reply