Пример #1
0
        //Setters for lambertian paramaters
        /*
        public void setKa(float ka) { ambientBRDF.DiffuseReflectionCoefficient = ka; }
        public void setKd(float kd) { diffuseBRDF.DiffuseReflectionCoefficient = kd; }
        public void setCd(RGBColor c) { ambientBRDF.ColorDiffuse = c; diffuseBRDF.ColorDiffuse = c; }
        public void setCd(Texture tex) { ambientBRDF.Texture = tex; diffuseBRDF.Texture = tex; }
        */
        public override RGBColor Shade(ShadeRec sr)
        {
            Vect3D reflectedDirection = -sr.Ray.Direction;
            RGBColor L = ambientBRDF.Rho(sr, reflectedDirection) * sr.WorldPointer.AmbientLight.GetLighting(sr);
            int numLights = sr.WorldPointer.LightList.Count;
            Vect3D incomingDirection;
            float nDotWi;
            bool inShadow;
            Ray shadowRay;
            //float t = GlobalVars.kHugeValue;

            //Loop through list of lights and add radiance for each diffuse light source.
            for(int i = 0; i < numLights; i++)
            {
                incomingDirection = sr.WorldPointer.LightList[i].GetDirection(sr);
                nDotWi = sr.Normal * incomingDirection;
                //Direction must not be 0,0,0 to be a diffuse light source.
                if(nDotWi > 0.0)
                {
                    inShadow = false;
                    if(sr.WorldPointer.LightList[i].CastsShadows)
                    {
                        shadowRay = new Ray(sr.HitPoint + (GlobalVars.SHAD_K_EPSILON * incomingDirection), incomingDirection);
                        inShadow = sr.WorldPointer.LightList[i].InShadow(sr, shadowRay);
                    }
                    if(!inShadow)
                    {
                        L += diffuseBRDF.F(sr, reflectedDirection, incomingDirection) * sr.WorldPointer.LightList[i].GetLighting(sr) * nDotWi;
                    }
                }
            }

            return L;
        }
Пример #2
0
        public override Vec3 SampleF(ShadeRec sr, ref Vec3 wr, Vec3 wo)
        {
            float ndotwo = (float)sr.Normal.Dot(wo);

            wr = (wo * -1) + 2.0 * sr.Normal * ndotwo;

            return(Fresnel(sr) * ColorUtils.WHITE / Math.Abs(sr.Normal.Dot(wr)));
        }
        public override Vector3 Sample_F(ShadeRec sr, Vector3 wo, ref Vector3 wi, ref float pdf)
        {
            float ndotwo = Vector3.Dot(sr.Normal, wo);

            wi  = -wo + 2.0f * sr.Normal * ndotwo;
            pdf = Vector3.AbsDot(sr.Normal, wi);
            return(kr * cr.GetColor(sr));
        }
Пример #4
0
 public override bool Hit(Ray ray, ref float tmin, ref ShadeRec sr)
 {
     if (bbox.Hit(ray))
     {
         return(base.Hit(ray, ref tmin, ref sr));
     }
     return(false);
 }
Пример #5
0
 public override Vector3 ShadeAreaLight(ShadeRec sr)
 {
     return(m_ce * m_ls);
     //if (sr.normal.Nor().Dot(sr.ray.dir.Nor()) < 0f)
     //    return m_fcolor;
     //else
     //    return ColourF.Black;
 }
Пример #6
0
        //public void SetTopMaterial(Material material)
        //{
        //    objects[0].Material = material;
        //}

        //public void SeTopBorderMaterial(Material material)
        //{
        //    objects[1].Material = material;
        //}

        //public void SetWallMaterial(Material material)
        //{
        //    objects[1].Material = material;
        //}

        //public void SetBottomBorderMaterial(Material material)
        //{
        //    objects[2].Material = material;
        //}

        //public void SetBottomMaterial(Material material)
        //{
        //    objects[2].Material = material;
        //}

        public override bool Hit(Ray ray, ref double tmin, ShadeRec sr)
        {
            if (bbox.Hit(ray))
            {
                return(base.Hit(ray, ref tmin, sr));
            }

            return(false);
        }
        public override Vec3 SampleF(ShadeRec sr, ref Vec3 wi, Vec3 wo, ref float pdf)
        {
            float ndotwo = (float)sr.Normal.Dot(wo);
            Vec3  r      = (wo * -1) + 2.0 * sr.Normal * ndotwo;

            pdf = (float)Math.Abs(sr.Normal.Dot(wi));

            return(kr * cr);
        }
