示例#1
0
        public override void InitPath(IPathProcessor buffer)
        {
            base.InitPath(buffer);
            MaxRaysPerPath = 1;
            this.scene = pathIntegrator.Scene;
            var pssSampler = (PsMltSampler)this.pathIntegrator.Sampler;

            this.Radiance = new RgbSpectrum(0f);
            this.Throughput = new RgbSpectrum(1f);
            if (this.Sample == null || this.Sample.LargeStep || pssSampler.BurnInPhase ||this.Sample.MutationsCount > (pssSampler.MaxMutations))
            {
                this.Sample = (PsSample)pssSampler.GetSample(this.Sample);
            }
            else
            {
                this.Sample.imageX = MC.Mutate(this.Sample.imageX, pssSampler.NextFloat(), pssSampler.NextFloat(),2.0f/(2000),0.1f);
                this.Sample.imageY = MC.Mutate(this.Sample.imageY, pssSampler.NextFloat(), pssSampler.NextFloat(), 2.0f / (2000), 0.1f);
                pssSampler.TotalSamples++;
            }
            IRay ray;
            pathIntegrator.Scene.Camera.GetRay(Sample.imageX, Sample.imageY, out ray);
            this.PathRay = (RayData)ray;
            this.RayIndex = -1;
            this.pathWeight = 1.0f;
            this.tracedShadowRayCount = 0;
            this.depth = 0;
            this.specularBounce = true;
        }
        public override void InitPath(IPathProcessor buffer)
        {
            base.InitPath(buffer);
            this.scene = pathIntegrator.Scene;
            this.PathState = PathTracerPathState.EyeVertex;
            if (this.secRays == null)
                this.secRays = new ConnectRayInfo[MaxEyeRays];
            this.RayIndex = -1;
            this.pathWeight = 1.0f;
            this.tracedShadowRayCount = 0;
            this.depth = 0;
            this.specularBounce = true;
            this.Radiance = new RgbSpectrum(0f);

            this.Sample = pathIntegrator.Sampler.GetSample(null);
            LightSample ls;
            var light = scene.Lights[scene.SampleLights(Sample.GetLazyValue())];
            light.EvaluatePhoton(scene, Sample.GetLazyValue(), Sample.GetLazyValue(), Sample.GetLazyValue(), Sample.GetLazyValue(), Sample.GetLazyValue(), out ls);
            PathRay = ls.LightRay;
            var lightPdf = ls.Pdf;
            Throughput = (RgbSpectrum)(ls.Spectrum);
            //* scene.Lights.Length) / lightPdf;

            //buffer.Scene.Camera.GetRay(Sample.imageX, Sample.imageY, out this.PathRay);
        }
 public CanonicalGlassMaterial(RgbSpectrum r, RgbSpectrum s, MediumInfo m)
 {
     Kr = r;
     Kt = s;
     Medium = m;
     fresnel = new FresnelDielectric(1f, m.IoR);
 }
示例#4
0
 public MeshLight(FrameLightsource lightsource)
 {
     MeshName = lightsource.Parameters.Get<string>(FrameLightsource.AreaLightGeometryName);
     LightName = MeshName;
     spectra = SPD_Data.FromSampled(SPD_Data.A, SpectrumType.Illuminant);
     gain = lightsource.Parameters.Get<RgbSpectrum>(FrameLightsource.LightsourcePower);
 }
示例#5
0
 public override void f(ref Vector WO, ref Vector WI, ref Normal N, ref RgbSpectrum in_fs, out RgbSpectrum fs)
 {
     CreateFrame(ref N);
     var lwo = WorldToLocal(ref WO);
     var lwi = WorldToLocal(ref WI);
     EvalBrdf(out fs, ref lwo, ref lwi);
 }
