[SOLVED] How do I add fog?

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

[SOLVED] How do I add fog?

Post by Guest »

How can I add the fog effect so that object fade to black in the distance? And please keep the answer simple cause I'm new. Thanks
Guest

Post by Guest »

you can do it with the irr::video::IVideoDriver::setFog() function.

I think, it is not necassary explain how to use this function.
Guest

Example?

Post by Guest »

Could someone write an example showing how to use it?
afecelis
Admin
Posts: 3075
Joined: Sun Feb 22, 2004 10:44 pm
Location: Colombia
Contact:

Post by afecelis »

Code: Select all

video::IVideoDriver* driver = device->getVideoDriver();
driver->setFog(SColor(0,125,125,0),true, 0,4000); //fog color-final values= amount of fog, distance
Image
Asterisk Man
Posts: 62
Joined: Wed Jun 09, 2004 5:51 am

Post by Asterisk Man »

remember that you have to set the fog flag to true on the material on the node that you wanna have fog in.
knightoflight
Posts: 199
Joined: Sun Aug 24, 2003 5:47 pm
Location: Germany

Post by knightoflight »

for my understanding: (i try in my broken english, excuse)
Does the fog work only for each node, so nodes that are more far away are more grey -
or does it work ON a node, so parts of the node (for example a big node like a big house) that are more far away are more grey ?
puh
Posts: 356
Joined: Tue Aug 26, 2003 3:53 pm

Post by puh »

knightoflight: second variant is correct. Look at the screen, the wall on the left is the same node.
Image
knightoflight
Posts: 199
Joined: Sun Aug 24, 2003 5:47 pm
Location: Germany

Post by knightoflight »

Hi Puh ! Thanks. Irrlicht rules :-)
puh
Posts: 356
Joined: Tue Aug 26, 2003 3:53 pm

Post by puh »

Definitely :!:
Guest

Post by Guest »

Dose fog work on OpenGL?
Guest

Post by Guest »

yes it works on opengl :wink:
Dogs
Posts: 195
Joined: Wed Sep 15, 2004 1:04 am
Location: michigan

Post by Dogs »

Hello I saw this post and figured id play around with fog some..

Well the code is in and I have no errors..

But I cant see any fog anywhere..
Ive changed the values all of them many times...

Could it be the fog is below my level or above or beside it..
Is there a way to move it around or is a large ground type fog...
Ive never seen the fog in action for irrlicht so wanted to figure it out someday anyway..

I read over the api section for it and everything looks ok.. I dont see anything about vector for placing it in diff locations..
Where exactly does the fog appear with your code afecelis? :?
afecelis
Admin
Posts: 3075
Joined: Sun Feb 22, 2004 10:44 pm
Location: Colombia
Contact:

Post by afecelis »

With my level called levelnode:

Code: Select all

levelnode->setMaterialFlag(EMF_FOG_ENABLE,true); //enables fog
driver->setFog(SColor(0,125,125,0),true, 0,4000); //fog color-final values= amount of fog, distance

result (vey soft, orange fog in the corners):
Image

after teaking some values:

Code: Select all

driver->setFog(SColor(0,125,125,0),true, 0,1000);
result: a denser fog

Image

hope it helps
Image
Dogs
Posts: 195
Joined: Wed Sep 15, 2004 1:04 am
Location: michigan

Post by Dogs »

With my level called levelnode:


levelnode->setMaterialFlag(EMF_FOG_ENABLE,true); //enables fog
driver->setFog(SColor(0,125,125,0),true, 0,4000); //fog color-final values= amount of fog, distance


Where is the name of your level at lol...
I dont have any name for my level that I know of..
Im kinda lost where you got levelnode from?

Sorry to be a pest like this but I dont understand :(
afecelis
Admin
Posts: 3075
Joined: Sun Feb 22, 2004 10:44 pm
Location: Colombia
Contact:

Post by afecelis »

Code: Select all

video::IVideoDriver* driver = device->getVideoDriver();
	scene::ISceneManager* smgr = device->getSceneManager();

	device->getFileSystem()->addZipFileArchive("./data/irrlicht.pk3");
	
	scene::IAnimatedMesh* level = 0;
	level = smgr->getMesh("irrlicht.bsp");
	
	scene::ISceneNode* levelnode = 0;
	levelnode = smgr->addOctTreeSceneNode(level->getMesh(0));	
	levelnode->setMaterialFlag(EMF_FOG_ENABLE,true); //enables fog
	levelnode->setPosition(core::vector3df(0,-100,0));
	levelnode->setScale( irr::core::vector3df(1,1,1) );

	driver->setFog(SColor(0,125,125,0),true, 0,1000); //fog color-final values= amount of fog, distance	
	driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);
Image
Post Reply