Пример #8
0
        public override Vec3 GetDirection(ShadeRec sr)
        {
            samplePoint = obj.Sample();
            normal      = obj.GetNormal(samplePoint);
            wi          = samplePoint - sr.HitPoint;
            wi.Normalize();

            return(wi);
        }
Пример #9
0
        public override Vector3 Path_Shade(ShadeRec sr)
        {
            Vector3 wo            = -sr.Ray.Direction;
            Vector3 wi            = Vector3.Zero();
            Vector3 f             = diffuse.Sample_F(sr, wo, ref wi);
            float   ndotwi        = Vector3.Dot(sr.Normal, wi);
            Ray     reflected_ray = new Ray(sr.HitPoint, wi);

            return(f * sr.World.Tracer.TraceRay(reflected_ray, sr.Depth + 1) * ndotwi);
        }
Пример #10
0
        public override Vector3 GetDirection(ShadeRec sr)
        {
            float   r            = Radius;
            Vector3 new_location = Vector3.Zero();

            new_location.X = Location.X + r * (2.0f * MathUtil.RandomFloat() - 1.0f);
            new_location.Y = Location.Y + r * (2.0f * MathUtil.RandomFloat() - 1.0f);
            new_location.Z = Location.Z + r * (2.0f * MathUtil.RandomFloat() - 1.0f);
            return(Vector3.Normalize(new_location - sr.LocalHitPoint));
        }
Пример #11
0
        public override Vector3 Path_Shade(ShadeRec sr)
        {
            Vector3 wo            = -sr.Ray.Direction;
            Vector3 wi            = Vector3.Zero();
            float   pdf           = 0;
            Vector3 fr            = reflective.Sample_F(sr, wo, ref wi, ref pdf);
            Ray     reflected_ray = new Ray(sr.HitPoint, wi);

            return(fr * sr.World.Tracer.TraceRay(reflected_ray, sr.Depth + 1) * (sr.Normal * wi) / pdf);
        }
Пример #12
0
        public override RGBColor TraceRay(Ray ray, int depth)
        {
            ShadeRec shadeRec = world.IntersectAllObjects(ray);

            if (shadeRec.HasHitObject)
            {
                return(shadeRec.Color);
            }
            return(world.BackgroundColor);
        }
        public override Vector3 GetDirection(ShadeRec sr)
        {
            Vector3 finaldir = Vector3.Zero();

            finaldir.X = Direction.X + r * (2.0f * MathUtil.RandomFloat() - 1.0f);
            finaldir.Y = Direction.Y + r * (2.0f * MathUtil.RandomFloat() - 1.0f);
            finaldir.Z = Direction.Z + r * (2.0f * MathUtil.RandomFloat() - 1.0f);
            finaldir.Normalize();
            return(finaldir);
        }
Пример #14
0
        public Vec3 PathShade(ShadeRec sr)
        {
            Vec3  wo           = sr.Ray.D * -1;
            Vec3  wi           = null;
            float pdf          = 0.0f;
            Vec3  f            = diffuse.SampleF(sr, ref wi, wo, ref pdf);
            Ray   reflectedRay = new Ray(sr.HitPoint, wi);

            return(f * sr.World.Tracer.TraceRay(reflectedRay, sr.Depth + 1)
                   * sr.Normal.Dot(wi) / pdf);
        }