示例#6
0
        private void EvalBrdf(out RgbSpectrum fs,ref  Vector wo, ref Vector wi)
        {

            Vector wh = wo + wi;

            if (wh.z < 0f)
            {
                wo = -wo;
                wi = -wi;
                wh = -wh;
            }
            if (wh.x.NearZero() && wh.y.NearZero() && wh.z.NearZero())
            {
                fs = RgbSpectrum.ZeroSpectrum();
                return;
            }
            wh = Vector.Normalize(wh);
            float whTheta = SphericalTheta(ref wh);
            float whCosPhi = CosPhi(ref wh), whSinPhi = SinPhi(ref wh);
            float whCosTheta = CosTheta(ref wh), whSinTheta = SinTheta(ref wh);
            Vector whx = new Vector(whCosPhi*whCosTheta, whSinPhi*whCosTheta, -whSinTheta);
            Vector why = new Vector(-whSinPhi, whCosPhi, 0);
            Vector wd = new Vector(Vector.Dot(ref wi, ref whx), Vector.Dot(ref wi, ref why), Vector.Dot(ref wi, ref wh));

            // Compute _index_ into measured BRDF tables
            float wdTheta = SphericalTheta(ref wd), wdPhi = SphericalPhi(ref wd);
            if (wdPhi > MathLab.M_PI) wdPhi -= MathLab.M_PI;

            // Compute indices _whThetaIndex_, _wdThetaIndex_, _wdPhiIndex_
            int whThetaIndex = REMAP(MathLab.Sqrt(Math.Max(0f, whTheta/(MathLab.M_PI/2f))),
                                     1f, nThetaH);
            int wdThetaIndex = REMAP(wdTheta, MathLab.M_PI/2f, nThetaD);
            int wdPhiIndex = REMAP(wdPhi, MathLab.M_PI, nPhiD);
            int index = wdPhiIndex + nPhiD*(wdThetaIndex + whThetaIndex*nThetaD);

            //try {

                /*int rIndex = index;
                int gIndex = index + 1;
                int bIndex = index + 2;*/
                
                int rIndex = index;
                int gIndex = index + BRDF_SAMPLING_RES_THETA_H*BRDF_SAMPLING_RES_THETA_D*BRDF_SAMPLING_RES_PHI_D/2;
                int bIndex = index + BRDF_SAMPLING_RES_THETA_H*BRDF_SAMPLING_RES_THETA_D*BRDF_SAMPLING_RES_PHI_D;
                
                /*
                int rIndex = 3*index;
                int gIndex = 3*index + 1;//BRDF_SAMPLING_RES_THETA_H * BRDF_SAMPLING_RES_THETA_D * BRDF_SAMPLING_RES_PHI_D / 2;
                int bIndex = 3*index + 2;//BRDF_SAMPLING_RES_THETA_H * BRDF_SAMPLING_RES_THETA_D * BRDF_SAMPLING_RES_PHI_D;
                */
                fs = new RgbSpectrum((float) (brdf[Math.Min(rIndex, brdf.Length-1)]*RED_SCALE),
                                     (float) (brdf[Math.Min(gIndex, brdf.Length-1)]*GREEN_SCALE),
                                     (float) (brdf[Math.Min(bIndex, brdf.Length-1)]*BLUE_SCALE));
                /*
            }
            catch (IndexOutOfRangeException ex)
            {
                fs = new RgbSpectrum(0f);
            }*/
        }
示例#7
0
        public override void InitPath(IPathProcessor buffer)
        {
            base.InitPath(buffer);
            this.scene = pathIntegrator.Scene;

            this.Radiance = new RgbSpectrum(0f);
            this.PathState = BDPTSamplerState.InitPath;
            if (this.connectRays == null)
                this.connectRays = new ConnectRayInfo[scene.MaxPathDepth * scene.MaxPathDepth];
            lightPath = new VertexInfo[MaxLightDepth];
            this.Sample = pathIntegrator.Sampler.GetSample(null);
            lightVertices = 0;

            //Init eye ray
            this.EyeThroughput = new RgbSpectrum(1f);
            pathIntegrator.Scene.Camera.GetRay(Sample.imageX, Sample.imageY, out this.PathRay);
            this.RayIndex = -1;
            this.LightRayIndex = -1;
            this.eyePdf = 1f;

            //Init light path
            LightSample ls;
            var light = scene.Lights[scene.SampleLights(Sample.GetLazyValue())];
            light.EvaluatePhoton(scene, Sample.GetLazyValue(), Sample.GetLazyValue(), Sample.GetLazyValue(), Sample.GetLazyValue(), Sample.GetLazyValue(), out ls);
            LightRay = ls.LightRay;
            lightPdf = ls.Pdf * (1f / scene.Lights.Length);
            LightThroughput = (RgbSpectrum)(ls.Spectrum);


            this.tracedConnectRayCount = 0;
            this.eyeDepth = 0;
            this.lightDepth = 0;
            this.eyeStop = false;
            this.lightStop = false;
        }
