One thing shaders currently don't take into account is distance - so this is a quick shader I wrote which is entirely based on distance. Keep in mind it would be very easy to integrate with other shaders - and I will probably do that sometime down the road.
DepthShader takes 5 parameters:
- light:LightObject3D - your light
- lightColor:Number - color your want your light
- ambientColor:Number - color your want your shadows
- minDist:Number - the minimum distance you want the shading applied too. Everything closer than this distance will have full light color.
- maxDist:Number - the maximum distance you want shading applied too. Everything beyond this distance will be fully shaded.
So, to put this into use, you simply use it like you would any other shader:
Actionscript:
-
depthShader = new DepthShader(light, 0xFFFFFF, 0x000000, 20, 400);
-
bmp = Bitmap(new texture()).bitmapData;
-
material = new ShadedMaterial(new BitmapMaterial(bmp), depthShader);
-
-
sphere = new Sphere(material,50);
And thats it!

16 Comments, Comment or Ping
Very cool!
February 28th, 2008
AMAZING!
thanks so much andy!
February 28th, 2008
love you for sharing this
February 28th, 2008
So so cool
Meet the maker #papervision3d irc server freenode …
(sorry Andy
)
February 28th, 2008
Wicked!
February 28th, 2008
!!!!!!!
(that’s all I can say.)
February 28th, 2008
How’d you get that nice bloomy effect? Is that the work of the shader or an effects layer you stuck on top of the scene? Either way, looks really nice. It’d be nice to have this integrated into the other shaders for realism’s sake.
February 28th, 2008
Who would knew that, when I’ve done http://www.flashsandy.org/demos/fog I thought we were behind you, guys, now it seems we were not…
February 29th, 2008
this has been a great help.. I’m trying to get some basic shading going on a transparent bitmap, and this shader seems to be creating a flat shade on the plane that I’m using.
could you post the source for the full material/light/shader creation?
thanks again.
March 23rd, 2008
Cool! I like it!
April 7th, 2008
First of all…looks great!!!
BUT
I have a question…Am not able to solve it. I am using a MovieClip as basic material. Parts of this MC are transparent.
When I use the depthshader, the transparent parts get a solid color…(and so does my plane
) Allowtransparancy doesnt do the trick…
Do u know how to solve this one?
June 15th, 2008
Excellent, that was exactly what i was searching for. Thank you for sharing it!
i also got a question, as many of us:
Is it possible to have a plane with the shadow effect applying on the different segment? (for now, when i use the DepthShader, the whole plane is lighted the same way, even with a small maxDistance)
thanx!
July 1st, 2008
I have the same problem, anyone have a solution for this:
WINK
First of all…looks great!!!
BUT
I have a question…Am not able to solve it. I am using a MovieClip as basic material. Parts of this MC are transparent.
When I use the depthshader, the transparent parts get a solid color…(and so does my plane
) Allowtransparancy doesnt do the trick…
Do u know how to solve this one?
July 18th, 2009
Reply to “DepthShader – A Distance Based Shader for Papervision”