Пример #15
0
 public override Vector3 Area_Light_Shade(ShadeRec sr)
 {
     if (Vector3.Dot(-sr.Normal, sr.Ray.Direction) > 0.0f)               //here may be ConcaveSphere not support
     {
         return(Radiance * Color);
     }
     else
     {
         return(Vector3.Zero);
     }
 }
        public override Vector3 GetDirection(ShadeRec sr)
        {
            w = sr.Normal;
            v = Vector3.Cross(new Vector3(0.0034f, 1, 0.0071f), w);
            v.Normalize();
            u = Vector3.Cross(v, w);
            Vector3 sp = sampler.SampleHemisphere();

            wi = sp.X * u + sp.Y * v + sp.Z * w;
            return(wi);
        }
Пример #17
0
 public override Vector3 Global_Shade(ShadeRec sr)
 {
     if (sr.Depth == 1)
     {
         return(Vector3.Zero);
     }
     else
     {
         return(ls * t.GetColor(sr));
     }
 }
Пример #18
0
 public override Vector3 Path_Shade(ShadeRec sr)
 {
     if (Vector3.Dot(-sr.Normal, sr.Ray.Direction) > 0.0f)
     {
         return(Radiance * Color);
     }
     else
     {
         return(Vector3.Zero());
     }
 }
Пример #19
0
        public override Vector3 GetDirection(ShadeRec sr)
        {
            Vector3 w = sr.normal.Nor();
            Vector3 v = w.Cross(Vector3.UpJitted).Nor(); //use Jitted Up vector avoid w parallels to vec3.up;
            Vector3 u = v.Cross(w).Nor();

            Vector3 sp  = m_sampler.SampleHemisphere();
            Vector3 dir = sp.x * u + sp.y * v + sp.z * w;

            return(dir.Nor());
        }
Пример #20
0
        private SColor NormalMap(Ray ray, HitableList hitableList)
        {
            ShadeRec record = new ShadeRec();

            if (hitableList.Hit(ray, 0.0, double.MaxValue, ref record))
            {
                return(0.5 * new SColor(record.normal.X + 1, record.normal.Y + 1, record.normal.Z + 1, 2.0));
            }
            double t = 0.5 * ray.normalDirection.Y + 1.0;

            return((1 - t) * new SColor(1, 1, 1) + t * new SColor(0.5, 0.7, 1));
        }
Пример #21
0
        public override Vector3 Area_Light_Shade(ShadeRec sr)
        {
            Vector3 L             = base.Shade(sr);
            Vector3 wo            = -sr.Ray.Direction;
            Vector3 wi            = Vector3.Zero();
            Vector3 fr            = reflective.Sample_F(sr, wo, ref wi);
            Ray     reflected_ray = new Ray(sr.HitPoint, wi);

            reflected_ray.Depth = sr.Depth + 1;
            L += fr * sr.World.Tracer.TraceRay(reflected_ray, sr.Depth + 1) * (sr.Normal * wi);
            return(L);
        }
Пример #22
0
        public override Vector3 L(ShadeRec sr)
        {
            //falloff
            float falloff = (m_pos - sr.localHitPoint).length;

            falloff = falloff > m_range ? m_range : falloff;
            falloff = falloff / m_range;

            float t = 1f - falloff * falloff;

            return(m_atten * m_color);
        }
        public override Vector3 Area_Light_Shade(ShadeRec sr)
        {
            Vector3 L             = (base.Area_Light_Shade(sr));
            Vector3 wo            = (-sr.Ray.Direction);
            Vector3 wi            = Vector3.Zero();
            float   pdf           = 0;
            Vector3 fr            = (glossy_specular.Sample_F(sr, wo, ref wi, ref pdf));
            Ray     reflected_ray = new Ray(sr.HitPoint, wi);

            L += fr * sr.World.Tracer.TraceRay(reflected_ray, sr.Depth + 1) * (Vector3.Dot(sr.Normal, wi)) / pdf;
            return(L);
        }
