Exemplo n.º 1
0
        private void Render()
        {
            int   h      = (int)(pictureBox1.Width * map.height / map.width);
            float scalex = (float)(pictureBox1.Width / map.width);
            float scaley = (float)(h / map.height);

            renderer.AddObject(map);
            renderer.AddObject(robot);
            if (route != null)
            {
                renderer.AddObject(route.GetPathShape());
            }
            if (bnt != null)
            {
                renderer.AddObject(bnt.GetPathShape());
            }


            pictureBox1.Image = renderer.Render(pictureBox1.Width, pictureBox1.Height, Color.White, scalex, scaley);

            //            var r = renderer.EmptyFrame(pictureBox1.Width, pictureBox1.Height, Color.White)
            //                .DrawMap(map)
            //                .DrawRobot(robot, map)
            //                .DrawPath(path, map);
            //            if (route != null)
            //                r = r.DrawLaseres(robot, map, (int) route.LL, (int) route.LF, (int) route.RR, (int) route.RF);
            //
            //            pictureBox1.Image = r.GetBitmap();
        }
Exemplo n.º 2
0
        private void DrawMap()
        {
            renderer.AddObject(map);
            int   h      = (int)(pictureBox1.Width * map.height / map.width);
            float scalex = (float)(pictureBox1.Width / map.width);
            float scaley = (float)(h / map.height);

            renderer.AddObject(map);
            pictureBox1.Image = renderer.Render(pictureBox1.Width, pictureBox1.Height, Color.White, scalex, scaley);
//            Renderer renderer = new Renderer();
//            pictureBox1.Image = renderer.EmptyFrame(pictureBox1.Width, pictureBox1.Height, Color.White)
//                .DrawMap(map)
//                .DrawPath(path, map)
//                .GetBitmap(); ;
        }
Exemplo n.º 3
0
        internal BoxBlurTechnique(
            ShaderProgram postVertProg, ShaderProgram blurFragProg,
            int sampleRange, float sampleScale, RenderScene scene, Logger logger = null)
        {
            if (postVertProg == null)
            {
                throw new ArgumentNullException(nameof(postVertProg));
            }
            if (blurFragProg == null)
            {
                throw new ArgumentNullException(nameof(blurFragProg));
            }
            if (scene == null)
            {
                throw new NullReferenceException(nameof(scene));
            }

            this.scene = scene;

            //Setup renderer
            renderer = new Renderer(scene, logger);
            renderer.AddSpecialization(sampleRange);
            renderer.AddSpecialization(sampleScale);

            //Add a full-screen object to the renderer
            renderObject = new AttributelessObject(scene, vertexCount: 3, new TextureInfo[0]);
            renderer.AddObject(renderObject, postVertProg, blurFragProg, debugName: "fullscreen");
        }
        internal GaussianBlurTechnique(
            ShaderProgram postVertProg, ShaderProgram blurFragProg,
            int iterations, float sampleScale, RenderScene scene, Logger logger = null)
        {
            if (postVertProg == null)
            {
                throw new ArgumentNullException(nameof(postVertProg));
            }
            if (blurFragProg == null)
            {
                throw new ArgumentNullException(nameof(blurFragProg));
            }
            if (scene == null)
            {
                throw new NullReferenceException(nameof(scene));
            }

            this.iterations = iterations;
            this.scene      = scene;

            //Create renderers (2 so we can ping-pong between two targets)
            rendererHor = new Renderer(scene, logger);
            rendererHor.AddSpecialization(true); //IsHorizontal
            rendererHor.AddSpecialization(sampleScale);

            rendererVer = new Renderer(scene, logger);
            rendererVer.AddSpecialization(false); //NOT IsHorizontal
            rendererVer.AddSpecialization(sampleScale);

            //Add a full-screen object to both renderers
            renderObject = new AttributelessObject(scene, vertexCount: 3, new TextureInfo[0]);
            rendererHor.AddObject(renderObject, postVertProg, blurFragProg, debugName: "horizontal");
            rendererVer.AddObject(renderObject, postVertProg, blurFragProg, debugName: "vertical");
        }
 internal void AddObject(
     IInternalRenderObject renderObject,
     ShaderProgram vertProg,
     ShaderProgram fragProg,
     int renderOrder  = 0,
     string debugName = null)
 {
     renderer.AddObject(renderObject, vertProg, fragProg, renderOrder, debugName: debugName);
 }
Exemplo n.º 6
0
        internal BloomTechnique(
            GBufferTechnique gbufferTechnique,
            ShaderProgram postVertProg, ShaderProgram bloomFragProg, ShaderProgram gaussBlurFragProg,
            RenderScene scene,
            Logger logger = null)
        {
            if (gbufferTechnique == null)
            {
                throw new NullReferenceException(nameof(gbufferTechnique));
            }
            if (postVertProg == null)
            {
                throw new ArgumentNullException(nameof(postVertProg));
            }
            if (bloomFragProg == null)
            {
                throw new ArgumentNullException(nameof(bloomFragProg));
            }
            if (gaussBlurFragProg == null)
            {
                throw new ArgumentNullException(nameof(gaussBlurFragProg));
            }
            if (scene == null)
            {
                throw new NullReferenceException(nameof(scene));
            }

            this.gbufferTechnique = gbufferTechnique;
            this.scene            = scene;

            //Create renderer for rendering the bloom texture
            renderer = new Renderer(scene, logger);

            //Add full-screen object for drawing the composition
            renderObject = new AttributelessObject(scene, vertexCount: 3, new TextureInfo[0]);
            renderer.AddObject(renderObject, postVertProg, bloomFragProg, debugName: "fullscreen");

            //Create a BlurTechnique for blurring the bloom texture
            blurTechnique = new GaussianBlurTechnique(
                postVertProg,
                gaussBlurFragProg,
                blurIterations,
                blurSampleScale,
                scene,
                logger);
        }
