Simple fog...

A forum to store posts deemed exceptionally wise and useful
R00mpel
Posts: 41
Joined: Sun Nov 09, 2003 10:12 am
Location: Russia, Nizhny Novgorod

Simple fog...

Post by R00mpel »

Hi all,
I've changed the engine a bit, so it now supports fog (only in Direct3D mode currently). I've simply added new virtual function to the CVideoDirectX8 class:

Code: Select all

void CVideoDirectX8::setFog(bool bUse, bool usePixelFog, bool useLinearFog, ul32 color, f32 start, f32 end, f32 density)
{
    pID3DDevice->SetRenderState(D3DRS_FOGENABLE, bUse);
    pID3DDevice->SetRenderState(D3DRS_FOGCOLOR, color);
    pID3DDevice->SetRenderState(usePixelFog?D3DRS_FOGTABLEMODE:D3DRS_FOGVERTEXMODE, useLinearFog?D3DFOG_LINEAR:D3DFOG_EXP);

    if(useLinearFog)                                                        
    {                                                                      
        pID3DDevice->SetRenderState(D3DRS_FOGSTART, *(DWORD *)(&start)); 
        pID3DDevice->SetRenderState(D3DRS_FOGEND,   *(DWORD *)(&end));   
    }

    else
    {
        pID3DDevice->SetRenderState(D3DRS_FOGDENSITY, *(DWORD *)(&density));
    }

    if(!usePixelFog)
        pID3DDevice->SetRenderState (D3DRS_RANGEFOGENABLE, true);

    return;
}
bool bUse determines whether the fog should be rendered;
bool usePixelFog determines whether pixel or vertex mode should be used;
bool useLinearFog determines whether linear or exponential fog should be used;
ul32 color determines the color of the fog (i.e. 0x00FF0000 is red, 0x0000FF00 is green, etc...). BTW, i've added

Code: Select all

typedef unsigned long ul32
to the irrTypes.h file.
f32 start and f32 end are the distances of the beginning and the end of LINEAR fog;
f32 density is the density of the EXPONENTIAL fog.