Пример #24
0
        public override Vector3 GetColor(ShadeRec sr)
        {
            Vector3 hit_point  = sr.LocalHitPoint;
            Vector3 offset     = noise_ptr.vector_fbm(hit_point * ring_noise_frequency);
            Vector3 ring_point = hit_point + ring_noise * offset;
            Vector3 temp_vec   = trunk_wobble * noise_ptr.vector_noise(new Vector3(0, 0, hit_point.Y * trunk_wobble_frequency));

            ring_point.X += temp_vec.X;
            ring_point.Z += temp_vec.X;
            float   r         = MathUtil.Sqrt(ring_point.X * ring_point.X + ring_point.Z * ring_point.Z) * ring_frequency;
            Vector3 temp_vec2 = Vector3.Zero();

            temp_vec2.X = angular_wobble_frequency * ring_point.X;
            temp_vec2.Y = angular_wobble_frequency * ring_point.Y * 0.1f;
            temp_vec2.Z = angular_wobble_frequency * ring_point.Z;
            float delta_r = angular_wobble * MathUtil.SmoothStep(0.0f, 5.0f, r) * noise_ptr.value_noise(temp_vec2);

            r += delta_r;
            r += ring_uneveness * noise_ptr.value_noise(new Vector3(r));
            float   temp        = r;
            float   in_ring     = MathUtil.SmoothPulseTrain(0.1f, 0.55f, 0.7f, 0.95f, 1.0f, r);
            Vector3 grain_point = Vector3.Zero();

            grain_point.X = hit_point.X * grain_frequency;
            grain_point.Y = hit_point.Y * grain_frequency * 0.05f;
            grain_point.Z = hit_point.Z * grain_frequency;
            float dpgrain   = 0.2f;
            float grain     = 0.0f;
            float amplitude = 1.0f;

            for (int i = 0; i < 2; i++)
            {
                float grain_valid = 1.0f - MathUtil.SmoothStep(0.2f, 0.6f, dpgrain);
                if (grain_valid > 0.0f)
                {
                    float g = grain_valid * noise_ptr.value_noise(grain_point);
                    g *= (0.3f + 0.7f * in_ring);
                    g  = MathUtil.Pow(MathUtil.Clamp(0.8f - g, 0.0f, 1.0f), 2.0f);
                    g  = grainy * MathUtil.SmoothStep(0.5f, 1.0f, g);
                    if (i == 0)
                    {
                        in_ring *= (1.0f - 0.4f * grain_valid);
                    }
                    grain = amplitude * MathUtil.Max(grain, g);
                }
                grain_point = 2.0f * grain_point;
                dpgrain    *= 2.0f;
                amplitude  *= 0.5f;
            }
            float final_value = MathUtil.MixFloat(in_ring * ringy, 1.0f, grain);

            return(MathUtil.MixColor(light_color, dark_color, final_value));
        }
Пример #25
0
        public bool TIR(ShadeRec sr)
        {
            Vector3 wo         = (-sr.Ray.Direction);
            float   cos_thetai = Vector3.Dot(sr.Normal, wo);
            float   eta        = eta_in / eta_out;

            if (cos_thetai < 0.0)
            {
                eta = 1.0f / eta;
            }
            return(1.0f - (1.0f - cos_thetai * cos_thetai) / (eta * eta) < 0.0f);
        }
Пример #26
0
 public override RGBColor F(ShadeRec shadeRec, Vector3d wi, Vector3d wo)
 {
     RGBColor L = new RGBColor();
     double NdotWi = Vector3d.Dot(shadeRec.Normal, wi);
     Vector3d r = (-wi + (Vector3d)shadeRec.Normal * NdotWi * 2);
     double RdotWo = Vector3d.Dot(r, wo);
     if (RdotWo > 0)
     {
         L = CS*KS*Math.Pow(RdotWo, Exp);
     }
     return L;
 }
