shadow problem

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Guest

shadow problem

Post by Guest »

Hi I am pretty new in designing effects with irrlicht. I have some problems with shadow even I looked at the tutorial about effects where niko shows the dynamic shadow and light.

So I tried it my self with a simple mesh and no dynamic shadow--- and it won't work.

Here are some basic questions:

1. it didn't make any differences wether I created a ILightSceneNode or not? do I have do create a lightscenenode in order to get shadows? if yes do I have to do anything with the lightscenenode besides creating it?

2.Do I have to do anything else than this:
marker->addShadowVolumeSceneNode();
smgr->setShadowColor(irr::video::SColor(220,0,0,0));
to create a shadow? Where do I have to set the position of the shadow if I don't need the light?

3. Do I need that world created in the tutorial around the mesh? Or should I see the shadow even on the pure background color or on an image?

4. If I have done anything right, why won't I see the shadow?

Thanks in advance
Guest

Post by Guest »

Please could someone help?
Evil Mr Sock
Posts: 37
Joined: Fri Jul 02, 2004 5:36 pm
Location: Albany, NY
Contact:

Post by Evil Mr Sock »

Yes, you need to create a light - and then, to see the shadow, you're going to have to have whatever's casting the shadow somewhere inbetween the light and some sort of surface for the shadow to be drawn on.
------------------------------------------
A monkey poured coffee in my boots.
------------------------------------------
Guest

Post by Guest »

Thank you Evil Mr Sock!!
But still some questions. What do you mean with "whatever's casting the shadow"? You mean any mesh with that?

And the surface should be what? I can't be just a bmp or jpg where the shadow is drawn on but it has to be other meshes?
thesmileman
Posts: 360
Joined: Tue Feb 10, 2004 2:20 am
Location: Lubbock, TX

Post by thesmileman »

What do you mean with "whatever's casting the shadow"?
What his whole post means is that you have to have one object, take the ground for instance, and another object, say a person, and a light. These objects must be in a row such as light, then a person, then the ground, just as the same if you step outside.

Now all you need to cast a shadow is import a mesh of the ground (This could really be anything you wanted) then another mesh of a person(This also could be anything you wanted) and then create a light or dynamic light. As long the scene would cast a shadow in real life(This does not mean reflected light and such) then it will cast a scene in Irrlicht if you have it set up to do so. Also you should use directx instead of opengl as I do not believe that shadows work as well in opengl yet as they do in directx.
Guest

Post by Guest »

Ok I did that, but it is not working.

Code: Select all

int main(){
irr::IrrlichtDevice *device = irr::createDevice(irr::video::EDT_DIRECTX9, irr::core::dimension2d<irr::s32>(512, 384), 16, false, false, 0);
	irr::video::IVideoDriver* driver = device->getVideoDriver();
	irr::scene::ISceneManager* smgr = device->getSceneManager();

	irr::scene::ICameraSceneNode* camera = smgr->addCameraSceneNode(0,irr::core::vector3df(0.0f, 0.0f, -10.0f),irr::core::vector3df(0,0,0));


	irr::scene::IAnimatedMesh* MyMesh = device->getSceneManager()->getMesh("figure.ms3d");
    irr::scene::IAnimatedMeshSceneNode* mynode= smgr->addAnimatedMeshSceneNode(MyMesh,0,-1,irr::core::vector3df(1,2,0),irr::core::vector3df(0.0f,0.0f,0.0f),irr::core::vector3df(0.05f,0.05f,0.05f));
	mynode->setMaterialTexture(0, driver->getTexture("cloth.JPG"));
	mynode->setMaterialFlag(irr::video::EMF_LIGHTING, false);


//GROUND
irr::scene::IAnimatedMesh* MyUnderMesh = device->getSceneManager()->getMesh("cube.3ds");
    irr::scene::IAnimatedMeshSceneNode* underground = smgr->addAnimatedMeshSceneNode(MyUnderMesh,0,-1,irr::core::vector3df(1,-2,0),irr::core::vector3df(-35.0f,0.0f,0.0f),irr::core::vector3df(0.5f,0.03f,0.1f));
	underground->setMaterialTexture(0, driver->getTexture("gr.jpg"));
	underground->setMaterialFlag(irr::video::EMF_LIGHTING, false);


//LIGHT
    irr::scene::ILightSceneNode* node = smgr->addLightSceneNode(0, irr::core::vector3df(1,1,1), 
        irr::video::SColorf(1.0f, 0.6f, 0.7f, 1.0f), 800.0f);

    irr::video::SLight *lm =&node->getLightData(); 
    lm->DiffuseColor = irr::video::SColorf(1.0f, 1.0f, 1.0f, 1.0f);

    mynode->addShadowVolumeSceneNode();	
    smgr->setShadowColor(irr::video::SColor(0,0,0,0));


while(device->run()) {
          driver->beginScene(true, true, irr::video::SColor(0,50,50,50));
          smgr->drawAll();
          driver->endScene();
}

device->drop();
return 0;
}
Where is the error?
thesmileman
Posts: 360
Joined: Tue Feb 10, 2004 2:20 am
Location: Lubbock, TX

