DepthShader – A Distance Based Shader for Papervision



depthshader2.png

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.

View the demo

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:
  1. depthShader = new DepthShader(light, 0xFFFFFF, 0x000000, 20, 400);
  2. bmp = Bitmap(new texture()).bitmapData;
  3. material = new ShadedMaterial(new BitmapMaterial(bmp), depthShader);
  4.  
  5. sphere = new Sphere(material,50);

And thats it!

Get the Source


16 Comments, Comment or Ping

  1. Very cool!

    February 28th, 2008

  2. AMAZING!
    thanks so much andy!

    February 28th, 2008

  3. stlucifer

    love you for sharing this ;)

    February 28th, 2008

  4. So so cool :)

    Meet the maker #papervision3d irc server freenode …

    (sorry Andy ;) )

    February 28th, 2008

  5. Evan

    Wicked!

    February 28th, 2008

  6. !!!!!!!

    (that’s all I can say.)

    February 28th, 2008

  7. BungaDunga

    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

  8. 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

  9. 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

  10. Cool! I like it!

    April 7th, 2008

  11. 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

  12. kelsolar

    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! :D

    July 1st, 2008

  13. 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”