Esempio n. 1
0
        private Action <TracerBuilder> ConfigureOptions(ITracingOptions options, Action <TracerBuilder> configureTracer)
        {
            return(builder =>
            {
                Sampler sampler = null;
                if (options.AlwaysSample)
                {
                    sampler = new AlwaysSampleSampler();
                }
                else if (options.NeverSample)
                {
                    sampler = new NeverSampleSampler();
                }

                builder.SetTracerOptions(TracerConfiguration);

                if (sampler != null)
                {
                    ConfiguredSampler = sampler;
                    builder.SetSampler(sampler);
                }

                configureTracer?.Invoke(builder);
            });
        }
 protected AspNetCoreTracingObserver(string observerName, ITracingOptions options, ITracing tracing, ILogger logger)
     : base(observerName, DIAGNOSTIC_NAME, logger)
 {
     Options     = options;
     Tracing     = tracing;
     Propagation = tracing.PropagationComponent.TextFormat;
     Tracer      = tracing.Tracer;
     PathMatcher = new Regex(options.IngressIgnorePattern);
 }
 protected HttpClientTracingObserver(string observerName, string diagnosticName, ITracingOptions options, ITracing tracing, ILogger logger)
     : base(observerName, diagnosticName, logger)
 {
     Options     = options;
     Tracing     = tracing;
     TextFormat  = tracing.TextFormat;
     Tracer      = tracing.Tracer;
     PathMatcher = new Regex(options.EgressIgnorePattern);
 }
        private Vector3 GetReflectionColor(
            ISurface surface,
            Vector3 position,
            Vector3 reflectionDir,
            ITracingOptions tracingOptions,
            int depth,
            int sampleIndex)
        {
            var ray = new Ray(position + reflectionDir * 0.001f, reflectionDir);

            return(surface.Reflect(position) * GetColorVectorForRay(ray, tracingOptions, depth + 1, sampleIndex));
        }
Esempio n. 5
0
        public OpenTelemetryTracing(ITracingOptions options, Action <TracerBuilder> configureTracer = null)
        {
            var maxAttributes = options.MaxNumberOfAttributes > 0 ? options.MaxNumberOfAttributes : DefaultMaxAttributes;
            var maxEvents     = options.MaxNumberOfMessageEvents > 0 ? options.MaxNumberOfMessageEvents : DefaultMaxEvents;
            var maxLinks      = options.MaxNumberOfLinks > 0 ? options.MaxNumberOfLinks : DefaultMaxLinks;

            TracerConfiguration = new TracerConfiguration(maxAttributes, maxEvents, maxLinks);

            var factory = TracerFactory.Create(ConfigureOptions(options, configureTracer));

            Tracer = factory.GetTracer(options.Name);
        }
        protected Color CastRay(Ray ray, ITracingOptions tracingOptions)
        {
            Vector3 color = Vector3.Zero;

            for (int i = 0; i < tracingOptions.SampleCount; i++)
            {
                var c = GetColorVectorForRay(ray, tracingOptions, 0, i);
                c      = Vector3.Clamp(c, Vector3.Zero, Vector3.One);
                color += c;
            }
            color /= tracingOptions.SampleCount;
            return(new Color(color));
        }
Esempio n. 7
0
        public SceneRenderer(
            Game game,
            RayMarching rayMarching,
            ITracingOptions tracingOptions
            ) : base(game)
        {
            _tracingOptions = tracingOptions;
            _rayMarching    = rayMarching;

            _spriteBatch = new SpriteBatch(game.GraphicsDevice);
            _pixel       = new Texture2D(game.GraphicsDevice, 1, 1);
            _pixel.SetData(new[] { Color.White });
        }
        private Vector3 CalculateNaturalColor(
            Vector3 position,
            Vector3 intersectionNormal,
            ITracingOptions tracingOptions,
            ISurface surface,
            int sampleIndex)
        {
            // use Phong shading model to determine color
            // https://en.wikipedia.org/wiki/Blinn%E2%80%93Phong_shading_model

            // use minimal ambient
            var color = new Vector3(0.2f);

            foreach (var light in tracingOptions.Scene.Lights)
            {
                var offset = Vector3.Zero;
                if (sampleIndex > 0)
                {
                    const float offsetFactor = 0.1f;
                    offset = new Vector3(-offsetFactor + offsetFactor * 2 * (float)_random.NextDouble(),
                                         -offsetFactor + offsetFactor * 2 * (float)_random.NextDouble(),
                                         -offsetFactor + offsetFactor * 2 * (float)_random.NextDouble());
                }
                var lightDistance = light.Position + offset - position;
                var lightDir      = Vector3.Normalize(lightDistance);

                // check if light source is reachable from current position or not
                // must move away from object slightly, otherwise collision will be current point
                var ray = new Ray(position + lightDir * 0.001f, lightDir);
                var ix  = CheckIntersection(ray, tracingOptions.Scene);
                if (ix.HasValue)
                {
                    var intersection = ix.Value;
                    var isInShadow   = intersection.Distance * intersection.Distance < lightDistance.LengthSquared();
                    if (isInShadow)
                    {
                        continue;
                    }
                }

                var illumination = MathHelper.Clamp(Vector3.Dot(lightDir, intersectionNormal), 0, float.MaxValue);
                var c            = illumination * light.Color.ToVector3() * light.Intensity;
                color += c * surface.Diffuse(position);

                var specular = MathHelper.Clamp(Vector3.Dot(lightDir, intersectionNormal), 0, float.MaxValue);
                color += specular * c * (float)Math.Pow(specular, surface.Shininess) * surface.Specular(position);
            }
            return(color / tracingOptions.Scene.Lights.Count);
        }
