Problems with stencil shadows

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.
Post Reply
nurbs999
Posts: 4
Joined: Thu Aug 26, 2010 6:16 pm

Problems with stencil shadows

Post by nurbs999 »

Hi guys,

i playing around with the engine a little and i have a problem with realtime shadows.
Here are two sample screeners:
http://yfrog.com/nfshadows1j (a green box as object)
http://yfrog.com/n8shadows3j (a white torus as object)

I created the model with blender, all normals are pointing to the outside and exported is as '.x' file and '.obj' file.

here the code i use:

Code: Select all

	// create render device 1024x600x32,fullscreen_flag,stencil,no_vsync
	IrrlichtDevice *device = createDevice( driverType, dimension2d<u32>(1024, 600), 32, b_fullscreen, true, false, &receiver );
	
	// if creation failed for any reason
	if( !device )
		return 1;

IVideoDriver *driver = device->getVideoDriver();
ISceneManager *scmgr = device->getSceneManager();
IGUIEnvironment *guienv = device->getGUIEnvironment();
IAnimatedMeshSceneNode *node = 0;
IAnimatedMesh *tank = scmgr->getMesh( "tank.x" );
ILightSceneNode *light = 0;
	
if( tank ) {
	node = scmgr->addAnimatedMeshSceneNode( tank );
}
if( node ) {
	node->setMaterialFlag( EMF_LIGHTING, false );
	node->setPosition( vector3df( 1000.0f, 1050.0f, 3000.0f ) );
	node->setScale( vector3df( 70.0f, 70.0f, 70.0f ) );
	node->addShadowVolumeSceneNode();
	node->setMaterialFlag( video::EMF_NORMALIZE_NORMALS, true );
}
	
// create light
light = scmgr->addLightSceneNode( 0, vector3df( 900.0f, 1400.0f, 3000.0f , SColorf( 1.0f, 0.0f, 0.8f, 0.0f ), 800.0f );
if( light ) {
	light->setDebugDataVisible( EDS_BBOX );
	light->enableCastShadow( true );
	light->setVisible( true );
	ISceneNode *bill = scmgr->addBillboardSceneNode( light, imension2d<f32>( 30, 30 ) );
	if( bill ) {
		bill->setMaterialFlag( EMF_LIGHTING, false );
		bill->setMaterialFlag( EMF_ZWRITE_ENABLE, false );
		bill-setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
		bill->setMaterialTexture( 0, driver->getTexture( img/particlered.bmp" ) );
	}
}
scmgr->setShadowColor( SColor( 150, 0, 0, 0 ) );
EDIT: changed images
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

The current shadow implementation has a bug that creates a second shadow which may partially invert the correct shadow. This will hopefully be fixed in the next release.
nurbs999
Posts: 4
Joined: Thu Aug 26, 2010 6:16 pm

Post by nurbs999 »

thanks for the info. but how does the specialFX example work then?

and i just tried the latest svn version and i got this error, while compiling my program (libIrrlicht.s compiles fine)

Code: Select all

g++ -I/usr/include/irrlicht -O3 -ffast-math *.cpp -o ./main -lIrrlicht -lGL -lXxf86vm -lXext -lX11 -ljpeg -lpng -lbz2
/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.4/../../../../lib64/libIrrlicht.a(CIrrDeviceLinux.o): In function `irr::CIrrDeviceLinux::TextureToARGBCursor(irr::video::ITexture*, irr::core::rect<int> const&, irr::core::vector2d<int> const&)':
/root/irrlicht_trunk/source/Irrlicht/CIrrDeviceLinux.cpp:2011: undefined reference to `XcursorImageCreate'
/root/irrlicht_trunk/source/Irrlicht/CIrrDeviceLinux.cpp:2039: undefined reference to `XcursorImageLoadCursor'
/root/irrlicht_trunk/source/Irrlicht/CIrrDeviceLinux.cpp:2041: undefined reference to `XcursorImageDestroy'
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

You now need to add XCursor to the linker options (-lXcursor) and also install that library (probably libXCursors_dev).

But how did you compile? The Makefile already has that changed - do you use an own one?
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
nurbs999
Posts: 4
Joined: Thu Aug 26, 2010 6:16 pm

Post by nurbs999 »

yes, i use my own makefile but your tip works.
it compiles fine now, but i still have the shadow problem.

up-to-date images:
http://yfrog.com/mzshadows2j how it look like
http://yfrog.com/mztankvj how it should
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

The example has the same problems. Depending on your light settings and the camera, these problems are more or less visible. Maybe try to use a spot light instead of directional.
The tank has another problem, which is less visible in the example's meshes. Due to the mesh format (I guess it's 3ds) you get many seams in the mesh. These seams completely break the stencil shadow generation. Try to use different file formats.
nurbs999
Posts: 4
Joined: Thu Aug 26, 2010 6:16 pm

Post by nurbs999 »

oh, ok.
and i tried two formats, as mentioned in my first post. '.x' which is directX-fileformat and '.obj' files. on both files the shadows look the same.
i also tried to triangulate the model while exporting, but nothing changed.
but, if i export a simple cube or a torus without editing it, the shadows look good.

EDIT: also tried spot and directional light, no changes to the shadow
Post Reply