How to set light source in sheet engine

Oct 16, 2013 at 4:54 AM
I want to adjust light source but i don't know how to calculate its parameters?
Oct 16, 2013 at 7:04 AM
Edited Oct 16, 2013 at 7:08 AM
There are 3 vectors you will have to update:
The above three should define a coordinate-system and should be perpendicular to each other. Let's begin with the first, simply define the direction of the light source with a vector:
sheetengine.shadows.lightSource = { x: 1, y: -1, z: -1 };
The next one is easy, too, just try to look for a vector that is perpendicular to this. You will have to solve the equation x0x + y0y + z0z = 0 (so take the scalar product of your two vectors, it should be equal to 0).
So let's start with x = 1 (it's just a random number to start off with), then we get 11 + -1y + -1
z = 0. We can still chose anything for y, let this be 2: 11 + -12 + -1*z = 0. Now we can solve this for z which gives us: 1-2-z=0 -> z = -1. So our second vector can be:
sheetengine.shadows.lightSourcep1 = { x: 1, y: 2, z: -1 };
From here the third vector is quite easy. Simply take the vector product of the previous two and that will give you the third one. Vector product is z = x1y2-x2y1, y = - x1z2+x2z1, x = y1z2-y2z1, so it is { x: 3, y: 0, z: 3 };
sheetengine.shadows.lightSourcep2 = { x: 3, y: 0, z: 3 };
And that's it. On a side note: if you just want to play around the lights, temporarily you can do it by adjusting the sheetengine.shadows.lightSource solely, and not care about the other two. For most of the time you will see the effect of your changes. The other two (the whole coordinate system) is required for shadow casting ordering to work perfectly, so play around with the lightsource vector, and if you like the angle you have chosen you can define the other two vectors and that will make sure that lights and shadows will work fine even with the craziest sheet infrastructures.

For an example of this download the examples from the downloads page and check out "Adjusting the light source". Also read the corresponding documentation here: