Unity Tutorial Introduction to Lighting and Rendering
PerVertexLighting vs PerPixelLighting
Types of light Sources in Unity
FIGURE 2.4: Types of lightsources, as seen in the Unity 5.6.1 Engine (Image from https://www.researchgate.net/publication/350578263_Real-Time_Global_Illumination_Using_OpenGL_And_Voxel_Cone_Tracing/figures)
Shaders in Unity
Blinn–Phong reflection model
(Image fromhttps://en.wikipedia.org/wiki/Blinn%E2%80%93Phong_reflection_model)
Phong reflection model
Ambient/Diffuse/Specular (Image from https://en.wikipedia.org/wiki/Phong_reflection_model)
lecture13
lecture13
lecture12
lecture12
Unity Quaternion.LookRotation
public static Quaternion LookRotation(Vector3 forward, [DefaultValue(“Vector3.up”)] Vector3 upwards)
{
return Quaternion.INTERNAL_CALL_LookRotation(ref forward, ref upwards);
}
[ExcludeFromDocs]
public static Quaternion LookRotation(Vector3 forward)
{
Vector3 up = Vector3.up;
return Quaternion.INTERNAL_CALL_LookRotation(ref forward, ref up);
}
// from http://answers.unity3d.com/questions/467614/what-is-the-source-code-of-quaternionlookrotation.html
private static Quaternion INTERNAL_CALL_LookRotation(ref Vector3 forward, ref Vector3 up)
{
forward = Vector3.Normalize(forward);
Vector3 right = Vector3.Normalize(Vector3.Cross(up, forward));
up = Vector3.Cross(forward, right);
var m00 = right.x;
var m01 = right.y;
var m02 = right.z;
var m10 = up.x;
var m11 = up.y;
var m12 = up.z;
var m20 = forward.x;
var m21 = forward.y;
var m22 = forward.z;
float num8 = (m00 + m11) + m22;
var quaternion = new Quaternion();
if (num8 > 0f)
{
var num = (float)Math.Sqrt(num8 + 1f);
quaternion.w = num * 0.5f;
num = 0.5f / num;
quaternion.x = (m12 – m21) * num;
quaternion.y = (m20 – m02) * num;
quaternion.z = (m01 – m10) * num;
return quaternion;
}
if ((m00 >= m11) && (m00 >= m22))
{
var num7 = (float)Math.Sqrt(((1f + m00) – m11) – m22);
var num4 = 0.5f / num7;
quaternion.x = 0.5f * num7;
quaternion.y = (m01 + m10) * num4;
quaternion.z = (m02 + m20) * num4;
quaternion.w = (m12 – m21) * num4;
return quaternion;
}
if (m11 > m22)
{
var num6 = (float)Math.Sqrt(((1f + m11) – m00) – m22);
var num3 = 0.5f / num6;
quaternion.x = (m10 + m01) * num3;
quaternion.y = 0.5f * num6;
quaternion.z = (m21 + m12) * num3;
quaternion.w = (m20 – m02) * num3;
return quaternion;
}
var num5 = (float)Math.Sqrt(((1f + m22) – m00) – m11);
var num2 = 0.5f / num5;
quaternion.x = (m20 + m02) * num2;
quaternion.y = (m21 + m12) * num2;
quaternion.z = 0.5f * num5;
quaternion.w = (m01 – m10) * num2;
return quaternion;
}