public void CalculatePhongLight(Vect4 light, Vect4 view, float ka, float kd, float ks, float h) { //Check if face is visible if (mr.enabled == true) { float Ia = ka * 1; float Id = kd * normal.DotProduct(normal, light); //calculate Reflection vector //dot product of Light * normal float dp = light.DotProduct(normal, light) * 2; Vect4 R = new Vect4(normal.x * dp, normal.y * dp, normal.z * dp); R = R.Substraction(light); R.Normalize(); float Is = ks * Mathf.Pow(R.DotProduct(R, view), h); float I = Ia + Id + Is; mr.material.SetColor("_Color", IndexedFace.Instance.materialColor * I); } }
public void CalculateNormal(Vect4 p1, Vect4 p2, Vect4 p3) { normal = p1.CrossProduct(p2.Substraction(p1), p3.Substraction(p1)); normal = normal.Normalize(); }