We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Fog for all! (Read 6117 times)
Fog for all!
Oct 20th, 2005, 4:32pm
 
I've bundled up my fog routines into a library for processing, so anyone who wants can have some simple fog in their sketches.

I've created a simple site which describes how to use the library, downloads, and a couple of examples of it in action.

http://www.hardcorepawn.com/fog/

Any comments or suggestions, please let me know, and I'll see what I can do.

I had wanted to make it work regardless of wether you're using P3D or OpenGL, however I couldn't work out a way of having it work transaprently no matter which you were using, since the OpenGL fog is all setup within setup() (effectively) and can't be run at a certain time like mine can.

EDIT: Just realised I forgot the compile switches to force it to target java 1.1, so it may currently only work in 1.4 or newer. I'll build a backwards compatible version tomorrow.


Update: All sorted now, should work with all the version of Java that Processing supports.

UPDATE: now also works with OPENGL, whilst still working with P3D, and being usable in online sketches with P3D.
Re: Fog for P3D
Reply #1 - Oct 21st, 2005, 2:53am
 
Very nice!  It'd be cool to see this implemented in P3D since I imagine it'd run a little faster if running in the pipeline.  I cannot see a huge reason for having it run at an arbitrary time, though, is it possible to make the library run it as a post() draw routine?

You could modify the setupFog() to include the color, or maybe a setColor() method, then use applet.registerPost(this); to automatically add the fog after the frame has been rendered.  Then for OpenGL you could simply call the GL functions for fog handling.

Upon looking at GL's fog routines, it sounds like its a bit more advanced, allowing for different fog modes (even a vertex-based fog mode).

Marcello
Re: Fog for P3D
Reply #2 - Oct 21st, 2005, 10:59am
 
It probably would be a bit quicker if integrated with the PGraphics3 library directly, but that would require a custom version of processing, and after the quick look at the Processing source, I'm not entirely sure how to add it in, and supply a patch so it can be integrated into the main code.

Unfortunately, if fog ran in post, you wouldn't be able to draw a 2D interface over a 3D scene without worrying about it being fogged, and I wanted to try to make sure it would be useful in as many situations as possible.

As it is, I have to set the zbuffer values of the area I want to draw my interface to MAX_FLOAT (to avoid them being drawn behind the scene), then call image(...) to draw them, and if fog ran after that, they'd probably be fogged out to some extent.
Re: Fog for P3D
Reply #3 - Oct 21st, 2005, 5:03pm
 
I seem to recall a method for enabling/disabling the depth test, but perhaps it was removed...

But yes, your point is quite valid, you wouldn't necessarily want fog on everything (though if it were integrated into P3D, it'd run it as it drew polygons, so some form of enable/disable would be sufficient to solve that problem).  However, looking through PTriangle.java, I'm not sure where the best place to add such code would be, anyhow, certainly something for whomever is working on or has a good understanding of the renderer.

Marcello
Re: Fog for all!
Reply #4 - Oct 27th, 2005, 2:57pm
 
I've managed to work out a way to get the fog to work with OPENGL as well as P3D, and it seems to all be fine as far as I can tell at the moment.
Re: Fog for all!
Reply #5 - May 26th, 2006, 1:05pm
 
Where's the fog gone, John?

broken link when attempting to download.

Re: Fog for all!
Reply #6 - May 27th, 2006, 12:29am
 
Oops, I got the link wrong when I did an updated version. Should work now.
Re: Fog for all!
Reply #7 - May 28th, 2006, 9:25am
 
Thanks John, that sorted it!
Re: Fog for all!
Reply #8 - Feb 27th, 2008, 9:24pm
 
Doesn't work with 0135 beta?

my code (as shown on the lib site)

import hardcorepawn.fog.*;

fog myFog;
float nearDist;
float farDist;
color fogColor;
void setup()
{
size(200,200,P3D); //OPENGL also works
myFog=new fog(this);
nearDist=150;
farDist=500;
myFog.setupFog(nearDist,farDist);
fogColor=color(64,128,256);
myFog.setColor(fogColor);
// other setup stuff ...
}

void draw()
{
//... draw all your 3d stuff here ...
// you can also change the fog distance with OPENGL:
//myFog.setDist(800,1200);
myFog.doFog();
}




PROBLEM: /tmp/build10964.tmp/Temporary_6220_6721.java:3:1:3:3: Semantic Error: Type "fog" was not found.


Anyone?
Re: Fog for all!
Reply #9 - Feb 27th, 2008, 9:37pm
 
I've no idea what causes this and haven't been able to fix it, but you can get around the issue by doing:

Code:
hardcorepawn.fog.fog myFog;


I've not really had any time to try to update the library or pages unfortunately.
Re: Fog for all!
Reply #10 - Apr 5th, 2008, 2:46am
 
Yeah...
I noticed that, too.
And I am actually also not sure, why P135 would do that, since it seems to work just fine with other libraries.
The only difference that I can see is the import statements after the package declaration.
Anyway, there is another solution.

Just import hardcorepawn.fog.fog directly.
Then the references to fog and everything else work.
Re: Fog for all!
Reply #11 - May 5th, 2009, 9:53am
 
JohnG, this works great, but is there any way to have it also apply to textures?  It fades all the lines/vertexes great, but I'm then left with all my textures.  I'd like to fog them out as well.
Re: Fog for all!
Reply #12 - May 5th, 2009, 10:27pm
 
Love it. thanks a lot! I was wondering how I was gonna do this, and thought I would do a quick search first.

Thanks
Re: Fog for all!
Reply #13 - Jun 11th, 2009, 3:00pm
 
its not working with the latest processing version, right? any plans on updating it ?
Re: Fog for all!
Reply #14 - Jun 13th, 2009, 3:23am
 
the moving camera example is the best one, cool effect! Wink
Page Index Toggle Pages: 1