Пример #27
0
        public override bool Hit(Ray ray, ref double tmin, ShadeRec sr)
        {
            Vec3 v0 = Mesh.Vertices[Index0];
            Vec3 v1 = Mesh.Vertices[Index1];
            Vec3 v2 = Mesh.Vertices[Index2];

            double a = v0.X - v1.X, b = v0.X - v2.X, c = ray.D.X, d = v0.X - ray.O.X;
            double e = v0.Y - v1.Y, f = v0.Y - v2.Y, g = ray.D.Y, h = v0.Y - ray.O.Y;
            double i = v0.Z - v1.Z, j = v0.Z - v2.Z, k = ray.D.Z, l = v0.Z - ray.O.Z;

            double m = f * k - g * j, n = h * k - g * l, p = f * l - h * j;
            double q = g * i - e * k, s = e * j - f * i;

            double invDenom = 1.0 / (a * m + b * q + c * s);

            double e1   = d * m - b * n - c * p;
            double beta = e1 * invDenom;

            if (beta < 0.0 || beta > 1.0)
            {
                return(false);
            }

            double r     = e * l - h * i;
            double e2    = a * n + d * q + c * r;
            double gamma = e2 * invDenom;

            if (gamma < 0.0 || gamma > 1.0)
            {
                return(false);
            }

            if (beta + gamma > 1.0)
            {
                return(false);
            }

            double e3 = a * p - b * r + d * s;
            double t  = e3 * invDenom;

            if (t < kEpsilin)
            {
                return(false);
            }

            tmin             = t;
            sr.Normal        = Normal;
            sr.LocalHitPoint = ray.HitPoint(t);
            sr.U             = InterpolateU(beta, gamma);
            sr.V             = InterpolateV(beta, gamma);

            return(true);
        }
Пример #28
0
 public override Vector3 L(ShadeRec sr)
 {
     if (!DistanceAttenuation)
     {
         return(Radiance * Color);
     }
     else
     {
         float d = Vector3.Distance(sr.HitPoint, (Location));
         return(Radiance * Color / (d * d));
     }
 }
Пример #29
0
        public override bool Hit(Ray r, ref float tmin, ref ShadeRec sr)
        {
            Point3D p0 = parent.vertices[index0];
            Point3D p1 = parent.vertices[index1];
            Point3D p2 = parent.vertices[index2];

            //solve with cramer's rule

            float a = p0.X - p1.X;
            float b = p0.X - p2.X;
            float c = r.Direction.X;
            float d = p0.X - r.Origin.X;

            float e = p0.Y - p1.Y;
            float f = p0.Y - p2.Y;
            float g = r.Direction.Y;
            float h = p0.Y - r.Origin.Y;

            float i = p0.Z - p1.Z;
            float j = p0.Z - p2.Z;
            float k = r.Direction.Z;
            float l = p0.Z - r.Origin.Z;

            float m = f * k - g * j;
            float n = h * k - g * l;
            float p = f * l - h * j;
            float q = g * i - e * k;
            float s = e * j - f * i;

            float inverseDenominator = 1.0f / (a * m + b * q + c * s);

            float beta = inverseDenominator * (d * m - b * n - c * p);
            if (beta < 0.0)
                return false;

            float rd = e * l - h * i;
            float gamma = inverseDenominator * (a * n + d * q + c * rd);
            if (gamma < 0.0)
                return false;
            if (beta + gamma > 1.0)
                return false;

            //Hit!
            float t = inverseDenominator * (a * p - b * rd + d * s);
            if (t < GlobalVars.K_EPSILON)
                return false;

            tmin = t;
            sr.Normal = InterpolateNormal(beta, gamma);
            sr.HitPointLocal = r.Origin + t * r.Direction;
            return true;
        }
Пример #30
0
        public override bool Hit(Ray ray, ref float tmin, ref ShadeRec sr)
        {
            float t = Vector3.Dot((Center - ray.Position), Normal) / Vector3.Dot(ray.Direction, Normal);

            if (t > MathUtil.Epsilon)
            {
                tmin             = t;
                sr.Normal        = Normal;
                sr.LocalHitPoint = ray.Position + t * ray.Direction;
                return(true);
            }
            return(false);
        }
