Ejemplo n.º 1
0
 public override void InitPath(PathBuffer buffer) {
     base.InitPath(buffer);
     this.scene = buffer.Scene;
     this.Radiance = new RgbSpectrum(0f);
     this.Throughput = new RgbSpectrum(1f);
     this.PathState = PathTracerPathState.EyeVertex;
     this.Sample = buffer.Sampler.GetSample();
     this.PathRay = new RayData ( scene.Camera.GetRay(Sample.imageX, Sample.imageY));
     this.RayIndex = -1;
     this.pathWeight = 1.0f;
     this.tracedShadowRayCount = 0;
     this.depth = 0;
     this.specularBounce = true;
 }
Ejemplo n.º 2
0
        public NativeRenderThread(int index, CpuBvhIntersectionEngine device, RayEngineScene scn, bool lowLatency, ImageFilm pixelDevice, ISampler sampler, SurfaceSampler ss)
            : base(index, scn) {
            intersectionDevice = device;

            // Allocate buffers

            // Sample buffer
            var sampleBufferSize = lowLatency ? (SAMPLE_BUFFER_SIZE / 4) : SAMPLE_BUFFER_SIZE;
            sampleBuffer = new SampleBuffer(sampleBufferSize);

            // Ray buffer (small buffers work well with CPU)
            var rayBufferSize = 1024;

            this.sampler = sampler;


            _pathRayProcessor = new PathBuffer(scn.MaxPaths, scn, pixelDevice, new SamplingContext() { PrimarySpaceSampler = sampler, SurfaceSampler = ss, LightSampler = new LightSampler(scn)});
            this.pixelDevice = pixelDevice;

            rayBuffer = new RayBuffer(rayBufferSize);

            renderThread = null;
        }
Ejemplo n.º 3
0
 public virtual void InitPath(IPathProcessor buffer)
 {
     this.Buffer = (PathBuffer) buffer;
 }
Ejemplo n.º 4
0
        private void UpdatePath(TickItem sender, GameWindow game, FrameEventArgs e)
        {
            _selectedCountry = _countries.RandomSubset(2).ToArray();

            var pathingCities = new[] {
                _selectedCountry?[0].Cities.RandomSubset(1).First(),
                _selectedCountry?[1].Cities.RandomSubset(1).First()
            };

            var connected =
                _selectedCountry[0].BorderCountries.Any(
                    o => o == _selectedCountry[1] || o.BorderCountries.Contains(_selectedCountry[1]));

            if (connected)
            {
                var middleC = _selectedCountry[0].BorderCountries.Contains(_selectedCountry[1])
                                        ? null
                                        : _selectedCountry[0].BorderCountries.FirstOrDefault(
                    o => o.BorderCountries.Contains(_selectedCountry[1]));

                if (_selectedCountry == null)
                {
                    return;
                }

                if (middleC != null)
                {
                    var path = new[] {
                        AStar.FindPath(pathingCities[0], _selectedCountry[0].Outbound[middleC], Distance, Distance),
                        AStar.FindPath(middleC.Outbound[_selectedCountry[0]], middleC.Outbound[_selectedCountry[1]],
                                       Distance, Distance),
                        AStar.FindPath(_selectedCountry[1].Outbound[middleC], pathingCities[1], Distance, Distance)
                    };

                    path[2].FirstPath.PreviousSteps = path[1];
                    path[1].FirstPath.PreviousSteps = path[0];
                    pathingCities = path[2].ToArray();
                    _path         = path[2];
                }
                else
                {
                    var path = new[] {
                        AStar.FindPath(pathingCities[0], _selectedCountry[0].Outbound[_selectedCountry[1]], Distance,
                                       Distance),
                        AStar.FindPath(_selectedCountry[1].Outbound[_selectedCountry[0]], pathingCities[1], Distance,
                                       Distance)
                    };

                    path[1].FirstPath.PreviousSteps = path[0];
                    pathingCities = path[1].ToArray();
                    _path         = path[1];
                }
            }
            else
            {
                var path = new[] {
                    AStar.FindPath(pathingCities[0], _selectedCountry[0].Cities[0], Distance, Distance),
                    new Path <City>(_selectedCountry[1].Cities[0])
                    {
                        PreviousSteps = new Path <City>(_selectedCountry[0].Cities[0])
                    },
                    AStar.FindPath(_selectedCountry[1].Cities[0], pathingCities[1], Distance, Distance)
                };
                path[2].FirstPath.PreviousSteps = path[1];
                path[1].FirstPath.PreviousSteps = path[0];
                pathingCities = path[2].ToArray();
                _path         = path[2];
            }

            _paths = new BufferElement[(pathingCities.Length - 1) * 2];

            for (var i = 0; i < pathingCities.Length - 1; i++)
            {
                var d = (float)((pathingCities[i].Longitude / _scale) + _add.X);
                if (d < -1)
                {
                    d += 2;
                }
                var d2 = (float)((pathingCities[i + 1].Longitude / _scale) + _add.X);
                if (d2 < -1)
                {
                    d2 += 2;
                }
                var color = pathingCities[i].Country == pathingCities[i + 1].Country ||
                            pathingCities[i].Country.BorderCountries.Contains(pathingCities[i + 1].Country)
                                        ? new Vector4(1f, 0f, 0f, 1f)
                                        : new Vector4(0f, 0f, 1f, 1f);

                _paths[i * 2] = new BufferElement(new Vector2(d, (float)((pathingCities[i].Latitude / _scale) + _add.Y)),
                                                  color);
                _paths[(i * 2) + 1] =
                    new BufferElement(new Vector2(d2, (float)((pathingCities[i + 1].Latitude / _scale) + _add.Y)), color);
            }

            PathBuffer?.Dispose();
            PathBuffer = new VertexBuffer <BufferElement>(_paths, () =>
            {
                GL.EnableClientState(ArrayCap.VertexArray);
                GL.EnableClientState(ArrayCap.ColorArray);
                GL.VertexPointer(2, VertexPointerType.Float, BufferElement.SizeInBytes, new IntPtr(0));
                GL.ColorPointer(4, ColorPointerType.Float, BufferElement.SizeInBytes, new IntPtr(Vector2.SizeInBytes));
            });

            _pathText.Text = _path.ToString();
        }