Exemplo n.º 1
0
        private void storePhoton(Photon photon, EnlightenmentType enlightenmentType)
        {
            switch (enlightenmentType)
            {
            //case EnlightenmentType.Direct:
            //    //Do nothing - Classic RayTracing
            //    ;
            //break;
            case EnlightenmentType.Indirect:
                this.storedIndirect++;
                this.indirectEnlightenment.Store(photon);
                break;

            case EnlightenmentType.Caustics:
                this.storedCaustic++;
                this.CausticsEnlightenment.Store(photon);
                break;
            }
        }
Exemplo n.º 2
0
 private void storePhoton(Photon photon, EnlightenmentType enlightenmentType)
 {
     switch (enlightenmentType) {
             //case EnlightenmentType.Direct:
             //    //Do nothing - Classic RayTracing
             //    ;
             //break;
         case EnlightenmentType.Indirect:
             this.storedIndirect++;
             this.indirectEnlightenment.Store(photon);
             break;
         case EnlightenmentType.Caustics:
             this.storedCaustic++;
             this.CausticsEnlightenment.Store(photon);
             break;
     }
 }
Exemplo n.º 3
0
        public void ShootPhoton(Photon photon, int depth, EnlightenmentType enlightenmentType)
        {
            Intersection intersection;
            if (this.scene.FindIntersection(photon, out intersection) && (depth < this.MaxRecursions)) {
                Material material = intersection.HitPrimitive.Material;
                //this.scene.Shader = material.CreateShader(this.scene);
                //RGBColor color = this.scene.Shader.Shade(photon, intersection);

                //float avgPower = photon.Power.Average;
                //float probDiff = avgPower * material.KDiff;
                //float probSpec = avgPower * material.KSpec;
                //float avgPower = photon.Power.Average;
                RGBColor mixColor = (photon.Power * material.DiffuseColor);
                float maxColor = Max(mixColor.R, mixColor.G, mixColor.B) /
                                 Max(photon.Power.R, photon.Power.G, photon.Power.B);
                float probDiff = maxColor * material.KDiff;
                float probTrans = maxColor * material.KTrans;
                float probSpec = maxColor * material.KSpec;
                Photon rPhoton = new Photon();
                Random rdn = new Random();
                double randomValue = rdn.NextDouble();
                if (randomValue <= probDiff) {
                    photon.Position = intersection.HitPoint;
                    //photon.Power = mixColor / probDiff;
                    this.storePhoton(photon, enlightenmentType);

                    rPhoton.Position = intersection.HitPoint;
                    rPhoton.Power = mixColor / probDiff;
                    rPhoton.Direction = Vector3D.ReflectedDiffuse(intersection.Normal);
                    this.ShootPhoton(rPhoton, depth + 1, EnlightenmentType.Indirect);
                } else if (randomValue <= probSpec + probDiff) {
                    rPhoton.Direction = Vector3D.Reflected(intersection.Normal, photon.Direction);
                    //rPhoton.Direction.Normalize();
                    rPhoton.Position = intersection.HitPoint;
                    rPhoton.Power = mixColor / probSpec;
                    this.ShootPhoton(rPhoton, depth + 1, EnlightenmentType.Caustics);
                } else if (randomValue <= probSpec + probDiff + probTrans) {
                    Vector3D T;
                    //float eta = intersection.HitFromInSide
                    //                ? material.RefractIndex * 1 / this.scene.RefractIndex
                    //                : this.scene.RefractIndex * 1 / material.RefractIndex;
                    //float eta = this.scene.RefractIndex * 1 / material.RefractIndex;
                    float eta = (photon.PrevRefractIndex.IsEqual(material.RefractIndex))
                                    ? material.RefractIndex * 1 / this.scene.RefractIndex
                                    : this.scene.RefractIndex * 1 / material.RefractIndex;
                    if (Vector3D.Refracted(intersection.Normal, photon.Direction, out T, eta)) {
                        rPhoton.Position = intersection.HitPoint;
                        rPhoton.Direction = T;
                        rPhoton.Power = mixColor / probTrans;
                        rPhoton.PrevRefractIndex = material.RefractIndex;
                        this.ShootPhoton(rPhoton, depth + 1, EnlightenmentType.Caustics);
                    }
                } else {
                    photon.Position = intersection.HitPoint;
                    //Absorb
                    this.storePhoton(photon, enlightenmentType);
                }
            }
        }
Exemplo n.º 4
0
        public void ShootPhoton(Photon photon, int depth, EnlightenmentType enlightenmentType)
        {
            Intersection intersection;

            if (this.scene.FindIntersection(photon, out intersection) && (depth < this.MaxRecursions))
            {
                Material material = intersection.HitPrimitive.Material;
                //this.scene.Shader = material.CreateShader(this.scene);
                //RGBColor color = this.scene.Shader.Shade(photon, intersection);

                //float avgPower = photon.Power.Average;
                //float probDiff = avgPower * material.KDiff;
                //float probSpec = avgPower * material.KSpec;
                //float avgPower = photon.Power.Average;
                RGBColor mixColor = (photon.Power * material.DiffuseColor);
                float    maxColor = Max(mixColor.R, mixColor.G, mixColor.B) /
                                    Max(photon.Power.R, photon.Power.G, photon.Power.B);
                float  probDiff    = maxColor * material.KDiff;
                float  probTrans   = maxColor * material.KTrans;
                float  probSpec    = maxColor * material.KSpec;
                Photon rPhoton     = new Photon();
                Random rdn         = new Random();
                double randomValue = rdn.NextDouble();
                if (randomValue <= probDiff)
                {
                    photon.Position = intersection.HitPoint;
                    //photon.Power = mixColor / probDiff;
                    this.storePhoton(photon, enlightenmentType);

                    rPhoton.Position  = intersection.HitPoint;
                    rPhoton.Power     = mixColor / probDiff;
                    rPhoton.Direction = Vector3D.ReflectedDiffuse(intersection.Normal);
                    this.ShootPhoton(rPhoton, depth + 1, EnlightenmentType.Indirect);
                }
                else if (randomValue <= probSpec + probDiff)
                {
                    rPhoton.Direction = Vector3D.Reflected(intersection.Normal, photon.Direction);
                    //rPhoton.Direction.Normalize();
                    rPhoton.Position = intersection.HitPoint;
                    rPhoton.Power    = mixColor / probSpec;
                    this.ShootPhoton(rPhoton, depth + 1, EnlightenmentType.Caustics);
                }
                else if (randomValue <= probSpec + probDiff + probTrans)
                {
                    Vector3D T;
                    //float eta = intersection.HitFromInSide
                    //                ? material.RefractIndex * 1 / this.scene.RefractIndex
                    //                : this.scene.RefractIndex * 1 / material.RefractIndex;
                    //float eta = this.scene.RefractIndex * 1 / material.RefractIndex;
                    float eta = (photon.PrevRefractIndex.IsEqual(material.RefractIndex))
                                    ? material.RefractIndex * 1 / this.scene.RefractIndex
                                    : this.scene.RefractIndex * 1 / material.RefractIndex;
                    if (Vector3D.Refracted(intersection.Normal, photon.Direction, out T, eta))
                    {
                        rPhoton.Position         = intersection.HitPoint;
                        rPhoton.Direction        = T;
                        rPhoton.Power            = mixColor / probTrans;
                        rPhoton.PrevRefractIndex = material.RefractIndex;
                        this.ShootPhoton(rPhoton, depth + 1, EnlightenmentType.Caustics);
                    }
                }
                else
                {
                    photon.Position = intersection.HitPoint;
                    //Absorb
                    this.storePhoton(photon, enlightenmentType);
                }
            }
        }