Page 1 of 1

Problems with stencil shadows

Posted: Thu Aug 26, 2010 6:30 pm
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

Posted: Thu Aug 26, 2010 10:14 pm
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.

Posted: Thu Aug 26, 2010 11:11 pm
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'

Posted: Fri Aug 27, 2010 12:36 am
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?

Posted: Fri Aug 27, 2010 12:53 am
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

Posted: Fri Aug 27, 2010 3:41 pm
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.

Posted: Sat Aug 28, 2010 10:31 am
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