Post by thesmileman »

try chaning

Code: Select all

underground->setMaterialFlag(irr::video::EMF_LIGHTING, false); 
to

Code: Select all

underground->setMaterialFlag(irr::video::EMF_LIGHTING, true); 
Rocketeer
Posts: 9
Joined: Sun Jul 11, 2004 9:13 am
Contact:

Post by Rocketeer »

I'm fairly sure you also need to enable the stencil buffer for shadows... I could be wrong, but try using the line

Code: Select all

irr::IrrlichtDevice *device = irr::createDevice(irr::video::EDT_DIRECTX9, irr::core::dimension2d<irr::s32>(512, 384), 16, false, true, 0);
(Note the last-but-one parameter is now true)

See the api docs for more info:
http://irrlicht.sourceforge.net/docu/na ... .html#a177
Guest

Post by Guest »

mmmh, doesn't work...
in the api it says: Specifies if the stencil buffer should be enabled. Set this to true, if you want the engine be able to draw stencil buffer shadows. Note that not all devices are able to use the stencil buffer. If they don't no shadows will be drawn.

So which device is not able to? because it seems as mine is not...

the other suggestion made the downsite of the underground black but no shadow from the mesh on the underground is drawn on top of the cube.
thesmileman
Posts: 360
Joined: Tue Feb 10, 2004 2:20 am
Location: Lubbock, TX

Post by thesmileman »

Anonymous wrote:the other suggestion made the downsite of the underground black but no shadow from the mesh on the underground is drawn on top of the cube.
not entirely sure what you mean by the sentance above. but did you do this:

Code: Select all

 underground->setMaterialFlag(irr::video::EMF_LIGHTING, false);
for all of your mesh node as well or just underground? If not do it for the mesh as well.
Guest

Post by Guest »

I tried to do it with both of my meshes (the underground and the figure on the underground). the bottom of the underground turned black and some parts of the figure turned black, but there is no shadow of the figure drawn on the underground...
thesmileman
Posts: 360
Joined: Tue Feb 10, 2004 2:20 am
Location: Lubbock, TX

Post by thesmileman »

Ahhh I think I see the problem. It is this line of code I think:

Code: Select all

 smgr->setShadowColor(irr::video::SColor(0,0,0,0)); 
Correct me if I am wrong but you have set the alpha value, the first value in SColor, to 0 which would make it a completly transparent shadow! :shock:

Try something like this

Code: Select all

 smgr->setShadowColor(irr::video::SColor(180,0,0,0)); 
for a nice slightly transparent shadow
Guest

Post by Guest »

Ohhhhh.... it works with OpenGL!! I can see a shadow when I use OpenGL . I can't see any shadow using Direct3D. Is there any chance to get it to work with Direct3D too? because I probably have to use DirectX8 or 9 for my project.
thesmileman
Posts: 360
Joined: Tue Feb 10, 2004 2:20 am
Location: Lubbock, TX

Post by thesmileman »

have you tried directX 8 or just 9
Guest

Post by Guest »

I tried it with both , DirectX8 and 9. In both cases I can't see a shadow.

By the way, thanks for the hint but 0 is not transparent but solid...
Post Reply