コード例 #1
0
        public void RenderDirectIllumination(RenderPointsStructure renderPointsStructure)
        {
            int i = 0;

            foreach (RenderPoint renderPoint in renderPointsStructure.RenderPoints)
            {
                Spectrum e = new Spectrum();
                if (renderPoint.Obj is ILight)
                {
                    e = ((ILight)renderPoint.Obj).GetIlluminanceSourceSurface(renderPoint.Position, renderPoint.Direction);     // Specturm.Zero; //new Specturm( 0.25f );
                }
                else if (renderPoint.Face.Material.Reflectance != null)
                {
                    foreach (ILight light in renderPointsStructure.Scene.Lights)
                    {
                        //if ( renderPoint.MirrorRenderPoint != null )
                        //    renderPoint.IsPrimaryPoint = true;

                        var toLightVector = new Vector(renderPoint.Position, light.Position, true);
                        var normal        = renderPoint.Face.Normal;
                        e += light.GetIlluminance(this.RayTracer, renderPoint.Face.Material, renderPoint.Position, normal, renderPoint.Direction);
                    }
                }

                //Specturm sp = new Specturm( e );
                renderPoint.IlluminanceDirect = e;

                i++;
                if (i % 50000 == 0)
                {
                    this.Log.Message(string.Format("Render {0} points of {1}", i, renderPointsStructure.RenderPoints.Count), 1);
                }
            }
        }
コード例 #2
0
        public void Calculate(RenderPointsStructure renderPointsStructure)
        {
            // Непосредственно калькулятор, который будет просчитывать точки
            var calculator = new DoubleLocalEstimationCalculator(this.RayTracer.Scene, this.RayTracer, NRays, WMin, this.Log);

            // Формируем ускоряющую структуру на основе сетки
            var giRenderPointsStructure = this.GenerateCalculatedStructure(renderPointsStructure);

            foreach (var item in giRenderPointsStructure.RenderPointsFace)
            {
                RayDebugStaticCollection.Add(new Ray(item.Vertexes[0].Position, item.Vertexes[1].Position), Color.WhiteSmoke);
                RayDebugStaticCollection.Add(new Ray(item.Vertexes[1].Position, item.Vertexes[2].Position), Color.WhiteSmoke);
                RayDebugStaticCollection.Add(new Ray(item.Vertexes[2].Position, item.Vertexes[0].Position), Color.WhiteSmoke);
            }

            //const float nPackets = 3;
            //const float wMin = 0.01f;

            // главный цикл по пакетам
            var calculationPoints = giRenderPointsStructure.RenderPointsVertexes.Select(x => (CalculationPointDLE)x).ToList();

            for (var packet = 0; packet < NPackets; packet++)
            {
                giRenderPointsStructure.RenderPointsVertexes.ForEach(x => x.Illuminance = new Spectrum());
                calculator.Calculate(calculationPoints);

                //calculator.Calculate(giRenderPointsStructure.RenderPointsVertexes);

                giRenderPointsStructure.RenderPointsVertexes.ForEach(x => x.IlluminancePacket.Add(x.Illuminance));
            }

            this.IlluminanceBugsCorrection(giRenderPointsStructure);

            foreach (var giface in giRenderPointsStructure.RenderPointsFace)
            {
                var e = new Spectrum[3];
                e[0] = giface.Vertexes[0].Illuminance;
                e[1] = giface.Vertexes[1].Illuminance;
                e[2] = giface.Vertexes[2].Illuminance;

                foreach (var point in giface.RenderPoints)
                {
                    var bc = giface.GetBarycentricCoordinates(point);
                    //var bc = giface.GetBarycentricCoordinates_Old( point );

                    var x = e[0] * ((float)bc[1]) + e[1] * ((float)bc[2]) + e[2] * ((float)bc[0]);

                    if (float.IsNaN(x.R))
                    {
                        throw new Exception();
                        //x = new Spectrum();
                    }

                    //point.IlluminanceIndirect = x;
                    point.IlluminanceIndirect = x;
                    //point.IlluminanceDirect = x;
                }
            }
        }