Пример #31
0
        public override Vector3 L(ShadeRec sr)
        {
            float ndotd = Vector3.Dot(-light_normal, wi);

            if (ndotd > 0.0)
            {
                return(Material.Get_Le(sr));
            }
            else
            {
                return(new Vector3());
            }
        }
Пример #32
0
        public override Vector3 Sample_F(ShadeRec sr, Vector3 wo, ref Vector3 wi)
        {
            Vector3 w = sr.Normal;
            Vector3 v = Vector3.Cross(new Vector3(0.0034f, 1, 0.0071f), w);

            v.Normalize();
            Vector3 u  = Vector3.Cross(v, w);
            Vector3 sp = Sampler.SampleHemisphere();

            wi = sp.X * u + sp.Y * v + sp.Z * w;
            wi.Normalize();
            return(ReflectionCoefficient * Texture.GetColor(sr) * MathUtil.InvPI);
        }
Пример #33
0
        public override Vector3 L(ShadeRec sr)
        {
            float nDotD = (-m_lightNormal).Dot(m_wi);

            if (nDotD > 0f)
            {
                return(m_material.Shade(sr));
            }
            else
            {
                return(ColourF.Black);
            }
        }
Пример #34
0
        public override RGBColor Shade(ShadeRec sr)
        {
            RGBColor L = base.Shade(sr); //Factor in all direct illumination

            Vect3D reflectedDirection = -sr.Ray.Direction; //Vector pointing towards camera
            Vect3D perfectReflection = new Vect3D(1.0f,1.0f,1.0f); //Vector equivalent to perfect reflection
            RGBColor fr = reflectiveBRDF.SampleF(sr, ref perfectReflection, ref reflectedDirection); //Set vectors for reflection to correct values
            Point3D hitPoint = sr.HitPoint + (perfectReflection * GlobalVars.SHAD_K_EPSILON); //Avoid salt+pepper noise
            Ray reflectedRay = new Ray(hitPoint, perfectReflection); //Cast ray from point of incidence

            L += fr * sr.WorldPointer.CurrentTracer.TraceRay(reflectedRay, sr.RecursionDepth + 1) * (sr.Normal * perfectReflection); //Recurse!

            return L;
        }
Пример #35
0
        public override RGBColor TraceRay(Ray ray, int depth)
        {
            ShadeRec shadeRec = new ShadeRec(world); //not used
            double t; // not used

            if (world.Sphere.Intersect(ray, out t, shadeRec))
            {
                return new RGBColor(1, 0, 0);
            }
            else
            {
                return new RGBColor(0, 0, 0);
            }
        }
Пример #36
0
 //Copy constructor
 public ShadeRec(ShadeRec shadeRec)
 {
     HitAnObject = shadeRec.HitAnObject;
     ObjectMaterial = shadeRec.ObjectMaterial;
     HitPoint = shadeRec.HitPoint;
     HitPointLocal = shadeRec.HitPointLocal;
     Normal = shadeRec.Normal;
     Color = shadeRec.Color;
     WorldPointer = shadeRec.WorldPointer;
     Ray = shadeRec.Ray;
     RecursionDepth = shadeRec.RecursionDepth;
     Direction = shadeRec.Direction;
     TMinimum = shadeRec.TMinimum;
     U = shadeRec.U;
     V = shadeRec.V;
 }
Пример #37
0
        public override RGBColor TraceRay(Ray ray, int depth)
        {
            ShadeRec shadeRec = new ShadeRec(world); //not used
            double t; // not used

            if (world.Sphere.Intersect(ray, out t, shadeRec))
            {
                return new RGBColor((float) (shadeRec.Normal.X + 1)/2,
                                    (float) (shadeRec.Normal.Y + 1)/2,
                                    (float) (shadeRec.Normal.Z + 1)/2);
            }
            else
            {
                return new RGBColor(0, 0, 0);
            }
        }