Esempio n. 9
0
        public void Draw(RenderTarget2D renderTarget, ITracingOptions tracingOptions, GameTime gameTime)
        {
            _shader.Begin(renderTarget);

            // compute shader requires batching in power of 2, so must input next power of 2
            // shader will auto. discard anything outside of texture range
            var x = _pow.First(x => x >= renderTarget.Width);
            var y = _pow.First(y => y >= renderTarget.Height);

            var width  = renderTarget.Width - 1;
            var height = renderTarget.Height - 1;

            // inject parameters
            _shader.SetParameter("eye", tracingOptions.Camera.Position);
            _shader.SetParameter("direction", tracingOptions.Camera.Direction);
            _shader.SetParameter("time", (float)gameTime.TotalGameTime.TotalSeconds);

            // hardcoded to chunks of 8x8 in compute shader
            _shader.Execute(x / 8, y / 8, 1);
            _shader.End();
        }
        public override void Draw(RenderTarget2D renderTarget, ITracingOptions tracingOptions, GameTime gameTime)
        {
            if (_buffer == null ||
                _buffer.Length != renderTarget.Width * renderTarget.Height)
            {
                _buffer = new Color[renderTarget.Width * renderTarget.Height];
            }

            for (int y = 0; y < renderTarget.Height; y++)
            {
                for (int x = 0; x < renderTarget.Width; x++)
                {
                    var ray = tracingOptions.Camera.GetRayForRasterPosition(x, y, renderTarget.Width - 1, renderTarget.Height - 1);
                    _buffer[x + y * renderTarget.Width] = CastRay(ray, tracingOptions);
                }
            }

            // TODO: SetData perf is "horrible"
            // compare against pixel/line drawing
            renderTarget.SetData(_buffer);
        }
        public OpenCensusTracing(ITracingOptions options, ISampler sampler = null)
        {
            this.options = options;
            var builder = TraceParams.DEFAULT.ToBuilder();

            if (sampler != null)
            {
                builder.SetSampler(sampler);
            }
            else if (options.AlwaysSample)
            {
                builder.SetSampler(Samplers.AlwaysSample);
            }
            else if (options.NeverSample)
            {
                builder.SetSampler(Samplers.NeverSample);
            }

            if (options.MaxNumberOfAnnotations > 0)
            {
                builder.SetMaxNumberOfAnnotations(options.MaxNumberOfAnnotations);
            }

            if (options.MaxNumberOfAttributes > 0)
            {
                builder.SetMaxNumberOfAttributes(options.MaxNumberOfAttributes);
            }

            if (options.MaxNumberOfLinks > 0)
            {
                builder.SetMaxNumberOfLinks(options.MaxNumberOfLinks);
            }

            if (options.MaxNumberOfMessageEvents > 0)
            {
                builder.SetMaxNumberOfMessageEvents(options.MaxNumberOfMessageEvents);
            }

            TraceConfig.UpdateActiveTraceParams(builder.Build());
        }
        public override void Draw(RenderTarget2D renderTarget, ITracingOptions tracingOptions, GameTime gameTime)
        {
            if (_buffer == null ||
                _buffer.Length != renderTarget.Width * renderTarget.Height)
            {
                _buffer = new Color[renderTarget.Width * renderTarget.Height];
            }

            var r = Parallel.For(0, renderTarget.Height, y =>
            {
                for (int x = 0; x < renderTarget.Width; x++)
                {
                    var ray = tracingOptions.Camera.GetRayForRasterPosition(x, y, renderTarget.Width - 1, renderTarget.Height - 1);
                    _buffer[x + y * renderTarget.Width] = CastRay(ray, tracingOptions);
                }
            });

            if (!r.IsCompleted)
            {
                throw new NotSupportedException("Parallel loop must always complete");
            }

            renderTarget.SetData(_buffer);
        }
        private Vector3 GetColorVectorForRay(Ray ray, ITracingOptions tracingOptions, int depth, int sampleIndex)
        {
            var ix = CheckIntersection(ray, tracingOptions.Scene);

            if (!ix.HasValue)
            {
                return(Vector3.Zero);
            }

            var intersection         = ix.Value;
            var intersectionLocation = ray.Position + ray.Direction * intersection.Distance;
            var intersectionNormal   = intersection.IntersectedObject.Normal(intersectionLocation);

            var color = CalculateNaturalColor(intersectionLocation, intersectionNormal, tracingOptions, intersection.IntersectedObject.Surface, sampleIndex);

            if (depth >= tracingOptions.ReflectionLimit)
            {
                return(color * Vector3.One / 2f);
            }
            // TODO: make feature of surface
            var reflectionDir = ray.Direction - 2 * Vector3.Dot(intersectionNormal, ray.Direction) * intersectionNormal;

            return(color + GetReflectionColor(intersection.IntersectedObject.Surface, intersectionLocation, reflectionDir, tracingOptions, depth + 1, sampleIndex));
        }