示例#8
0
        public Photon(ref Point pt, ref Vector dir, ref RgbSpectrum power)
        {
            var dirx = MathLab.Clamp(dir.z, -1f, 1f);

            int theta = Convert.ToInt32(Math.Acos(dirx) * (256.0d / Math.PI));
            if (theta > 255)
                theta = 255;

            Theta = (byte)theta;

            int phi = Convert.ToInt32(Math.Atan2(dir.y, dir.x) * (256.0d / 2.0 * Math.PI));


            if (phi > 255)
                phi = 255;
            else

                if (phi < 0)
                    phi = phi + 256;

            Phi = (byte)phi;
            Position = pt;
            Power = power;
            Plane = 0;
        }
示例#9
0
 public SphereAreaLight(LightsourceInfo frameLight)
 {
     this.Position = (Point)frameLight.Position;
     this.Power = new RgbSpectrum(frameLight.Spectra);
     this.Spectra = SPD_Data.FromSampled(SPD_Data.D5000, SpectrumType.Illuminant);
     //new SampledSpectrum(ref this.Power, SpectrumType.Illuminant);
 }
示例#10
0
        public override void Sample_f(ref Vector wo, ref Normal N, ref Normal shadeN, ref RgbSpectrum in_f, float u0, float u1, float u2, ref SurfaceTextureData surfaceData, out BsdfSampleData result)
        {
            result.Lambda = 0f;

            Vector dir =
                MC.CosineSampleHemisphere(u0, u1);
            result.Pdf = dir.z * MathLab.INVPI;
            result.Type = BrdfType.Diffuse;
            Vector v1, v2;
            Normal n = N;
            Vector.CoordinateSystem(ref n, out v1, out v2);

            dir = new Vector(
                v1.x * dir.x + v2.x * dir.y + n.x * dir.z,
                v1.y * dir.x + v2.y * dir.y + n.y * dir.z,
                v1.z * dir.x + v2.z * dir.y + n.z * dir.z);

            var wi = dir;

            float dp = (Normal.Dot(ref shadeN, ref wi));
            if (dp <= 0.01f)
            {
                result.Pdf = 0f;
                result.F = new RgbSpectrum();
            }
            else
            {
                result.Pdf /= dp;
                result.F = surfaceData.Diffuse*MathLab.INVPI;
            }
            result.Wi = wi;
        }
示例#11
0
        public override void InitPath(IPathProcessor buffer)
        {
            base.InitPath(buffer);
            scene = pathIntegrator.Scene;

            this.Sample = new Sample(pathIntegrator.Sampler);
            this.RayIndex = -1;
            float lspdf;

            int li = scene.SampleLights(this.Sample.GetLazyValue(), out lspdf);
            var ls = new LightSample();
            bool done = false;
            while (!done)
            {
                scene.Lights[li].EvaluatePhoton(
                    scene,
                    Sample.GetLazyValue(),
                    Sample.GetLazyValue(),
                    Sample.GetLazyValue(),
                    Sample.GetLazyValue(),
                    Sample.GetLazyValue(),
                    out ls);

                done = ls.Pdf > 0f;

            }

            var pathWeight =  (ls.Pdf *  lspdf);

            this.ThroughtPut = ((RgbSpectrum)(ls.Spectrum) / pathWeight);
            this.PathRay = ls.LightRay;
        }