Пример #38
0
 public override RGBColor Shade(ShadeRec shadeRec)
 {
     Vector3d wo = -shadeRec.Ray.Direction;
     RGBColor L = ambientBRDF.Rho(shadeRec, wo)*shadeRec.World.AmbientLight.L((shadeRec));
     for (int i = 0; i < shadeRec.World.Lights.Count; i++)
     {
         Vector3d wi = shadeRec.World.Lights[i].GetDirection(shadeRec);
         double NdotWi = Vector3d.Dot(shadeRec.Normal, wi);
         if (NdotWi>0)
         {
             L = L + diffuseBRDF.F(shadeRec, wo, wi) +
                 glossySpecularBRDF.F(shadeRec, wo, wi)*shadeRec.World.Lights[i].L(shadeRec)*NdotWi;
         }
     }
     return L;
 }
Пример #39
0
        public override bool Intersect(Ray ray, out double tmin, ShadeRec shadeRec)
        {
            double t = Vector3d.Dot((Point - ray.Origin), Normal)
                       / Vector3d.Dot(ray.Direction, Normal);
            if (t>kEpsilon && !double.IsInfinity(t))
            {
                tmin = t;
                shadeRec.Normal = Normal;
                shadeRec.Hitpoint = ray.Origin + t*ray.Direction;

                return true;
            }
            else
            {
                tmin = 0;
                return false;
            }
        }
Пример #40
0
        public override bool Intersect(Ray ray, out double tmin, ShadeRec shadeRec)
        {
            double t = 0;
            Vector3d temp = ray.Origin - Center;
            double a = Vector3d.Dot(ray.Direction, ray.Direction);
            double b = Vector3d.Dot(temp, ray.Direction)*2;
            double c = Vector3d.Dot(temp, temp) - Radius*Radius;
            double disc = b*b - 4*a*c;

            tmin = 0;
            if (disc < 0)
            {
                return false;
            }
            else
            {
                //TODO: what if denom == 0?
                double e = Math.Sqrt(disc);
                double denom = 2*a;

                //smaller root
                t = (-b - e)/denom;
                if (t>kEpsilon)
                {
                    tmin = t;
                    shadeRec.Normal = (temp + t*ray.Direction)/Radius;
                    shadeRec.Hitpoint = ray.Origin + t*ray.Direction;
                    return true;
                }
                //larger root
                t = (-b + e) / denom;
                if (t > kEpsilon)
                {
                    tmin = t;
                    shadeRec.Normal = (temp + t * ray.Direction) / Radius;
                    shadeRec.Hitpoint = ray.Origin + t * ray.Direction;
                    return true;
                }

                //no valid intersection
                return false;
            }
        }
Пример #41
0
        //public void set_image(Image img_arg) { img = img_arg; }
        public override RGBColor GetColor(ShadeRec sr)
        {
            float u;
            float v;

            //Use provided UV coordinates if no map type defined
            if (_mapType == null)
            {
                u = sr.U;
                v = sr.U;
            }
            else
            {
                Point2D uv = _mapType.GetUV(sr.HitPointLocal);
                u = uv.coords.X;
                v = uv.coords.Y;
            }

            return _image.GetColorAtUV(u, v, true);
        }
Пример #42
0
 public virtual RGBColor Shade(ShadeRec shadeRec)
 {
     return new RGBColor();
 }
Пример #43
0
 //public void setMapper(Mapper map) { _mapType = map; }
 public virtual RGBColor GetColor(ShadeRec sr)
 {
     return new RGBColor(1, 1, 1);
 }
Пример #44
0
 public abstract RGBColor Shade(ShadeRec sr);
