public Vec3 GetColor(ShadeRec sr)
        {
            ShadeRec localSr = sr.Clone();

            localSr.LocalHitPoint = MathUtils.TransformPoint(invMatrix, sr.LocalHitPoint);
            return(texture.GetColor(localSr));
        }
Example #2
0
        public bool Scatter(Ray ray, HitRecord record, ref Vector attenuation, ref Ray scattered)
        {
            var reflected = Reflect(ray.Direction.Normalize(), record.Normal);

            scattered   = new Ray(record.P, reflected + fuzz * MathHelper.RandUnitVector(record.Normal));
            attenuation = albedo.GetColor(record.U, record.V, record.P);
            return(scattered.Direction.Dot(record.Normal) > 0);
        }
Example #3
0
        public bool Scatter(Ray ray, HitRecord record, ref Vector attenuation, ref Ray scattered)
        {
            var reflected = record.Normal + record.P + MathHelper.RandUnitVector(record.Normal);

            attenuation = albedo.GetColor(record.U, record.V, record.P);
            scattered   = new Ray(record.P, reflected - record.P);
            return(true);
        }
        public Vector GetColor(float u, float v, Vector p)
        {
            var sin = Math.Sin(10 * p.X) * Math.Sin(10 * p.Y) * Math.Sin(10 * p.Z);

            return(sin < 0
                ? odd.GetColor(u, v, p)
                : even.GetColor(u, v, p));
        }
Example #5
0
        public bool Scatter(Ray ray, HitRecord record, ref Vector attenuation, ref Ray scattered)
        {
            attenuation = albedo.GetColor(record.U, record.V, record.P);
            var    refracted = Vector.Zero;
            Vector outwardNormal;
            float  newRefractivity;
            float  cosin;
            float  possible;
            var    reflected = Reflect(ray.Direction, record.Normal);

            if (ray.Direction.Dot(record.Normal) > 0f)
            {
                outwardNormal   = record.Normal.Negative();
                newRefractivity = refractivity;
                cosin           = ray.Direction.Normalize().Dot(record.Normal);
            }
            else
            {
                outwardNormal   = record.Normal;
                newRefractivity = 1f / refractivity;
                cosin           = -ray.Direction.Normalize().Dot(record.Normal);
            }

            if (Refract(ray.Direction, outwardNormal, newRefractivity, ref refracted))
            {
                possible = SchlickEquation(cosin, newRefractivity);
            }
            else
            {
                scattered = new Ray(record.P, reflected);
                possible  = 1f;
            }

            // reflection or refraction
            if (MathHelper.Randf() < possible)
            {
                scattered = new Ray(record.P, reflected);
            }
            else
            {
                scattered = new Ray(record.P, refracted);
            }
            return(true);
        }
 public override Vec3 F(ShadeRec sr, Vec3 wi, Vec3 wo)
 {
     return(kd * cd.GetColor(sr) * MathUtils.InvPI);
 }
Example #7
0
 public FloatColor GetColor(Vector2 uv) => Texture.GetColor(uv, Scale, Offset);