示例#12
0
        public override void Sample_f(ref Vector wo, ref Normal N, ref Normal shadeN, ref RgbSpectrum in_f, float u0, float u1, float u2, ref SurfaceTextureData surfaceData, out BsdfSampleData result) {
            EvalParams(ref surfaceData);

            bool into = (Normal.Dot(ref N, ref shadeN) > 0f);
            result = new BsdfSampleData();
            result.Type = this.Type;

            if (!into) {
                // No internal reflections
                result.Wi = (-wo);
                result.Pdf = 1f;
                result.Type = reflectionSpecularBounce ? BrdfType.Specular : BrdfType.Glossy;
                result.F =  Krefl;
            }
            else {
                // RR to choose if reflect the ray or go trough the glass
                float comp = u0 * totFilter;
                if (comp > transFilter) {
                    Vector mwo = -wo;
                    result.Wi = mwo - (2f * Vector.Dot(ref N, ref mwo)) * N.ToVec();
                    result.Pdf = reflPdf;
                    result.Type = reflectionSpecularBounce ? BrdfType.Specular : BrdfType.Glossy;
                    result.F = Krefrct;
                }
                else {
                    result.Wi = -wo;
                    result.Pdf = transPdf;
                    result.F = Krefrct;
                    result.Type = transmitionSpecularBounce ? BrdfType.Specular : BrdfType.Glossy;
                }
            }

        }
示例#13
0
 public override void InitPath(IPathProcessor buffer)
 {
     base.InitPath(buffer);
     this.scene = pathIntegrator.Scene;
     this.Radiance = new RgbSpectrum(0f);
     this.Throughput = new RgbSpectrum(1f);
     this.PathState = PathTracerPathState.EyeVertex;
     if (this.secRays == null)
         this.secRays = new ShadowRayInfo[scene.ShadowRayCount];
     if (this.volumeComp == null)
     {
         this.volumeComp = scene.GetVolumeComputation();
     }
     else
     {
         this.volumeComp.Reset();
     }
     this.Sample = pathIntegrator.Sampler.GetSample(null);
     IRay ray;
     pathIntegrator.Scene.Camera.GetRay(Sample.imageX, Sample.imageY, out ray);
     this.PathRay = (RayData)ray;
     this.RayIndex = -1;
     this.pathWeight = 1.0f;
     this.tracedShadowRayCount = 0;
     this.depth = 0;
     this.specularBounce = true;
     this.rayID = (int)(Sample.imageX + Sample.imageY * 640f);
 }
示例#14
0
        public override void InitPath(IPathProcessor buffer)
        {
            //Choose lightsource
            //Sample it
            base.InitPath(buffer);
            this.Sample = new Sample(pathIntegrator.Sampler);
            this.RayIndex = -1;
            float lspdf;

            int li = scene.SampleLights(this.Sample.GetLazyValue(), out lspdf);
            RayData ray;

            var ls = new LightSample();
            bool done = false;
            while (!done)
            {
                scene.Lights[li].EvaluatePhoton(
                    scene,
                    Sample.GetLazyValue(),
                    Sample.GetLazyValue(),
                    Sample.GetLazyValue(),
                    Sample.GetLazyValue(),
                    Sample.GetLazyValue(),
                    out ls);

                done = ls.Pdf > 0f;

            }

            this.pathWeight = 10000 /(ls.Pdf * lspdf);
            ls.Spectrum.Mul(pathWeight);
            this.ThroughtPut = new RgbSpectrum(ls.Spectrum.ToArray());
            this.PathRay = ls.LightRay;
        }
示例#15
0
文件: BxDF.cs 项目: HungryBear/rayden
        public static RgbSpectrum FrDiel(float coso, float cost, RgbSpectrum etao, RgbSpectrum etat)
        {
            RgbSpectrum Rparl = ((etat * coso) - (etao * cost)) / ((etat * coso) + (etao * cost));
            RgbSpectrum Rperp = ((etao * coso) - (etat * cost)) / ((etao * coso) + (etat * cost));

            return (Rparl * Rparl + Rperp * Rperp) / 2f;
        }
