This little experiment is a proof of concept of fog using papervision’s render layers and the color transform object. This would make a lot of sense for the frustum camera where the culled triangles wouldn’t just pop out of void but would nicely fade in. Also to my surprise there is almost no performance penalty for the fog.
Take a look here or download the source.
Other interesting effect is using alphas on the render layers.
May 30, 2008 at 3:31 pm |
Beautiful, as usual.
May 30, 2008 at 3:56 pm |
Thanx Dude!
I love your vectorvision demo, I tried to comment on it but my comment turned all japanese
May 31, 2008 at 1:20 am |
Oh,Sorry for that. That means that “your comment is waiting for the author’s permission.”
Since I sometimes got spams on my comments, I changed the setting into the one that requires my permission so as to protect visitors from visiting stupid sites.
But now your comment is displayed
Btw, thank you for visiting.
June 13, 2008 at 10:28 pm |
I was looking at the math you used to place the do3d objects in there respective renderLayers and noticed that you were not actually utilizing any of the odd indexed renderLayers? I think this is do to the Left Bit shift that you used.
I’m just wondering cuz I am trying to learn to use bitwise operators in my code and I have to say its been kicking my butt. So when I saw you using it successfully in your code I though “Hey, lets break down the math so I can learn to use it”.
Just wondering, if I’m wrong tell my I’m a dork. But please enplane why I’m a dork.
Thanks, and the fog simple kicks ass. I love it.
June 17, 2008 at 6:07 pm |
Hi Brandon,
Glad you like the fog, the bitwise operations is a different story, they can be either handy or very fast or both. Unfortunately for me in the fog source the left bit shift is rather useless as it is equivalent to casting a Number to int and the multiplying it with 2 which is rather stupid than smart because this way i end up with half the layers not being used at all.
thanx for pointing it out
August 2, 2008 at 4:45 pm |
I’d really like to try out the source, downloaded it, but I get many compilation errors, mostly about the renderLayers, eg:
1119: Access of possibly undefined property renderLayerManager through a reference with static type org.papervision3d.view:Viewport3D.
I’m using the latest great white revision through svn, are there some extra classes I need to download? thanks for any advice.
August 2, 2008 at 5:05 pm |
Craigie, papervision has been evolving at amazing pace for the past few months, big changes to pv3d often cause old code to break, next time I publish source code I’ll include the pv3d revision with it.
However if you are interested in the fog itself you should look at this post of Andy Zupko, he has build fog into pv3d as a renderer filter.
August 13, 2008 at 9:02 am |
Cool. Come by and hypnotize yourself if you please
March 5, 2009 at 9:42 pm |
Hi,
Your tutorial looks great and runs fast, I have to do an all nighter and need to get fog working, I’m using the latest SVN, so the RenderLayers do not work. Can I trouble you to show me how to convert your code to use the new Viewpoint layers?
Thanks!
private function setupFog():void {
renderLayers = [];
renderLayers.push(viewport.renderLayerManager.defaultLayer);
for(var i:int = 0 ; i < fogSteps ; i++){
var l : RenderLayer = new RenderLayer();
viewport.addRenderLayer(l);
// l.alpha = i * (1 / fogSteps);
var ct : Color = new Color();
ct.setTint(0xffffff, i * (1 / fogSteps));
l.transform.colorTransform = ct;
renderLayers.push(l);
}
}
private function sortObjectsForFog(e:Event):void {
for each(var do3d:DisplayObject3D in scene.children){
if(!do3d.culled)do3d.renderLayer = renderLayers[Math.abs( Math.min(fogSteps, (do3d.screenZ) * .08 << 1 ))];
}
}
March 9, 2009 at 2:37 pm |
Hi Scott, this code has become somehow obsolete now as papervision has got a build in fog, check Andy’s post on fog.
September 2, 2009 at 7:49 pm |
I am going insane trying to figure out how to get a depth of field on a site I’ve been working on. I wanted to use your fog source code but cannot get it to flow with my code
ive looked all over the web and cannot find anything that can work without using basicview
i try to run the code:
var fogMaterial:FogMaterial = new FogMaterial(0xffffff);
var fogLayers:int = 8;
var minDepth:Number = 3000;
var maxDepth:Number = 60600;
but i get the error:
override public function drawTriangle(tri:RenderTriangle, graphics:Graphics, renderSessionData:RenderSessionData, altBitmap:BitmapData = null, altUV:Matrix = null):void
September 2, 2009 at 7:51 pm |
looks like my message cot cut off?? not sure but any help would be much appreciated,
thank you
February 7, 2010 at 8:21 am |
I just had to say thankyou for posting. I happened on your web site from bing and I wanted say i’m impressed.