Exemplo n.º 7
0
        internal AmbientOcclusionTechnique(
            GBufferTechnique gbufferTechnique,
            ShaderProgram postVertProg, ShaderProgram aoFragProg, ShaderProgram boxBlurFragProg,
            RenderScene scene,
            Logger logger = null)
        {
            if (gbufferTechnique == null)
            {
                throw new NullReferenceException(nameof(gbufferTechnique));
            }
            if (postVertProg == null)
            {
                throw new ArgumentNullException(nameof(postVertProg));
            }
            if (aoFragProg == null)
            {
                throw new ArgumentNullException(nameof(aoFragProg));
            }
            if (boxBlurFragProg == null)
            {
                throw new ArgumentNullException(nameof(boxBlurFragProg));
            }
            if (scene == null)
            {
                throw new NullReferenceException(nameof(scene));
            }

            this.gbufferTechnique = gbufferTechnique;
            this.scene            = scene;
            this.logger           = logger;

            //Create renderer for rendering the ao texture
            renderer = new Renderer(scene, logger);
            renderer.AddSpecialization(scene.SwapchainCount);
            renderer.AddSpecialization(sampleKernelSize);
            renderer.AddSpecialization(sampleRadius);
            renderer.AddSpecialization(sampleBias);
            swapchainIndexPushDataBinding = renderer.AddPushData <int>();
            targetSizePushBinding         = renderer.AddPushData <Int2>();

            //Create random for generating the kernel and noise (using a arbitrary fixed seed)
            IRandom random = new ShiftRandom(seed: 1234);

            //Create the sample kernel
            Span <Float4> sampleKernel = stackalloc Float4[sampleKernelSize];

            GenerateSampleKernel(random, sampleKernel);
            sampleKernelBuffer = DeviceBuffer.UploadData <Float4>(
                sampleKernel, scene, BufferUsages.UniformBuffer);

            //Create the rotation noise texture
            Float4Texture rotationNoiseTexture = TextureUtils.CreateRandomFloatTexture(
                random, min: (-1f, -1f, 0f, 0f), max: (1f, 1f, 0f, 0f), size: (noiseSize, noiseSize));

            rotationNoiseSampler = new DeviceSampler(scene.LogicalDevice,
                                                     texture: DeviceTexture.UploadTexture(rotationNoiseTexture, scene),
                                                     repeat: true,
                                                     pointFilter: true);

            //Add full-screen object for drawing the composition
            renderObject = new AttributelessObject(scene, vertexCount: 3, new TextureInfo[0]);
            renderer.AddObject(renderObject, postVertProg, aoFragProg, debugName: "fullscreen");

            //Create a BlurTechnique for blurring the ao texture (to hide the ao sample pattern)
            blurTechnique = new BoxBlurTechnique(
                postVertProg,
                boxBlurFragProg,
                blurSampleRange,
                sampleScale: 1f,
                scene,
                logger);
        }
        internal DeferredTechnique(
            GBufferTechnique gbufferTechnique,
            ShadowTechnique shadowTechnique,
            BloomTechnique bloomTechnique,
            AmbientOcclusionTechnique aoTechnique,
            TextureInfo reflectionTexture,
            ShaderProgram compositionVertProg, ShaderProgram compositionFragProg,
            RenderScene scene,
            Logger logger = null)
        {
            if (gbufferTechnique == null)
            {
                throw new NullReferenceException(nameof(gbufferTechnique));
            }
            if (shadowTechnique == null)
            {
                throw new NullReferenceException(nameof(shadowTechnique));
            }
            if (bloomTechnique == null)
            {
                throw new NullReferenceException(nameof(bloomTechnique));
            }
            if (aoTechnique == null)
            {
                throw new NullReferenceException(nameof(aoTechnique));
            }
            if (reflectionTexture.Texture == null)
            {
                throw new ArgumentNullException(nameof(reflectionTexture));
            }
            if (compositionVertProg == null)
            {
                throw new ArgumentNullException(nameof(compositionVertProg));
            }
            if (compositionFragProg == null)
            {
                throw new ArgumentNullException(nameof(compositionFragProg));
            }
            if (scene == null)
            {
                throw new NullReferenceException(nameof(scene));
            }

            this.gbufferTechnique = gbufferTechnique;
            this.shadowTechnique  = shadowTechnique;
            this.bloomTechnique   = bloomTechnique;
            this.aoTechnique      = aoTechnique;
            this.scene            = scene;

            //Create renderer for rendering the composition effects
            renderer = new Renderer(scene, logger);
            renderer.AddSpecialization(scene.SwapchainCount);
            swapchainIndexPushDataBinding = renderer.AddPushData <int>();

            //Add full-screen object for drawing the composition
            renderObject = new AttributelessObject(scene,
                                                   vertexCount: 3, new [] { reflectionTexture });
            renderer.AddObject(
                renderObject,
                compositionVertProg,
                compositionFragProg,
                debugName: "fullscreen");
        }