Exemple #1
0
        public override bool DistanceToRay(Ray ray, HitResult result)
        {
            var pos = Transform.Translation;

            float a = VMath.Dot(ray.vec, pos - ray.pos);
            float e = (pos - ray.pos).LengthSquare();

            float f = Range * Range - e + a * a;

            if (f < 0)
            {
                return(false);
            }

            float distance = a - (float)Math.Sqrt(f);

            if (result.distance > distance && distance > 0.05)
            {
                result.normal   = VMath.Normalize((ray.pos + ray.vec * distance) - pos);
                result.material = Material;
                result.distance = distance;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #2
0
        public virtual void Scatter(Ray ray, Vector3 normal, Vector2 uv, Vector3 pos, out Vector3 vec, out Vector3 albedo)
        {
            float dot = VMath.Dot(normal, ray.vec);

            albedo = Albedo.GetColor(uv) * Math.Abs(dot);

            vec = CreateReflectedVector(ray, normal, pos);
        }
Exemple #3
0
 public float[] Forward(float[] input)
 {
     System.Array.Copy(input, this.input, inputNum);
     for (int i = 0; i < neuronNum; i++)
     {
         active[i] = VMath.Tanh(VMath.Dot(weights[i].w, input) + bias[i]);
     }
     return(active);
 }
Exemple #4
0
        public float CalculateTimeToIntersectWithRay(Ray ray)
        {
            float dot = VMath.Dot(Normal, ray.vec);

            if (Math.Abs(dot) <= 1E-6)
            {
                return(1E+6F);
            }

            return(VMath.Dot(Normal, Pos - ray.pos) / dot);
        }
Exemple #5
0
        protected Vector3 CreateReflectedVector(Ray ray, Vector3 normal, Vector3 pos)
        {
            if (Rand.NextDouble() < Roughness)
            {
                var vec = new Vector3((float)Rand.NextDouble() * 0.5F - 0.25F, 3, (float)Rand.NextDouble() * 0.5F - 0.25F) - pos;
                if (VMath.Dot(vec, normal) > 0)
                {
                    return(VMath.Normalize(vec));
                }
            }

            return(Vector3.Interpolate(Reflect(ray.vec, normal), RandomCosineDirection() * Matrix3.LookAt(normal, RandomCosineDirection()), Roughness));
        }
Exemple #6
0
        public bool IsIntersectWithRay(Ray ray)
        {
            var   target = Pos - ray.pos;
            float time   = VMath.Dot(VMath.Normalize(ray.vec), target);

            if (time <= 0)
            {
                return(false);
            }

            float distance = target.LengthSquare() - time * time;

            return(distance <= Range * Range);
        }
Exemple #7
0
        public bool IsIntersectWithRay(Ray ray)
        {
            var cross1 = VMath.Cross(Pos2 - Pos1, ray.pos - Pos1);
            var dot1   = VMath.Dot(cross1, ray.vec);

            var cross2 = VMath.Cross(Pos3 - Pos2, ray.pos - Pos2);
            var dot2   = VMath.Dot(cross2, ray.vec);

            if (dot1 > 0 ^ dot2 > 0)
            {
                return(false);
            }

            var cross3 = VMath.Cross(Pos1 - Pos3, ray.pos - Pos3);
            var dot3   = VMath.Dot(cross3, ray.vec);

            return(!(dot2 > 0 ^ dot3 > 0));
        }
Exemple #8
0
        public float CalculateTimeToIntersectWithRay(Ray ray)
        {
            float a0 = ray.vec.LengthSquare();
            float a1 = VMath.Dot(ray.vec, Pos - ray.pos);
            float a2 = (Pos - ray.pos).LengthSquare() - Range * Range;

            float d = a1 * a1 - a0 * a2;

            if (d < 0)
            {
                return(1E+6F);
            }

            float d2 = (float)Math.Sqrt(d);

            if (-a1 - d2 >= 0)
            {
                return(-(a1 + d2) / (2 * a0));
            }
            else
            {
                return(-(a1 - d2) / (2 * a0));
            }
        }
Exemple #9
0
 public Vector3 Reflect(Vector3 vec, Vector3 nornal)
 {
     return(VMath.Normalize(vec - 2 * VMath.Dot(vec, nornal) * nornal));
 }
Exemple #10
0
 public Vector3 GetColor(Ray ray)
 {
     return(VMath.Dot(Pos, ray.vec) > 0.995 ? Color : new Vector3(1, 1, 1) * 0.1F);
 }
Exemple #11
0
 public bool IsIntersectWithRay(Ray ray)
 {
     return(Math.Abs(VMath.Dot(Normal, ray.vec)) > 1E-6);
 }