Esempio n. 14
0
        public SceneRenderer(
            Game game,
            PerformanceEvaluator performanceEvaluator,
            ITracingOptions tracingOptions,
            ICamera camera,
            IEnumerable <IRaytracer> raytracerBackends,
            Settings settings
            ) : base(game)
        {
            _performanceEvaluator      = performanceEvaluator;
            _tracingOptions            = tracingOptions;
            _raytracingBackends        = raytracerBackends.OrderBy(x => x.Name).ToArray();
            _selectedRaytracingBackend = _raytracingBackends
                                         .FirstOrDefault(x => x.GetType().Name.Equals(settings.Compute.Backend, StringComparison.OrdinalIgnoreCase)) ??
                                         throw new NotSupportedException($"Unsupported backend {settings.Compute.Backend} requested. " +
                                                                         $"  Supported backends are: {string.Join(",", _raytracingBackends.Select(x => x.Name))}");

            _camera   = camera;
            _settings = settings;

            _spriteBatch = new SpriteBatch(game.GraphicsDevice);
            _pixel       = new Texture2D(game.GraphicsDevice, 1, 1);
            _pixel.SetData(new[] { Color.White });
        }
Esempio n. 15
0
 public TracingLogProcessor(ITracingOptions options, ITracing tracing)
 {
     this.options = options;
     this.tracing = tracing;
 }
 public InboundRequestObserver(string observerName, string diagnosticName, ITracingOptions options, ITracing tracing, ILogger logger)
     : base(observerName, diagnosticName, options, tracing, logger)
 {
     this.logger = logger;
 }
Esempio n. 17
0
 public TracingLogProcessor(ITracingOptions options, ITracing tracing)
 {
     _options = options;
     _tracing = tracing;
 }
 public abstract void Draw(RenderTarget2D renderTarget, ITracingOptions tracingOptions, GameTime gameTime);
Esempio n. 19
0
 public TracingLogProcessor(ITracingOptions options)
 {
     _options = options;
 }
Esempio n. 20
0
 public AspNetCoreMvcActionObserver(ITracingOptions options, ITracing tracing, ILogger <AspNetCoreMvcActionObserver> logger = null)
     : base(OBSERVER_NAME, options, tracing, logger)
 {
 }
Esempio n. 21
0
 public HttpClientCoreObserver(ITracingOptions options, ITracing tracing, ILogger <HttpClientCoreObserver> logger = null)
     : base(OBSERVER_NAME, DIAGNOSTIC_NAME, options, tracing, logger)
 {
 }
Esempio n. 22
0
 public OutboundRequestObserver(ITracingOptions tracingOptions, ITracing tracing, ILoggerFactory loggerFactory)
     : base(tracingOptions, tracing, loggerFactory.CreateLogger <OutboundRequestObserver>())
 {
 }