BTW, the fog has no effect on the skybox :( It also makes billboards with alpha channel look ugly :( Anyways, i hope this would be useful for someone... :roll:

P.S. Please excuse me for my bad english...
The only thing to fear is running out of beer!
saigumi
Posts: 921
Joined: Fri Aug 22, 2003 11:31 am
Location: St. Louis, MO USA
Contact:

Post by saigumi »

Cool.

I put this into my copy of the engine with one small change. I switched "ul32 color" with "SColor color" to use the current engine data structure.

Though, I did have to put in a recast of color to an (unsigned long) when calling SetRenderState().
Crud, how do I do this again?
R00mpel
Posts: 41
Joined: Sun Nov 09, 2003 10:12 am
Location: Russia, Nizhny Novgorod

Post by R00mpel »

Yeah, i think that's much better than using new typedef... I'm going to make the engine support OpenGL fog also. BTW, does anybody know how to make the fog to change the background?
The only thing to fear is running out of beer!
SuryIIID
Posts: 14
Joined: Mon Dec 29, 2003 8:54 pm
Location: Bulgaria..?

Post by SuryIIID »

Good job man , i missed the fog effect and i intended to implement it myself but you were faster (Molodiec :wink: )

And once again that's the power of an open source product it is much more literally natural than a closed product.I mean if there is a child wich has all the women and men in the world as it's parents i bet this will be the perfect child ever :)
BTW, does anybody know how to make the fog to change the background?
Do you mean fog to affect the skybox ?
Personally i prefer not to affect the SkyBox since this cause some unwanted effects like shading the corners of the box etc.

one way around i know is to cancel the fog before rendering the skybox and enable it before rendering the meshes.
Guest

Post by Guest »

great job man. But how do i call the function, i mean how do i get the handle to a IVideoDirectx8 class. Could you please post a bit of code showing this.. :(
R00mpel
Posts: 41
Joined: Sun Nov 09, 2003 10:12 am
Location: Russia, Nizhny Novgorod

Post by R00mpel »

Hi all!
I've finally implemented the setFog function for OpenGL, here it is:

Code: Select all

void CVideoOpenGL::setFog(bool bUse, bool usePixelFog, bool useLinearFog, SColor color, f32 start, f32 end, f32 density)
{
	f32 fogColorData[4];
	fogColorData[0] = color.getRed();
	fogColorData[1] = color.getGreen();
	fogColorData[2] = color.getBlue();
	fogColorData[3] = color.getAlpha();

	glFogf(GL_FOG_MODE, useLinearFog?GL_LINEAR:GL_EXP);
	if(useLinearFog)
	{
		glFogf(GL_FOG_START, start);
		glFogf(GL_FOG_END,   end);
	}		
	
	else
		glFogf(GL_FOG_DENSITY, density);

	glFogfv(GL_FOG_COLOR, fogColorData);

	bUse?glEnable(GL_FOG):glDisable(GL_FOG);
	return;
}
The bUsePixelFog parameter is not used.

I also slightly changed CVideoDirectX8::setFog function; now it looks like this:

Code: Select all

void CVideoDirectX8::setFog(bool bUse, bool usePixelFog, bool useLinearFog, SColor color, f32 start, f32 end, f32 density)
{
	pID3DDevice->SetRenderState(D3DRS_FOGENABLE, bUse);
	pID3DDevice->SetRenderState(D3DRS_FOGCOLOR, color.color);
	pID3DDevice->SetRenderState(usePixelFog?D3DRS_FOGTABLEMODE:D3DRS_FOGVERTEXMODE, useLinearFog?D3DFOG_LINEAR:D3DFOG_EXP);

	if(useLinearFog)          {                                                                       
        pID3DDevice->SetRenderState(D3DRS_FOGSTART, *(DWORD *)(&start));
        pID3DDevice->SetRenderState(D3DRS_FOGEND,   *(DWORD *)(&end));
    }

	else
		pID3DDevice->SetRenderState(D3DRS_FOGDENSITY, *(DWORD *)(&density));

	if(!usePixelFog)
        pID3DDevice->SetRenderState (D3DRS_RANGEFOGENABLE, true);

	return;
}
I could post this earlier, but i was too busy :roll:
But how do i call the function, i mean how do i get the handle to a IVideoDirectx8 class.
You don't need it. You only have to add this functions and to recompile the engine... Then you can call 'em this way:

Code: Select all

driver->setFog(true, true, true, video::SColor(0, 128, 128, 128), 1000.0f, 2000.0f, 0.01f);
That's all...

2SuryIIID: yeah, that's why i love open source products :) And i think you're right, shaded corners of the skybox look really ugly :wink: !
The only thing to fear is running out of beer!
DarkWhoppy
Posts: 386
Joined: Thu Sep 25, 2003 12:43 pm
Contact:

Post by DarkWhoppy »

Thanks :D Maybe Niko will add this to the next release of Irrlicht. ( I still don't get a DLL when compiling the engine myself... so could someone send me a Dev-C++ version of the DLL with the fog functio nin both devices? ) :cry:
Programmer of the Irrlicht Scene Editor:
Homepage - Forum Thread
Version 2 on its way!!
Robomaniac
Posts: 602
Joined: Sat Aug 23, 2003 2:03 am
Location: Pottstown, PA
Contact:

Post by Robomaniac »

I got the engine to compile with the added functions, but when i try to call the entry line

Code: Select all

   driver->setFog(true, true, true, video::SColor(0, 128, 128, 128), 1000.0f, 2000.0f, 0.01f);
the program crashes with the standard windows xp error

Thanks in advance

--The Robomaniac
R00mpel
Posts: 41
Joined: Sun Nov 09, 2003 10:12 am
Location: Russia, Nizhny Novgorod

Post by R00mpel »

Uhm... That's strange :? Which driver do you use - OpenGL or DirectX? You may also try to change the second parameter to false... And which exactly error do you get?
The only thing to fear is running out of beer!
cochi
Posts: 7
Joined: Sat Nov 22, 2003 2:20 pm
Location: Paderborn, NRW, Germany

Post by cochi »

The Irrlicht community is not organized very good... I know at least one person who already hacked fog into the engine (OGL+DX) and who was experimenting with volumetric fog last time he talked about it.

So what's the result? We have perhaps a dozend people working on the same thing, I see very rare releases of the engine and the left hand apparently doesn't know what the right is doing.

Just to mention uncoordinated GUI extensions (as mine), Linux patches which are merged only within weeks and such.

We need a CVS, more than one developer and a huge code cleanup of the engine internas. Otherwise this engine will collaps some time.
And I'm always wondering what many out there are doing when almost praying that "Irrlicht is the best" thing. There is no "best" at all and apparently they didn't look too deep into the engine sources, trying to trace malfunctions through duplicated code layers just down to non-standard constructs like Niko's list-class... Personally I'm quite fed up with Irrlicht and I know enough good coders who are with me.

Sorry, Niko I don't want to bash your work. In fact I like it quite much despite the points above. Otherwise I'd have quitted already. But if your engine doesn't adapt these points I'm afraid that all breaks down. And it would be a pity.
Just think about a CVS, as mentioned already in the #irrlicht Chat and assign 1-2 new developers with distinct areas to work in (e.g. GUI development and Linux maintainer).

Cya,
cochi
Robomaniac
Posts: 602
Joined: Sat Aug 23, 2003 2:03 am
Location: Pottstown, PA
Contact:

Post by Robomaniac »

I fully agree with cochi, of course with no offence to niko. We definately need a CVS and more developers working on the engine.

--The Robomaniac
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

Post by keless »

First, there is a thread with a similar theme over here:
http://irrlicht.sourceforge.net/phpBB2/ ... .php?t=913

anyhow, I do like the engine, but I'd like to say some things:

First, I know Niko has said he wants to be the only coder for the engine until Ver1.0 -- this kind of makes sense. If means the core of the engine will have a consistant design, and that he will be able to easily change any aspect of it as he discovers things while developing it out of its infancy.

That being said, your statement that there are "duplicated code layers" and your suggestion that the code being produced doesnt meet this ideal is disturbing. I havent had time to read the engine source myself, only use it-- and using it has been a dream. Without browsing the source, I should point out that IrrLicht is an abstract engine, and perhaps what you thought of as "duplicated layers" are merely abstractions to allow for differences in OS and underlying render APIs? I can only hope.

As for the rest of it-- I eagerly await the time when he does open the engine up to a core team. But until then, it might be wise to appoint a Linux maintainer, who's job it would be to make sure OS-independant and linux-specific fixes are incorperated into the engine (by kicking Niko's butt until they are) and by compiling and releasing the latest and greatest Linux .SOs, and what have you. (all this externally from niko's power over the code, however)

The bit about Niko's list class: as long as its easier to debug than std::vector and as long as its efficient, I have no problem with a non standard set of core data-structs.

Also, I would love to read a good .PLAN or mission statement from Niko in the next week or so. Anyhow, I think you've made me curious enough to stop working and go read the engine source, you devil you. And if I find its not as beautiful inside as it is out, Im going to kick Niko's butt until it is! :twisted:
a screen cap is worth 0x100000 DWORDS
Serg Nechaeff
Posts: 162
Joined: Wed Nov 26, 2003 5:24 pm
Location: Europe

Post by Serg Nechaeff »

cochi wrote:I'm always wondering what many out there are doing when almost praying that "Irrlicht is the best" thing. There is no "best" at all and apparently they didn't look too deep into the engine sources,
cause we out here are developing games, not engines :)
I mean I dont have enough experience to explore irrlicht's sources, but if you and other coders say so, then maybe Niko will take that into consideration... and will also start a mailing list ;)
http://www.javazing.com
P-III-950, WinXP, GeForce FX5600 128 MB ForceWare 52.16, DX9, Eclipse IDE, JRE 1.6
sirshane
Posts: 31
Joined: Tue Oct 14, 2003 5:02 am
Contact:

Post by sirshane »

I'm just posting to support Cochi's comments.

I should just say up front that I don't think Niko's code completely sucks. If I did, I wouldn't have been interested in Irrlicht in the first place. But once you really start to get into the engine's core code, I mean really get involved looking at it, you start to realize that much of it is actually very poorly written.

I do not wish to offend Niko, I appreciate the simplicity of the engine, as do so many other people on this forum. That's the great thing about Irrlicht, it's easy to use. But it's the worst pain in the ass to actually work on, or at least it is in my opinion.

The community needs CVS, and i've talked to Niko about that. He agrees. Yet we still haven't seen it. This whole 'waiting for version 1.0' thing is rediculous. When is version 1.0? That could be tommorrow, six months from now, or 10 years from now. Who knows. Look at CrystalSpace. That engine has been in development for more than seven years and it still isn't version 1.0.

If Irrlicht is to succeed, it needs to be truly released to the community. We need CVS, mailing lists, bug reporting tools, etc. We need to open up the communication so more people can work on it more efficiently.
-Shane
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

Post by keless »

I also support the CVS notion, but if Niko does open up the library, its got to be to an organized and prepared team of experienced coders who are motivated to produce.

At the same time, they need to be able to communicate with each other, and debate about things before implementing them. This can be tough if team members are on opposite sides of the world and have different sleep schedules (my personal experience from GTEngine).

Well, I dont want to say too much, as I am apt to have a big mouth, and Niko has yet to make an appearance in all of this.
a screen cap is worth 0x100000 DWORDS
Post Reply