public CanonicalGlassMaterial(RgbSpectrum r, RgbSpectrum s, MediumInfo m)
 {
     Kr = r;
     Kt = s;
     Medium = m;
     fresnel = new FresnelDielectric(1f, m.IoR);
 }
Example #2
0
        public BaseBxdf GetBsdf(ref RayData pathRay, ref RayHit hit, ref MediumInfo med, bool fromLight, float u0)
        {
            var currentTriangleIndex = (int) hit.Index;
            bool isLight = scene.IsLight(currentTriangleIndex);

            var mesh = scene.GetMeshByTriangleIndex(currentTriangleIndex);
            if (mesh == null)
            //|| mesh.MeshName.Equals("COL254_01", StringComparison.InvariantCultureIgnoreCase))
            {
                //ii.Color = new RgbSpectrum(1f);
                //Debugger.Break();
                throw new ApplicationException("Invalid triangle index " + currentTriangleIndex + " Mesh not found");
            }
            UV TexCoords;
            Normal normal = new Normal(), shadeN = new Normal();

            mesh.InterpolateTriUV(currentTriangleIndex, hit.U, hit.V, out TexCoords);
            //normal = -scene.Triangles[currentTriangleIndex].ComputeNormal(scene.Vertices).Normalize();

            mesh.InterpolateTriangleNormal((int)hit.Index, hit.U, hit.V, ref normal);
            //normal = -normal;
            shadeN = (Normal.Dot(ref pathRay.Dir, ref normal) > 0f) ? -normal : normal;


            var bsdf =  mesh.Material.GetBsdf(ref pathRay, ref hit, ref normal, ref shadeN, ref TexCoords, ref med, fromLight,u0);
            bsdf.SetLight(isLight);
            return bsdf;
        }
Example #3
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];
     }
     contCount = 0;
     this.Sample = pathIntegrator.Sampler.GetSample(this.Sample);
     pathIntegrator.Scene.Camera.GetRay(Sample.imageX, Sample.imageY, out this.PathRay);
     this.RayIndex = -1;
     this.tracedShadowRayCount = 0;
     this.depth = 0;
     this.currentMedium = MediumInfo.Air;
     this.bsdfEvent = BsdfEvent.Specular;
     this.prevEvent = BsdfEvent.None;
     shadowRayEvent = BsdfEvent.None;
 }
        private RgbSpectrum Shade(MediumInfo currentMedium, float weight, RayInfo vray, IntersectionInfo isect, int depth)
        {
            var txtn = isect.GeometryInfo.GeoNormal;
            var p = isect.GeometryInfo.HitPoint;
            Vector v1, v2;
            Vector.CoordinateSystem(ref txtn, out v1, out v2);

            var Radiance = BaseColor * Vector.AbsDot(ref txtn, ref vray.Dir);
            for (int i = 0; i < shadowRayCount; i++)
            {
                var dir = MC.CosineSampleHemisphere(rnd.Value.NextFloat(), rnd.Value.NextFloat());
                dir = new Vector(v1.x * dir.x + v2.x * dir.y + txtn.x * dir.z, v1.y * dir.x + v2.y * dir.y + txtn.y * dir.z, v1.z * dir.x + v2.z * dir.y + txtn.z * dir.z);
                stats.intersections++;
                if (!manager.Intersect(new RayInfo(p, dir, 1e-4f, maxOcclussionRayLength)))
                {
                    Radiance += AddedRadiance * (1.0f / shadowRayCount);
                }
            }
            return Radiance;
        }
 private RgbSpectrum Trace(RayInfo ray, float weight, MediumInfo currentMedium, int depth)
 {
     IntersectionInfo isect;
     //RaysTraced++;
     stats.totalRays++;
     var color = new RgbSpectrum(0f);
     if (manager.Intersect(ray, out isect))
     {
         stats.intersections++;
         //Intersections++;
         color = this.Shade(currentMedium, weight, ray, isect, depth);
     }
     else
     {
         color = this.ShadeBackground(ray);
     }
     return color;
 }