Fast Shadows

 

Available in the Unity3D Asset Store

Fast Shadows is a fast, easy to use substitute for the Unity3D Blob Shadow Projector. It is  heavily optimized for mobile devices. Raycasting determines where shadows should appear. Shadows are a square mesh with a transparent material that hovers above a surface. Fast Shadows is VERY fast!

  • One draw call for many shadows
  • Works with Unity3D Free (Indy) version
  • Multiple shapes can share an atlas
  • FAST, FAST, FAST! Did I mention it is fast?
How To Use It
Video Of Fast Shadows On Uneven Terrain
Live Demo
Try the live Demo
Easy To Use
Add the FS_ShadowSimple script to your object and a shadow will appear when you press play. No scripting required!
Features
  • All shadows in a scene can share a single draw call
  • Works with the free indy version of Unity3D
  • A layer mask can be used to specify which surfaces show shadows
  • Can control the maximum projection distance. Shadows fade and disappear as they approach this distance
  • ‘Static’ shadows (shadows that don’t move) are calculated only once and have no overhead in Update. A scene can have hundreds of static shadows on a mobile device.
  • Different shadows can have different shapes and still share a single draw call using a texture atlas
  • Shadows can be cast by a light object (or any game object) or by specifying a light direction vector
  • Can use either the provided shadow material, or your own shadow material for interesting effects.
  • Shadow rotation matches object’s rotation
  • Perspective and orthographic projection
  • Easy to use. No Scripting required.
  • FAST, FAST, FAST! Did I mention it is fast?

 Limitations

These shadows are very fast approximations of shadows. There are some limitations:

  • Shadows are NOT volumetric; the size and the orientation of the shadows DO change, but the shape of the silhouette does not. Shadows use a light cookie (as does the blob shadow projector). The shape or the silhouette in the light cookie will not change as an object tumbles.
  • Shadows work best when cast on smooth surfaces. The shadow will not deform to match the contours of the surface. Spikes can penetrate the shadow and grooves are ignored.
  • Shadows only project onto one surface at a time. This creates a slight discontinuity as shadows pass from one object to another.
  • The edge of a shadow can extend beyond the object it is being projected upon.

For moving objects, or transparent shadows with blurry edges, these oddities are hardly noticeable.

Screenshots

 

 

 

 

 

 

 

 

 

Fast Shadows was created by Ian Deane. Other assets by Ian Deane include:

Fast Shadows is available in the asset store.

18 thoughts on “Fast Shadows”

    1. The shader does not calculate the shadow image. Each shadow requires a material. If this material field has not been set then the script loads the default one from the Resources folder which uses a fuzzy circle shaped shadow texture. You could use the included material or any custom material you wish to generate strange effects.

  1. I have a landscape that I’d like to project one of your fast shadows onto. I know that this isn’t ideal, as terrain could cut through the shadow and so on. However I’d like to know if I could somehow tweak the shadow so that a) the z buffer is somehow set to never draw under the terrain and b) the z buffer also always draws behind the player.
    Do you think this might work? I have no coding knowledge so I don’t really have much idea!

    1. Hmmm, I think this could be done with three cameras. One to render the terrain, one to render the shadow, one to render the player. The cameras could be set to render player on top of shadow on top of terrain. This would have some nasty side effects though. The player and shadow could never go behind a hill. Also you may need to add a line of code to the shadow script to put the shadow on its own layer to do this.

      If you are using a terrain then you must be developing for non-mobile platforms. If you only need one shadow I would recommend the blob shadow projector approach. I would recommend fast shadows if you had hundreds of objects with shadows moving on your terrain.

      1. Hi, I ended up buying your plugin yesterday to test out as it was only $20. It actually works surprisingly well. My terrain has everything from flat areas to pronounced spikes/jagged areas and your shadow works 99% of the time, I pretty much don’t ever notice any problems from the viewpoint of the player.

        The blob shadow projector is the entire reason I sought this out, as it doubles my terrain (actually a planet) polygons every frame. Yours doesn’t!

        I originally tried casting shadows from the actual light positions (a sun) and this caused too many noticeable problems as the shadow stretched across my undulating terrain. I wonder whether you could detect when its stretching out/reaching that limit, and fade it out as it does? Or have an angle that you can set where it starts fading? Anyway just a thought!

        Email me if you want and I’ll try and get you a copy or some footage.

        Thanks very much, great plugin!

        1. Thanks for the feedback. I could see how low angle shadows would be a problem on undulating terrain. An angle limit is a good suggestion. I will try it out and perhaps add it to the next version.

  2. Hi there,
    thanks for Fast Shadows, its great so far. We are making a car race and the only problem I have is that when the car is in a 45° angle I get two shadows. One on the terrain and one in a 90° angle. Also when the car goes head over heals the shadow flashes in the air, instead on the terrain. Any idea what this can be?
    We use light source. If you email me I can send you a screenshot.
    Thanks

  3. The problem of the shadow flashing up in the air is almost certainly a layer mask issue. If the layer mask is not set correctly then the racast often hits the shadowcasting object itself. The other two shadow problem may be a layer mask issue as well.

    Try turning on gizmos. you should be able to see the fustrum of the shadow that may help diagnose what is going on.

    Also fast shadows likes to be oriented with z forward, y up, x right, although I suspect this is not the problem.

    Let me know if these suggestions help. If not send me the screenshot and I will investigate further.

  4. Is there a way to set shadows to static at runtime? My needs for fast shadow require an object to move into place and then be there indefinitely. It would be a big boost to our performance if I could set the shadow to static after it has finished its introductory animation (zoom into scene).

    Thanks

  5. Hello Great product, I just bought this the other day and love the perf.

    For parallel “sun” light I am just typing in the vector instead of binding to the sun light object. Would be a cool small feature if the script could look at the light source and if it was directional use parallel projections. (no big deal though since the work around is trivial 🙂 ).

    The tricky thing I could use a pointer with is where I am getting a delay in the shadow aligning to my objects when they rotate. example steps: add a cube to the world with your fast shadow script and have it float above the terrain with a shadow hitting it at an angle (and bind a rectangular shadow as the texture). When you rotate the cube on its Y(or whatever the world up is) axis it takes a second or two for the shadow frustum to resolve and find the perfect angle. (the gizmos are really helpful in illustrating this). this can cause the shadow to feel a bit laggy when attached to a vehicle that is steering left and right. In my case I wouldn’t mind just calling the right code a few times in a loop to just speed up the rate at which things resolve (which might be a quick and dirty hack without needing to redo any maths.) Let me know if you have any thoughts on where I should change things for my use.
    Thanks!

  6. I tried to use fast shadows to create mobile shadows for a car in my project but they only work when the car is static, I created a simple animation sequence with the car in unity and the shadows do not work when the car is moving

    I created two empty GameObjects that cast the car shadows and made them a child of my car model so they move together
    whenever the animation plays I see the projection volumes of the shadows distort and disappear

    any fixes for this?if you need more details please let me know
    thanks

    1. Hi Pablo,

      Sorry for the very late reply to this. My notifications do not seem to be working.

      The shadows should definately work. Is “static” checked for the shadows?

Leave a Reply

Indie games