示例#16
0
        public override void Sample_f(ref Vector wo, ref Normal N, ref Normal shadeN, ref RgbSpectrum in_f, float u0, float u1, float u2, ref SurfaceTextureData surfaceData, out BsdfSampleData result)
        {
            result.Lambda = 0f;

            Vector dir = MC.CosineSampleHemisphere(u0, u1);
            result.Pdf = dir.z * MathLab.INVPI;
            result.Type = BrdfType.Diffuse | BrdfType.Refractive;

            Vector v1, v2;
            Normal n = -N;
            Vector.CoordinateSystem(ref n, out v1, out v2);

            dir = new Vector(
                v1.x * dir.x + v2.x * dir.y + n.x * dir.z,
                v1.y * dir.x + v2.y * dir.y + n.y * dir.z,
                v1.z * dir.x + v2.z * dir.y + n.z * dir.z);

            var wi = dir;

            float dp = (Normal.AbsDot(ref n, ref wi));
            // Using 0.01 instead of 0.0 to cut down fireflies
            if (dp <= 0.0001f)
            {
                result.Pdf /= 1000f;
                //    return new RgbSpectrum(0f);
            }
            else
            {
                result.Pdf /= dp;
            }

            result.F=  KdOverPI;
            result.Wi = wi;
        }
示例#17
0
 public override void InitPath(IPathProcessor buffer)
 {
     base.InitPath(buffer);
     this.scene = pathIntegrator.Scene;
     this.Radiance = new RgbSpectrum(0f);
     this.Throughput = new RgbSpectrum(1f);
     this.PathState = PathTracerPathState.EyeVertex;
     if (this.secRays == null)
     {
         this.secRays = new ShadowRayInfo[scene.ShadowRaysPerSample];
         continueRays = new ShadowRayInfo[scene.ShadowRaysPerSample];
     }
     if (volumeComp == null)
     {
         volumeComp = new VolumeComputation(scene.VolumeIntegrator);
     }
     contCount = 0;
     this.Sample = pathIntegrator.Sampler.GetSample(this.Sample);
     pathIntegrator.Scene.Camera.GetRay(Sample.imageX, Sample.imageY, out this.PathRay);
     this.RayIndex = -1;
     this.pathWeight = 1.0f;
     this.tracedShadowRayCount = 0;
     this.depth = 0;
     this.specularBounce = true;
     this.inVolume = false;
 }
示例#18
0
 public override void f(ref Vector lwo, ref Vector lwi, ref Normal N, ref RgbSpectrum in_fs, out RgbSpectrum fs)
 {
     CreateFrame(ref N);
     var wi = WorldToLocal(ref lwi);
     var wo = WorldToLocal(ref lwo);
     EvalBrdf(ref wo, ref wi, ref N, out fs);
 }
示例#19
0
 public InfiniteLight(RgbSpectrumTexture tx)
 {
     tex = tx;
     shiftU = 0f;
     shiftV = 0f;
     gain = new RgbSpectrum(1.0f);
 }
示例#20
0
        private void EvalBrdf(ref Vector wo, ref Vector wi, ref Normal N, out RgbSpectrum fs)
        {
            float cosThetaO = Vector.AbsDot(ref N, ref wo);
            //AbsCosTheta(wo);
            float cosThetaI = Vector.AbsDot(ref N, ref wi);
            //AbsCosTheta(wi);
            if (Math.Abs(cosThetaI - 0f) < Epsilon || Math.Abs(cosThetaO - 0f) < Epsilon)
            {
                fs = new RgbSpectrum(0f, 0f, 0f);
                return;
                //return new RgbSpectrum(1f, 0f, 0f);
            }
            Vector wh = wi + wo;
            if (wh.IsZero())
            {
                fs = new RgbSpectrum(0f);
                return;
            }
            //return new RgbSpectrum(1f, 0f, 0f);
            wh = wh.Normalize();
            float cosThetaH = Vector.Dot(ref wi, ref wh);
            var F = fresnel.Evaluate(cosThetaH);

            fs = (R0 * distr.D(ref wh) * G(ref N, ref wo, ref wi, ref wh) * F / (4f * cosThetaI * cosThetaO));
        }
示例#21
0
        public PhongMaterial(RgbSpectrum kd, RgbSpectrum ks, float exp)
        {
            Ks = ks * 0.45f;
            Kd = kd * 0.45f;
            this.exp = exp;

        }
