Jan
20
2013

Fake Circular Shadow Casters

fake_circular_shadow_casters_unity3D

More fake shadow tests.. (currently works from one direction only)

Info:
– Lets say all of your shadow casting objects are spheres/circular, then we could calculate what area is not visible based on the distance & angle from the player to spheres (or so I hoped, but couldnt find any method of calculating it..so now this is using precalculated values which were recorded by hand, 1 by 1.. : )
– Precalculated SinCos lookup tables and distance tables..
– GL quads for drawing the shadow area
– Demo 1.0 uses only 360 precalculated values..thats why its bit jumpy.
– No rays/raycasting used, currently main function only does: 1 Mathf.RoundToInt, 1 multiplication, 2 vector3 multiplications, getting values from 2 precalculated arrays, 3 vector additions…

Progress:
– Yay! got some help from friends and now can calculate the point/tangent on a circle from another point:

s = transform.position; // player
t = target.transform.position; // sphere
distance = Vector3.Distance(s,t);
var r:float = 0.5; // sphere radius
var f:float =  Mathf.Sqrt((distance*distance)-(r*r));
var alpha:float = Mathf.Asin(r/distance);
var yy:float = Mathf.Sin(alpha)*f;
var xx:float = Mathf.Cos(alpha)*f;
Debug.DrawRay (transform.position, Vector3(xx*1,0,yy*1), Color.red);
Debug.DrawRay (transform.position, Vector3(xx*1,0,-yy*1), Color.green);

Webplayer:
http://unitycoder.com/upload/demos/FakeCircularShadowCasters/ (v1.0 *Note: using only array of 360 pre-calculated values, thats why its bit jumpy..)

Download source:
coming later..


Related Posts

About the Author:

.fi

2 Comments + Add Comment

Leave a comment

Connect

Twitter View LinkedIn profile Youtube Github Join Discord Twitch Instagram BlueSky

UnityLauncherPro

Get UnityLauncherPRO and work faster with Unity Projects!
*free unity hub alternative

@unitycoder_com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.