I am creating a game for android mobile platform so I want to save on performance where ever I can.
So which one should I use? The default shadows we get in unity or the on with using the projector?
I am creating a game for android mobile platform so I want to save on performance where ever I can.
So which one should I use? The default shadows we get in unity or the on with using the projector?
blob as far as i know is much simpler for the system to run so i would go with them if you can.
Alright, thanks, I’ll go with blob.
Don’t use projectors.
How else can I get blob shadows?
If you have a complex ground surface and only need a small number of objects to cast a real time shadow (like only one!) then projector based blob shadows are a decent choice. It also depends highly on the geometry you’re projecting onto.
Projectors work by re-rendering every mesh within its frustum with the projector’s shader. If your scene is one big mesh, this is really bad as you’ll be nearly doubling the poly count of the scene with just one projector. If your scene is multiple small meshes than this can also be bad as it means a lot of extra draw calls. If your scene is made up of meshes a bit bugger than the size of the shadow and relatively low poly, this can be okay, but is still significantly increases the fillrate of your scene as anything the projector is touching is still rendering twice.
Unity’s default shadows use shadow maps. These work by rendering the objects that cast shadows into a second texture and then reading that texture in the shader. This is both faster and slower than projectors due to the number of additional draw calls this can create if you have a lot of shadow casting meshes. It can also significantly increases the complexity of your shaders making everything in the scene render slower as all light receiving objects will be reading from that additional shadow map texture regardless of if the shadow is casting on it or not.
Ultimately both are both good and bad options for mobile, depending on your needs.
The best solution from a performance perspective (ignoring not having shadows) is non-projector based blob shadows. I’ve gone this route for every mobile project I’ve worked on. With some tricks you can even get shadows that are more convincing than projector based or shadow map based shadows.
The short version is you place a quad mesh on the ground with a dark, blurry circle on it below your character and you’re done.
If you’ve got a complex ground plane you may need to do one or more raycasts against the ground to determine the height and slope. I’ve also written or worked with versions of this that scale the shadow blob mesh when near an edge, or generate a mesh in real time that clips at the edge. You can get additional mileage by rotating / scaling / fading the blob based on the height and angle of the object, as well as placing more than one blob per character. For Cosmic Chef I use one blob shadow attached to the character’s pelvis, and one for each foot.
Older 3D Zelda games does an additional trick where the shadow blobs on feet stretch out away from the direction of the strongest light in the scene.
Look closely at that video of Zelda and you’ll notice Link’s shadow is on top of his feet, almost at his ankles!
I
I added a quad and created a new material with mobile> particles> multiply and selected the black fading circle image (in defaults), assgined the quad the material and made it a child of my car (the gameobject is a simple car).
Is it what you wanted me to do? It’s much better tho, thanks.
Yep, that’s about right. If you want to be a little fancier with car shadows you can use a dark rectangle shape that’s not completely black and add dark spots where the tires hit the ground. This is how shadows have been done for cars in games for literally decades. I like taking the car mesh into my modelling program and render out the ambient occlusion for it on a plane, then use that for the blob shadow.
Here’s another example. Gran Turismo 3: A-Spec for the PS2. Easily one of the best looking games of that generation.
It’s using two blob shadows. One directly under the car, and one using a special mesh that fakes the shadow you might get from a shadow map. If you notice around 2:20 in that video the long shadow actually cuts into the grass on the left!
One of the other old ways of doing shadows was to render the mesh a second time, but with the vertices stretched out depending on their height from the ground, then flattened. GT3’s shadows appear to be something similar, but probably using a simplified mesh that fades out with vertex alpha. Cheap & good looking!
That’s a great idea, thanks!
How does the mesh bends when it’s in grass (grass side being a little elevated)?
It doesn’t. It just clips right through it. The only reason it doesn’t happen sooner is because that shadow isn’t on the ground but rather floating a few centimeters up off of it. That way it can handle a ground plane that isn’t perfectly flat.
Thanks for the help!
@bgolus Could you please elaborate on how you would generate the mesh to prevent the shadow blob from hanging over the edge of a terrain? All I can think of is just raycasting below to the terrain collider, and then changing vertices to fit within the collider’s boundaries. But this would require the collider shape to be close to perfect with the visual appearance of the terrain, and would only work with box-shaped colliders.
This is exactly the case I used this with. It was a side scrolling platforming game with all platforms conforming to roughly a box. Rayman Run games are great examples of really nice implementations of this, using two blobs that either clip on connected hard corner transitions, or fade in & out on hard edges.
For more complex 3d setups you can trace and project against the collision mesh, the trick is to realize most people won’t notice that it doesn’t match perfectly.
Really interesting point about fading out on hard edges. I just watched a video of Rayman Run in slow-mo and I can see what you are talking about. Thanks!