示例#22
0
 public SkyLight(float turb, Vector sd)
 {
     this.turbidity = turb;
     this.sundir = sd.Normalize();
     this.gain = new RgbSpectrum(1f);
     this.Init();
 }
示例#23
0
        public void Store(ref RgbSpectrum power, ref Point position, ref Vector dir)
        {
            if (this.photonsCount > (this.maxPhotons - 2))
                return;



            if (power.Length <= 0f)
                return;
            var dirx = MathLab.Clamp(dir.z, -1f, 1f);
            int theta = Convert.ToInt32(Math.Acos(dirx) * (256.0d / Math.PI));
            if (theta > 255)
                theta = 255;
            var thetaB = (byte)theta;
            int phi = Convert.ToInt32(Math.Atan2(dir.y, dir.x) * (256.0d / 2.0 * Math.PI));
            if (phi > 255)
                phi = 255;
            else if (phi < 0)
                phi = phi + 256;
            var phiB = (byte)phi;
            this.hitPoints[photonsCount] = new Photon()
            {
                Position = position,
                Power = power,
                Theta = thetaB,
                Phi = phiB
            };
            this.photonsCount++;
        }
示例#24
0
 public DirectionalLight(Vector pos, RgbSpectrum power, SampledSpectrum spd)
 {
     this.Direction = pos;
     this.Power = power;
     this.Spectra = SPD_Data.FromSampled(SPD_Data.D5000, SpectrumType.Illuminant);
     //lightSpectra = GlobalConfiguration.Instance.SpectralRendering ? Spectra.ToArray() : this.Power.ToArray();
 }
示例#25
0
 public DirectionalLight(FrameLightsource frameLight)
 {
     this.Position = (Point)frameLight.Parameters.Get<Vector>(FrameLightsource.DirLightDirection);
     this.Power = frameLight.Parameters.Get<RgbSpectrum>(FrameLightsource.LightsourcePower);
     this.Spectra = SPD_Data.FromSampled(SPD_Data.D5000, SpectrumType.Illuminant);
     //new SampledSpectrum(ref this.Power, SpectrumType.Illuminant);
 }
示例#26
0
 protected override void EvalParams(ref SurfaceTextureData surfaceData)
 {
     Krefl = surfaceData.Specular;
     Kdiff = surfaceData.Diffuse;
     R0 = surfaceData.T0;
     KdiffOverPI = Kdiff * MathLab.INVPI;
     exponent = 1f / (surfaceData.Exponent + 1f);
 }
示例#27
0
 public DistributionBsdf(MicrofacetDistribution dist,IFresnelTerm f, RgbSpectrum r0)
 {
     this.R0 = r0;
     this.distr = 
         //dist;
     new Anisotropic(50f, 10f);
     this.fresnel = f;
 }
        public ImportanceSampledInfiniteLight(RgbSpectrumTexture tx, RgbSpectrumTexture tx_l)
        {
            Sampler = new LatLongMap(tx, tx_l);

            shiftU = 0f;
            shiftV = 0f;
            gain = GlobalConfiguration.Instance.SpectralRendering ? RgbSpectrum.UnitSpectrum() : new RgbSpectrum(0.1f);
        }
示例#29
0
 public void SetDistributions(ref RgbSpectrum kd, ref RgbSpectrum ks, ref RgbSpectrum kr, ref RgbSpectrum ke, ref RgbSpectrum kt)
 {
     this.Kd = ColorFactory.CreateRegularSpd(ref kd, SpectrumType.Reflectance);
     this.Ks = ColorFactory.CreateRegularSpd(ref ks, SpectrumType.Reflectance);
     this.Kr = ColorFactory.CreateRegularSpd(ref kr, SpectrumType.Reflectance);
     this.Kt = ColorFactory.CreateRegularSpd(ref kt, SpectrumType.Reflectance);
     this.Ke = ColorFactory.CreateRegularSpd(ref ke, SpectrumType.Reflectance);
 }
示例#30
0
        public AnisotropicPhong(RgbSpectrum kd, RgbSpectrum ks, float u, float v)
        {
            this.nu = u;
            this.nv = v;
            this.Kd = kd;
            this.Ks = ks;

        }