コード例 #3
0
        RenderPointsStructureDLE GenerateCalculatedStructure(RenderPointsStructure renderPointsStructure)
        {
            var tick   = Environment.TickCount;
            var result = new RenderPointsStructureDLE();

            foreach (var obj in this.scene.Objects)
            {
                foreach (var face in obj.Faces)
                {
                    if (face.Material.Reflectance == null)
                    {
                        continue;
                    }

                    if (!renderPointsStructure.FaceRenderPoints.ContainsKey(face))
                    {
                        continue;
                    }

                    var a = new TriangleFaceDLE(face, renderPointsStructure.FaceRenderPoints[face]);
                    GenerateRenderPointsFace(a, result);
                }
            }


            // Generate center points && set shadow points to vertexes
            foreach (var face in result.RenderPointsFace)
            {
                var center    = (face.Vertexes[0].Position + face.Vertexes[1].Position + face.Vertexes[2].Position) / 3;
                var direction = (face.Vertexes[0].Direction + face.Vertexes[1].Direction + face.Vertexes[2].Direction) / 3;
                direction.Normalize();
                var vertexCenter = new TriangleVertexDLE(face.Face, center, direction, face);
                face.Center = vertexCenter;
                result.RenderPointsVertexes.Add(vertexCenter);
            }


            if (this.Log != null)
            {
                tick = Environment.TickCount - tick;
                this.Log.Message(string.Format("GiDoubleLocalEstimation. GenerateCalculatedStructure: SubMeshes = {0}, CalcPoints = {1}, Time = {2}", result.RenderPointsFace.Count, result.RenderPointsVertexes.Count, tick));
            }
            return(result);
        }
コード例 #4
0
        public void FinalGathering(RenderPointsStructure renderPointsStructure)
        {
            // Final gathering
            this.Log.Message("Start final gathering");

            this.Log.Message("Start final gathering mirror", 1);
            foreach (var renderPoint in renderPointsStructure.RenderPoints.Where(x => x.IsPrimaryPoint && x.MirrorRenderPoint != null).ToList())
            {
                var currentRenderPoint = renderPoint;
                //var mirrorPoint = renderPoint.MirrorRenderPoint;
                while (currentRenderPoint.MirrorRenderPoint != null)
                {
                    if (!(currentRenderPoint.MirrorRenderPoint.Obj is ILight))
                    {
                        renderPoint.IlluminanceDirect   += currentRenderPoint.MirrorRenderPoint.IlluminanceDirect * currentRenderPoint.Face.Material.Mirror.Reflectance;
                        renderPoint.IlluminanceIndirect += currentRenderPoint.MirrorRenderPoint.IlluminanceIndirect * currentRenderPoint.Face.Material.Mirror.Reflectance;
                    }

                    currentRenderPoint = currentRenderPoint.MirrorRenderPoint;
                }
            }
            this.Log.Message("End final gathering mirror", 1);
            this.Log.Message("End final gathering");
        }
コード例 #5
0
 public RenderResultDeleteMe(RenderPointsStructure renderPointsStructure, int width, int height)
 {
     this.Width  = width;
     this.Height = height;
     this.RenderPointsStructure = renderPointsStructure;
 }
コード例 #6
0
        public RenderPointsStructure GenerateRenderPoints(ICamera camera, int width, int height)
        {
            var tick   = Environment.TickCount;
            var result = new RenderPointsStructure(this.Scene, width, height);

            this.Log.Message(string.Format("Start generationg render points. Estimated count {0}", width * height));

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    Ray ray = camera.GetTracingRay(x, y, width, height);

                    var intersection = this.RayTracer.Trace(ray.From, ray.Direction);
                    if (intersection == null)
                    {
                        continue;
                    }

                    // выбраковка не лицевых граней
                    var cosa = Vector.Dot(ray.Direction, intersection.Face.Normal);
                    if (cosa > 0)
                    {
                        continue;
                    }

                    var renderPoint = new RenderPoint(x, y, intersection, ray.Direction * -1f, true);
                    result.Add(renderPoint);

                    // материал зеркальный
                    var currentRenderPoint = renderPoint;
                    int iteration          = 0;
                    while (intersection.Face.Material.Mirror != null)
                    {
                        var reflectedRayDirection = ray.Direction.Reflect(intersection.Face.Normal);
                        ray = new Ray(intersection.Point, reflectedRayDirection);

                        //if ( rand.Next(100) == 50 )
                        //    RayDebugStaticCollection.Add( new Ray( intersection.Point, reflectedRayDirection ), Color.Red );

                        intersection = this.RayTracer.Trace(ray.From, ray.Direction, Constants.Epsilon);
                        if (intersection == null)
                        {
                            break;
                        }

                        var mirrorRenderPoint = new RenderPoint(x, y, intersection, ray.Direction * -1f, false);
                        result.Add(mirrorRenderPoint);
                        currentRenderPoint.MirrorRenderPoint = mirrorRenderPoint;
                        currentRenderPoint = mirrorRenderPoint;
                        iteration++;
                        if (iteration > 5)
                        {
                            break;
                        }
                    }
                }
            }

            if (this.Log != null)
            {
                tick = Environment.TickCount - tick;
                Log.Message(string.Format("GetRenderPoints: Rays = {0}, Time = {1} s", result.RenderPoints.Count, (float)tick / 1000));
            }

            return(result);
        }
コード例 #7
0
 public void RenderGlobalIllumination(RenderPointsStructure renderPointsStructure)
 {
     this.GlobalIllumination.Calculate(renderPointsStructure);
 }