Gamasutra: The Art & Business of Making Gamesspacer
Implementing Fake Shadows in Unity for Mobiles
Printer-Friendly VersionPrinter-Friendly Version
View All     RSS
April 20, 2014
arrowPress Releases
April 20, 2014
PR Newswire
View All





If you enjoy reading this site, you might also want to check out these UBM TechWeb sites:


 
Implementing Fake Shadows in Unity for Mobiles
by Vijay Kartick Prem Kumar on 12/08/13 01:40:00 am

The following blog post, unless otherwise noted, was written by a member of Gamasutra’s community.
The thoughts and opinions expressed are those of the writer and not Gamasutra or its parent company.

 

Shadows are most important for any 3D game. Without shadows the scene looks unrealistic and not so 3D.. The following is my experiences in trying to implement a light weight shadow in unity and this article is in beginner level only.

unnamed

This is the screenshot of my mobile game "Thumbi"  . The Blue and Red Cubes needed shadow to give a good 3d effect.

First I used the builtin hard and soft shadows.  The total number of verts rendered without shadows was around 70,but the number of verts rendered with shadows was in thousands . This is a very simple casual game for mobile and rendering such a heavy shadow is unnecessary. Besides if i made the Floor Quad unlit/Transparent the shadows wont be drawn on it . This is as per design of unity3D. Hence came my next experiment projectors.

Second  Projectors are available in Standard assets of unity. It is not available in  standard assets for mobiles which should have made me think why? Many forums said projectors are cheaper than actual shadows but they are not at all cheap for mobile games. The number of verts when i used projectors was in hundreds and i got around only 15 fps for such a low poly game. For some reason projectors wont draw on transparent textures in unity. Playing this fast paced game at 15 FPS spoiled the gameplay. Hence i needed something else.

Third  Using a simple Black&White Texture with  of 16x16 like the below one

circle_gradient

Just use a quad with Multiply shader from mobile particles. Offset the quad opposite to direction of light to imitate a shadow and shift it below your object. The quad is made a child of the cube and moved along  with the cube. Ok now we got a shadow with only 2 draw calls and few verts. This approach is useful only for flat surface and when the object is at same height from floor and direction of light is fixed.

For a more better shadow you can use Raycast in downward axis to check the distance to the ground and translate the shadow quad downward accordingly. For most mobile games only one light should be used in a scene for good performance. Hence you can find the direction between Cube and Light and move the shadow quad behind the cube in the opposite direction. Eg.,

Vector3  dir= DistanceFactor* (CubeTransform.position- LightTransform.position).normalized;

dir+=CubeTransform.position;

shadowquad.position= new vector3(dir.x,groundDistance,dir.z);

This code will make the shadow opposite to light direction, and fix it and a distance from cube determined by DistanceFactor. Use any texture you like with similar gradient.This shadow will look awkward on inclined floors.

Now you got a good looking Fake shadow for your mobile game. Do play my game "Thumbi". It's FREE.


Related Jobs

Penny Publications, LLC
Penny Publications, LLC — Norwalk, Connecticut, United States
[04.18.14]

Game Designer
Hasbro
Hasbro — Pawtucket, Rhode Island, United States
[04.18.14]

Sr. Designer/Producer, Integrated Play
Nexon America, Inc.
Nexon America, Inc. — El Segundo , California, United States
[04.17.14]

Web Designer - Temporary - 3 month
Darkside Game Studios
Darkside Game Studios — Sunrise, Florida, United States
[04.17.14]

Mid-Senior Graphics Programmer






Comments


Muhammad Helmy
profile image
you courage me to show off my way to do it when I use Unity for mobile :)


none
 
Comment: