decals & planes

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
rt
Posts: 150
Joined: Sun Nov 30, 2003 6:54 am
Location: canada
Contact:

decals & planes

Post by rt »

i am wondering what is the correct way to go about attaching a 2D bitmap image to point on the 3D surface of a wall (assuming i already have the 3d position). is there a function for this? can i get the normal of the triangle of the surface?

lets say i import a .3ds cube which is 20x20x20 and texture it with a wood texture. now i want to add a decal to the top-plane of the cube. is this possible? the long term idea is to be able to add decals when bullets hit the surface of walls (http://www.flipcode.com/tutorials/tut_decals.shtml)

currently i try to emulate this by adding a new thin square mesh textured with the image i want and place it slightly above the surface of the cube.. but it looks wrong because you can see the decal is floating on the surface of the cube.. in addition, this also causes clipping problems because as the fps-camera moves away the 'decal' starts to flicker :( can the flicking be worked around?

this is what my hack decal looks like close up
Image

but as you see when you back away trouble happens
Image


any help is much appreciated! thank you.
rt
Posts: 150
Joined: Sun Nov 30, 2003 6:54 am
Location: canada
Contact:

random flicker

Post by rt »

after some trial and error it seems that the some nodes i add (such as the 'decals' which are just .3ds meshs scaled to have 0 y-dimension) appear to flicker randomly based on which order i have my lines of code and weather or not i run the game from inside msvc++ or standalone! for example the following lines produce no flicker when i run the game in debug mode from msvc++, but if i run the file directly from the folder then the flicker is there!

Code: Select all

irr::scene::IAnimatedMesh* mesh = smgr->getMesh("boards.3DS");
if (mesh) node = smgr->addAnimatedMeshSceneNode(mesh);
	if (node) {
		node->setMaterialFlag(irr::video::EMF_LIGHTING, false);
		node->setMaterialTexture( 0, driver->getTexture("ice.bmp") );
		node->setScale(irr::core::vector3df(10,0,10));
                                node->setPosition(pos);
	}
irr::scene::IAnimatedMeshSceneNode *hog = smgr->addAnimatedMeshSceneNode(mesh);
	if (hog) {
		hog->setMaterialFlag(irr::video::EMF_LIGHTING, false);
		hog->setMaterialTexture( 0, driver->getTexture("hog.bmp") );
		hog->setPosition(irr::core::vector3df(-300.0f,-2,0));
		hog->setScale(irr::core::vector3df(40,1,10));
                                hog->setPosition(pos2);
	}

however if i revsere the oder in which those nodes are created (from the same mesh) then the flicker is present when i run in debug mode from msvc++ but *not* present when i run the exe itself from outside of msvc++ !

has anyone else experience this problem of seemingly random nodes appearing to flicker when the FPS camera is moved away from them? i can't see why changing the order of creating the nodes should have any effect on the scene (or for that matter why the scene looks one way when run from within msvc++ and a different way when run byt itself)

should i create a debug or release build of irrlicht.dll?

http://www.teamtomko.com/game_debug_msvc.jpg <--- this is a srcreenshot when i run the game from msvc++

http://www.teamtomko.com/game_debug_msvc_flicker.jpg <--- this is a srcreenshot when i run the game from msvc++ and i simply reverse the order adding those nodes .. that's it! and the flicker somehow happens :(

is there a correct order to creating many nodes using the same mesh?
rt
Posts: 150
Joined: Sun Nov 30, 2003 6:54 am
Location: canada
Contact:

more trials and more errors

Post by rt »

after some more experimenting it seems that the 'flicker' problem occurs in both directx and opengl modes and on multiple windows systems. the only way to stop the flicker is to play around with the order of creating the nodes until it's gone. however since there appears to be no rhyme or reason to it this can take a lot of time... if anyone can offer some possible explanation or suggest a course of action it would help out a lot :?
hell_bird
Posts: 18
Joined: Mon Nov 03, 2003 12:30 pm

Post by hell_bird »

i think it's z-fighting (computing inaccuracies in the Z-Buffer). possible solutions are using the stencil-buffer or you can increase the distance between the decal and the wall, if the way wall-camera is longer
rt
Posts: 150
Joined: Sun Nov 30, 2003 6:54 am
Location: canada
Contact:

Post by rt »

hell_bird wrote:i think it's z-fighting (computing inaccuracies in the Z-Buffer). possible solutions are using the stencil-buffer or you can increase the distance between the decal and the wall, if the way wall-camera is longer
thx for the suggestion! i enabled the stencil-buffer but it seems to have had no effect. i don't want to increase the distance between the objects because i want the 'decal' to appear to be lying on the surface of an object.
after yet more experimenting it seems that not only my 'decals' but even thick objects start to 'flicker' and phase out as the camera moves away. as before, if i change the order of creating the nodes the flicker may or may not dissapear, or change in the degree of it's flickerness :?

one last observation.. if i move the camera far enough away and set it's setFarValue() large enough, then any object that is near a wall will start to show up on the other side of the wall they are near to! i tested it out using the 'hello world' tutorial, i simply added the woman model and then a .bsp map i created which is a simple boxed room. if you fly the camera away then you start to see the woman model flicker and show through the walls of the room.. it's driving me nuts! is there a way to increase z-buffer accuracy? or is that not at fault?
rt
Posts: 150
Joined: Sun Nov 30, 2003 6:54 am
Location: canada
Contact:

re-inventing the bsp?

Post by rt »

i thought i had searched the forum completly before, but i must have missed this thread (http://irrlicht.sourceforge.net/phpBB2/ ... .php?t=665).. it mentions the same effect of object showing through other object as the camera moves away.

i tried out the 'fix' described in that thread by setting my cameras nearvalue to 15.0f and fov to something like 0.1f and it seems to have fixed the flicker problem! but i am at a loss to understand why it fixes the problem... can anyone offer some suggestions?
rt
Posts: 150
Joined: Sun Nov 30, 2003 6:54 am
Location: canada
Contact:

fix the fix

Post by rt »

actually, the 'fix' of setting the nearvalue to a larger number only changes when the problem expresses itself. with the nearvalue large you can move farther away without any stripe artifacts, but they will still appear if you move even farther away. there is a dependance on the thinness of the model as well such that thinner models stripe at a shorter distance. i can not understand how no one else has encountered this problem :?

when i have a thin mesh near a wall it will start to stripe when i am about 170 units away ( mesh->getPosition().Y - camera->getPosition().Y = 170 ) .. what is a good number for indoor rooms? how large should they be?
Post Reply