Пример #45
0
        //Gets and sets
        /*
        virtual public void setKa(float ka) { ambientBRDF.DiffuseReflectionCoefficient = ka; }
        virtual public void setKd(float kd) { diffuseBRDF.DiffuseReflectionCoefficient = kd; }
        virtual public void setCd(RGBColor c) { ambientBRDF.ColorDiffuse = c; diffuseBRDF.ColorDiffuse = c; specularBRDF.ColorSpecular = c; }
        virtual public void setExp(float exp) { specularBRDF.PhongExponent = exp; }
        virtual public void setKs(float ks) { specularBRDF.SpecularReflectionCoefficient = ks; }
        virtual public void setCd(Texture tex) { ambientBRDF.Texture = tex; diffuseBRDF.Texture = tex; }
        */
        public override RGBColor Shade(ShadeRec sr)
        {
            Vect3D reflectedDirection = -sr.Ray.Direction; //Ray pointing from point of intersection to camera.
            RGBColor L = ambientBRDF.Rho(sr, reflectedDirection) * sr.WorldPointer.AmbientLight.GetLighting(sr); //Start with ambient
            int numlights = sr.WorldPointer.LightList.Count;
            Vect3D incomingDirection; //Direction to incident light
            float nDotWi;
            bool inShadow;
            Ray shadowRay;

            //Add together light contributions for all light sources
            for(int i = 0; i<numlights; i++)
            {
                incomingDirection = sr.WorldPointer.LightList[i].GetDirection(sr); //Get the direction from the point of contact to the light source.
                nDotWi = (float)(sr.Normal * incomingDirection); //Dot product of normal and light source, 0 if orthogonal, 1 if parallel.
                if(nDotWi > 0.0f)//Avoid unnecessary light summation
                {
                    inShadow = false;

                    if(sr.WorldPointer.LightList[i].CastsShadows)
                    {
                        shadowRay = new Ray(sr.HitPoint+(GlobalVars.SHAD_K_EPSILON*incomingDirection), incomingDirection);
                        inShadow = sr.WorldPointer.LightList[i].InShadow(sr, shadowRay);
                    }
                    if (!inShadow)
                    {
                        //Add diffuse and specular components.
                        L += (diffuseBRDF.F(sr, reflectedDirection, incomingDirection) + specularBRDF.F(sr, reflectedDirection, incomingDirection)) * sr.WorldPointer.LightList[i].GetLighting(sr) * nDotWi;
                    }
                }
            }

            return L;
        }
Пример #46
0
 public virtual RGBColor Rho(ShadeRec sr, Vect3D reflectedDirection)
 {
     return GlobalVars.COLOR_BLACK;
 }
Пример #47
0
 public override RGBColor F(ShadeRec shadeRec, Geometry.Vector3d wi, Geometry.Vector3d wo)
 {
     return CD*KD*1/Math.PI;
 }
Пример #48
0
 public override Vector3d GetDirection(ShadeRec shadeRec)
 {
     return new Vector3d();
 }
Пример #49
0
 public virtual RGBColor SampleF(ShadeRec shadeRec, Vector3d wi, Vector3d wo)
 {
     return new RGBColor();
 }
Пример #50
0
 public virtual RGBColor Rho(ShadeRec shadeRec,Vector3d wo)
 {
     return new RGBColor();
 }
Пример #51
0
 public override RGBColor L(ShadeRec shadeRec)
 {
     return color*ls;
 }
Пример #52
0
 public virtual bool Intersect(Ray ray, out double tmin, ShadeRec shadeRec)
 {
     tmin = 0;
     return false;
 }
Пример #53
0
 public override Vector3d GetDirection(ShadeRec shadeRec)
 {
     Vector3d dir = Location - (Vector3d) shadeRec.Hitpoint;
     dir.Normalize();
     return dir;
 }
Пример #54
0
 public override RGBColor Rho(ShadeRec shadeRec, Geometry.Vector3d wo)
 {
     return CD*KD;
 }
Пример #55
0
 public virtual RGBColor AreaLightShade(ShadeRec shadeRec)
 {
     return new RGBColor();
 }
Пример #56
0
 public override RGBColor L(ShadeRec shadeRec)
 {
     return Color*LightScale;
 }
Пример #57
0
 public virtual RGBColor SampleF(ShadeRec sr, ref Vect3D incomingDirection, ref Vect3D reflectedDirection)
 {
     return GlobalVars.COLOR_BLACK;
 }
Пример #58
0
 public virtual Vector3d GetDirection(ShadeRec shadeRec)
 {
     return new Vector3d();
 }