[RELEASED] Fast Shadows

Version 1.2 now available in the asset store! Fast Shadows is faster than ever!

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!

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?

Links

Easy To Use
Add the FS_ShadowSimple script to your object and a shadow will appear when you press play. No scripting!

Limitations
These shadows are designed to be fast, not 100% accurate. 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 or over corners.
  • 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.

Live Demo
Try the live demo.

Videos
How To Use It:

Fast Shadows On Uneven Terrain:

Screenshots

Update Fast Shadows 1.1 Released

This update includes:
Smoother shadow rotations
Better documentation
All fields can be modified dynamically
Code cleanup
Fixed a problem with one of the sample scenes

For Unity ā€œFreeā€?

Yes, it was developed using the free version of Unity3d. definitely works.

I see that it goes to the angle of the ā€˜wall’ or ā€˜ground’. But what if half the shadow is on the floor and the other on the wall? Will the shadow project onto the 2 angles correctly?

The shadow will not distribute across two objects correctly. It will appear on one surface, then jump to the other. Even so, the illusion can still be quite convincing. Check out the web demo as an example. The shadows work best if your game has a large reasonably smooth floor.

is it a good idea to cast rays for shadows? i already own ramp brush

(bookmarked)

Purchased and loving it…

When using a light source + perspective i achieve great results (almost PRO looking), there are places, when going around the track where the blob orientation suddenly switches direction… but its not a big deal.

Great asset, exactly what Unity indie needs!!
@everyone: Just buy it!!

Thank you!

Question, how is this different from Projector Shadow (Blob Shadow)?
What does it bring to the table that’s not offered in Projector Shadow (besides single draw call optimization)?

Here is my understanding of how the blob shadow projector works:

Unity first renders all objects in the scene. Unity then determines which objects are in the frustrum of the blob shadow projector. Unity re-renders these objects with a transparent blob shadow shader and overlays this on top of the other render.

Advantages:

  • Shadows conform well to geometry.

Disadvantages:

  • Lots of extra draw calls, 100 shadows on a terrain means the terrain mesh is sent to the graphics card 100 times!
  • shadows project through walls and onto backsides of objects,
  • performance sucks on mobile (one shadow will noticeably slow the framerate, several will kill it).

Blob shadow projector is best choice for non-mobile platforms and when only a few shadows will be needed (not good for armies), or when shadow need to conform well to geometry.

Here is how fast shadows works:

A raycast is done to determine where a shadow should appear. Quad meshes are generated for each shadow and combined into a single draw call.
Advantages:

  • Speed (mobile can support a dozen or so moving shadows and hundreds of static shadows. non-mobile can support thousands, try that with a blob shadow projector),
  • shadows don’t project through objects.

Disadvantages:

  • Shadows don’t conform to geometry perfectly,
  • they can extend beyond edges of an object and as they pass from object to object they only render on one object at a time.

Fast shadows is a good choice for smooth walls and floors, and where mobile devices and large numbers of shadows are needed. It works reasonably well on terrains provided the shadows are not much larger than the triangles making up the terrain mesh (view you terrain in wireframe to see).

Yes, consider 1000 objects with shadows on a terrain.

Using the blob shadow projector the terrain mesh will be sent to the graphics card 1001 times! This will be very slow even on a PC with a good graphics card.

With Fast Shadows, there will be 1000 raycasts and a bit of math with each shadow to calculate the mesh. Then one call to draw them. If the shadows are static then there is raycast and math only happen once. This is MUCH faster!

Could you please show me how your Fast Shadows will look like when cast (projected) onto non flat surfaces - such as terrains?

I will whip an example up tonight and post it tomorrow.

The shadow jumping may be due to the rotations in the model. Fast Shadows wants the model to have Y=up, Z=forward, X=right. When I import models from blender they have rotations which confuses Fast Shadows. This can be fixed by using a hierarchy like:

  • GameObject (Attach FS_SimpleShadow here and your character controller should move this. default rotation should be 0,0,0)

  • Model Game Object

I like to see it on a terrain too. If you can raycast, get the surface normal and rotate the shadow, then it could be good replacement for blob

Here is a video of Fast Shadows on a terrain. It works quite well when character is approximately the same size as the triangles in the terrain mesh. For very large game objects such as huge hovering space ships it does not work very well.

https://www.youtube.com/watch?v=8npF5zCepm0

can u post demo for terrain. Also, is this limited to 1 type of rendering or can it have mutiple different materials to use as the shadow. I’m thinking of replacing the projector for those projector fx on the ground.

Here is a downloadable platform demo of Fast Shadows on terrain:

Each shadow has a material field in the inspector. The material you assign to the shadow can be any material. You are not limited to the default material provided with Fast Shadows.

Excellent! Just what I needed. Will definitely pick this up.

Cheers!

I found a problem. When an object is on top of another, the shadow is projected on the object. It should have a layer filter so it can cast on terrain only.