Example #1
0
        public virtual bool Hit(Ray ray, float min_distance, float max_distance, ref HitData hit_data)
        {
            Vector3 v = ray.Origin - Translation;
            float   a = Vector3.Dot(ray.Direction, ray.Direction);
            float   b = Vector3.Dot(v, ray.Direction);
            float   c = Vector3.Dot(v, v) - Radius * Radius;

            if (b * b - a * c > 0)
            {
                if (FillHitData((-b - (float)Math.Sqrt(b * b - a * c)) / a, ray, min_distance, max_distance, ref hit_data))
                {
                    return(true);
                }

                if (FillHitData((-b + (float)Math.Sqrt(b * b - a * c)) / a, ray, min_distance, max_distance, ref hit_data))
                {
                    return(true);
                }
            }

            return(false);
        }
Example #2
0
 public Vector3 Emit(IMaterial material, Ray ray, HitData hit_data)
 {
     return(Vector3.Zero);
 }
Example #3
0
        public Vector3 Emit(IMaterial material, Ray ray, HitData hit_data)
        {
            DiffuseLightMaterial diffuse_light_material = material as DiffuseLightMaterial;

            return(diffuse_light_material.Emit.Value(hit_data.UV.X, hit_data.UV.Y, hit_data.Point));
        }
Example #4
0
 public bool Scatter(IMaterial material, Ray ray, HitData hit_data, ref Vector3 attenuation, ref Ray scattered)
 {
     return(false);
 }
Example #5
0
        protected bool FillHitData(float root, Ray ray, float min_distance, float max_distance, ref HitData hit_data)
        {
            if (root < min_distance || root > max_distance)
            {
                return(false);
            }

            hit_data.Distance = root;
            hit_data.Point    = ray.PointAt(root);
            hit_data.Normal   = (hit_data.Point - Translation) / Radius;
            hit_data.Material = Material;

            float phi   = (float)Math.Atan2(hit_data.Point.Z, hit_data.Point.X);
            float theta = (float)Math.Asin(hit_data.Point.Y);

            hit_data.UV.X = 1 - (phi + (float)Math.PI) / (float)(2.0f * Math.PI);
            hit_data.UV.Y = (theta + (float)Math.PI / 2.0f) / (float)Math.PI;

            return(true);
        }