public void Resize(int width, int height)
 {
     fbo = new FBOwithDepth(Texture2dGL.Create(width, height));
     fbo.Attach(Texture2dGL.Create(width, height));
     fbo.Attach(Texture2dGL.Create(width, height));
     fbo.Texture.WrapFunction = TextureWrapFunction.MirroredRepeat;
 }
 public void UpdateResolution(int width, int height)
 {
     ((FBO)PassOneSurface)?.Dispose();
     PassOneSurface = new FBO(Texture2dGL.Create(width, height, FboTexComponentCount, FboTexFloat));
     ((FBO)PassTwoSurface)?.Dispose();
     PassTwoSurface = new FBO(Texture2dGL.Create(width, height, FboTexComponentCount, FboTexFloat));
 }
Example #3
0
 public void UpdateResolution(int width, int height)
 {
     ((FBO)_outputSurface)?.Dispose();
     _outputSurface = new FBOwithDepth(Texture2dGL.Create(width, height));
     _outputSurface.Attach(Texture2dGL.Create(width, height, 3, true));
     _outputSurface.Attach(Texture2dGL.Create(width, height, 1, true));
     _outputSurface.Attach(Texture2dGL.Create(width, height, 3, true));
 }
Example #4
0
        public void UpdateResolution(int width, int height)
        {
            _ssao.UpdateResolution(width, height);
            _blur.UpdateResolution(width, height);

            ((FBO)_outputSurface)?.Dispose();
            _outputSurface = new FBO(Texture2dGL.Create(width, height));
        }
        public void UpdateResolution(int width, int height)
        {
            ((FBO)_outputSurface)?.Dispose();
            _outputSurface = new FBO(Texture2dGL.Create(width, height, _fboTexComponentCount, _fboTexFloat));

            _postProcessShader.Activate();
            _postProcessShader.Uniform("iResolution", new Vector2(width, height));
            _postProcessShader.Deactivate();
        }
Example #6
0
        public void UpdateResolution(int width, int height)
        {
            ((FBO)_outputSurface)?.Dispose();
            _outputSurface = new FBO(Texture2dGL.Create(width, height));

            _sphereCutProgram.Activate();
            _sphereCutProgram.Uniform("iResolution", new Vector2(width, height));
            _sphereCutProgram.Deactivate();
        }
Example #7
0
        public void UpdateResolution(int width, int height)
        {
            ((FBO)_depthSurface)?.Dispose();
            _depthSurface = new FBOwithDepth(Texture2dGL.Create(width * 4, height * 4, 1, true));
            ((FBO)_outputSurface)?.Dispose();
            _outputSurface = new FBOwithDepth(Texture2dGL.Create(width, height, 1));

            _depthShader.Uniform("iResolution", new Vector2(width, height));
            _shadowShader.Uniform("iResolution", new Vector2(width, height));
        }
        public Terrain(IContentLoader contentLoader, string heightMapPath, float scale, float sizeX, float sizeY)
        {
            this.scale = scale;
            this.sizeX = sizeX;
            this.sizeY = sizeY;
            Texture2dGL htext = contentLoader.Load <Texture2dGL>(heightMapPath);

            heightMap = htext.SaveToBitmap();
            CalculatePixelSizes();
        }
Example #9
0
        public Visual(IRenderState renderState, IContentLoader contentLoader)
        {
            fbo = new FBO(Texture2dGL.Create(70, 70));
            fbo.Texture.Filter = TextureFilterMode.Nearest;
            copyToFrameBuffer  = new PostProcessing(contentLoader.LoadPixelShader("copy.frag"));

            renderState.Set(BlendStates.AlphaBlend);
            renderState.Set(new LineSmoothing(true));
            renderState.Set(new LineWidth(5f));
            GL.Enable(EnableCap.PointSmooth);
        }
Example #10
0
 private void SetUpBlocksAndTextures(int amountBlocksX, int amountBlocksY, int resX, int resY)
 {
     this.amountBlocksX = amountBlocksX;
     this.amountBlocksY = amountBlocksY;
     this.blockSizeX    = resX / amountBlocksX;
     this.blockSizeY    = resY / amountBlocksY;
     FBO1 = new FBO(Texture2dGL.Create(resX, resY, 4, true));
     FBO1.Texture.WrapFunction = TextureWrapFunction.MirroredRepeat;
     FBO2 = new FBO(Texture2dGL.Create(resX, resY, 4, true));
     FBO2.Texture.WrapFunction = TextureWrapFunction.MirroredRepeat;
 }
Example #11
0
        public Water(IContentLoader contentLoader)
        {
            waterMapShader = contentLoader.Load <IShaderProgram>("WaterMap.*");
            mapFBO         = new FBO(Texture2dGL.Create(256, 256, 4, true));
            mapFBO.Attach(Texture2dGL.Create(256, 256, 4, true));
            mapFBO.Textures[0].WrapFunction = TextureWrapFunction.MirroredRepeat;
            waveLayers = GetWaveLayer();
            List <Wave> waveList = GetWaves();

            numberOfWaves = waveList.Count;
            waveBuffer.Set(waveList.ToArray(), BufferUsageHint.StaticCopy);
        }
Example #12
0
        public void UpdateResolution(int width, int height)
        {
            ((FBO)_outputSurface)?.Dispose();
            _outputSurface = new FBO(Texture2dGL.Create(width, height));
            for (int i = 0; i < _bloom.Length; i++)
            {
                _bloom[i].UpdateResolution(width, height);
            }

            _environmentMapProgram.Activate();
            _environmentMapProgram.Uniform("iResolution", new Vector2(width, height));
            _environmentMapProgram.Deactivate();
        }
Example #13
0
 public void Resize(int width, int height)
 {
     _width                       = width;
     _height                      = height;
     _aspect                      = (float)width / height;
     _renderToTexture[0]          = new FBO(Texture2dGL.Create(width, height));
     _renderToTexture[1]          = new FBO(Texture2dGL.Create(width, height));
     _renderToTexture[2]          = new FBO(Texture2dGL.Create(width, height));
     _renderToTexture[3]          = new FBO(Texture2dGL.Create(width / 2, height / 2));
     _renderToTexture[4]          = new FBO(Texture2dGL.Create(width, height));
     _renderToTextureWithDepth[0] = new FBOwithDepth(Texture2dGL.Create(width, height));
     _renderToTextureWithDepth[1] = new FBOwithDepth(Texture2dGL.Create(width / 2, height / 2, 1, true));
 }
Example #14
0
        public PlayerTrail()
        {
            var window = Framework.Game.Instance.Window;

            fbo = new FBO(Texture2dGL.Create(window.Width, window.Height));
            fbo.Texture.WrapFunction = TextureWrapFunction.MirroredRepeat;
            try {
                shader = ShaderLoader.FromStrings(
                    DefaultShader.VertexShaderScreenQuad,
                    DefaultShader.FragmentShaderCopy);
            } catch (ShaderException e) {
                Console.WriteLine(e.ShaderLog);
            }
        }
Example #15
0
        public Rasterizer(IContentLoader contentLoader, int resolutionX, int resolutionY, Action drawHandler)
        {
            if (drawHandler is null)
            {
                throw new ArgumentException("Draw handler must not equal null!");
            }

            this.drawHandler  = drawHandler;
            copyToFrameBuffer = new PostProcessing(contentLoader.LoadPixelShader("copy.frag"));
            var texRenderSurface = Texture2dGL.Create(resolutionX, resolutionY);

            texRenderSurface.Filter = TextureFilterMode.Nearest;
            fbo = new FBO(texRenderSurface);
        }
Example #16
0
        public void Resize(int width, int height)
        {
            var texNormalMaterial = Texture2dGL.Create(width, height, 4, true);
            var texPosition       = Texture2dGL.Create(width, height, 4, true);

            mrtSurface = new FBOwithDepth(texNormalMaterial);
            mrtSurface.Attach(texPosition);
            var bindings = new List <TextureBinding>()
            {
                new TextureBinding(nameof(texNormalMaterial), texNormalMaterial),
                new TextureBinding(nameof(texPosition), texPosition),
            };

            lightsVisual = new MeshVisual(lightsVisual.Drawable, lightsVisual.ShaderProgram, bindings);
        }
Example #17
0
        private static ITexture CreaterCheckerTex()
        {
            var black = Color4.Black;
            var white = Color4.White;
            var data  = new Color4[2, 2];

            data[0, 0] = black;
            data[0, 1] = white;
            data[1, 0] = white;
            data[1, 1] = black;
            var tex = new Texture2dGL();

            tex.LoadPixels(data, 4, true);
            tex.Filter = TextureFilterMode.Nearest;
            return(tex);
        }
Example #18
0
        public EnvironmentMap(int size, IContentLoader contentLoader, Dictionary <Enums.EntityType, DefaultMesh> meshes)
        {
            _bloom = new[] {
                new Bloom(contentLoader),
                new Bloom(contentLoader),
                new Bloom(contentLoader),
                new Bloom(contentLoader),
                new Bloom(contentLoader),
                new Bloom(contentLoader)
            };

            _positions = new[]
            {
                new Position(Vector3.Zero, -90, 180), //right
                new Position(Vector3.Zero, 90, 180),  //left
                new Position(Vector3.Zero, 0, -90),   //up
                new Position(Vector3.Zero, 0, 90),    //down
                new Position(Vector3.Zero, 0, 180),   //back
                new Position(Vector3.Zero, 180, 180)  //front
            };

            for (int i = 0; i < 6; i++)
            {
                _cameras[i]     = new Camera <Position, Perspective>(_positions[i], new Perspective(farClip: 500f));
                _mapSurfaces[i] = new FBOwithDepth(Texture2dGL.Create(size, size));
            }

            _cubeFbo = new CubeMapFBO(size);

            _deferred = new Deferred(contentLoader, meshes);
            _deferred.UpdateResolution(size, size);
            _shadowMapping = new DirectionalShadowMapping(contentLoader, meshes);
            _shadowMapping.UpdateResolution(size, size);
            _lighting = new Lighting(contentLoader);
            _lighting.UpdateResolution(size, size);
            _skybox = new Skybox(contentLoader, 245, "blue");
            _skybox.UpdateResolution(size, size);
            _add = new Add(contentLoader);
            _add.UpdateResolution(size, size);

            _environmentMapProgram = contentLoader.Load <IShaderProgram>("environmentMap.*");

            foreach (var meshContainer in meshes)
            {
                _geometries.Add(meshContainer.Key, VAOLoader.FromMesh(meshContainer.Value, _environmentMapProgram));
            }
        }
Example #19
0
        public void UpdateResolution(int width, int height)
        {
            ((FBO)_deferredSurface)?.Dispose();
            _deferredSurface = new FBOwithDepth(Texture2dGL.Create(width, height));
            _deferredSurface.Attach(Texture2dGL.Create(width, height, 3, true));
            _deferredSurface.Attach(Texture2dGL.Create(width, height, 1, true));
            _deferredSurface.Attach(Texture2dGL.Create(width, height, 3, true));
            _deferredSurface.Attach(Texture2dGL.Create(width, height, 4, true));

            _projectilesGenerationNvidia.UpdateResolution(width, height);
            _projectilesGenerationRadeon.UpdateResolution(width, height);
            _addProjectilesNvidia.UpdateResolution(width, height);
            _addProjectilesRadeon.UpdateResolution(width, height);

            _tesselation.UpdateResolution(width, height);
            _addTesselation.UpdateResolution(width, height);
        }
        public ITexture2D GetIBLTexture(string path)
        {
            FreeImageAPI.FREE_IMAGE_FORMAT type   = FreeImageAPI.FreeImage.GetFileType(path, 0);
            FreeImageAPI.FIBITMAP          bitmap = FreeImageAPI.FreeImage.Load(type, path, FreeImageAPI.FREE_IMAGE_LOAD_FLAGS.DEFAULT);
            //FreeImageAPI.FIBITMAP convert = FreeImageAPI.FreeImage.ToneMapping(bitmap, FreeImageAPI.FREE_IMAGE_TMO.FITMO_DRAGO03, 0, 0);
            FreeImageAPI.FIBITMAP convert = FreeImageAPI.FreeImage.ToneMapping(bitmap, FreeImageAPI.FREE_IMAGE_TMO.FITMO_REINHARD05, 0, 0);

            if (bitmap.IsNull)
            {
                return(null);
            }
            uint width     = FreeImageAPI.FreeImage.GetWidth(convert);
            uint height    = FreeImageAPI.FreeImage.GetHeight(convert);
            int  channelNo = 3;

            byte[] imgData = new byte[width * height * channelNo];
            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    int idx = i * (int)width + j;
                    FreeImageAPI.RGBQUAD color = new FreeImageAPI.RGBQUAD();
                    int byteIdx = idx * channelNo;
                    byteIdx -= 1;
                    bool  pSuccess = FreeImageAPI.FreeImage.GetPixelColor(convert, (uint)j, (uint)i, out color);
                    Color nColor   = color.Color;

                    imgData[byteIdx + 1] = color.rgbRed;
                    imgData[byteIdx + 2] = color.rgbGreen;
                    imgData[byteIdx + 3] = color.rgbBlue;

                    if (!pSuccess)
                    {
                        return(null);
                    }
                }
            }
            Texture2dGL text = Texture2dGL.Create((int)width, (int)height);
            IntPtr      ptr  = Marshal.UnsafeAddrOfPinnedArrayElement(imgData, 0);

            text.LoadPixels(ptr, (int)width, (int)height, OpenTK.Graphics.OpenGL4.PixelInternalFormat.Rgb8, OpenTK.Graphics.OpenGL4.PixelFormat.Rgb, OpenTK.Graphics.OpenGL4.PixelType.UnsignedByte);
            return(text);
        }
 public PostProcessingVisual(int width, int height, IContentLoader contentLoader)
 {
     renderToTexture = new FBO(Texture2dGL.Create(width, height));
     renderToTexture.Texture.WrapFunction = TextureWrapFunction.MirroredRepeat;
     try
     {
         shaderProgram = contentLoader.LoadPixelShader("Grayscale");
         shaderProgram = contentLoader.LoadPixelShader("Sepia");
         shaderProgram = contentLoader.LoadPixelShader("Vignetting");
         shaderProgram = contentLoader.LoadPixelShader("ChromaticAberration");
         shaderProgram = contentLoader.LoadPixelShader("convolution");
         shaderProgram = contentLoader.LoadPixelShader("EdgeDetect");
         shaderProgram = contentLoader.LoadPixelShader("Ripple");
         shaderProgram = contentLoader.LoadPixelShader("Swirl");
     }
     catch (ShaderException e)
     {
         Console.WriteLine(e.Message);
         Console.ReadLine();
     }
 }
Example #22
0
        private ITexture getTextureFromResource(Bitmap bitmap)
        {
            var texture = new Texture2dGL()
            {
                Filter = TextureFilterMode.Mipmap
            };

            texture.Activate();
            //todo: 16bit channels
            using (Bitmap bmp = new Bitmap(bitmap))
            {
                bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
                var bmpData          = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), SysDraw.ImageLockMode.ReadOnly, bmp.PixelFormat);
                var internalFormat   = SelectInternalPixelFormat(bmp.PixelFormat);
                var inputPixelFormat = SelectPixelFormat(bmp.PixelFormat);
                texture.LoadPixels(bmpData.Scan0, bmpData.Width, bmpData.Height, internalFormat, inputPixelFormat, PixelType.UnsignedByte);
                bmp.UnlockBits(bmpData);
            }
            texture.Deactivate();

            return(texture);
        }
Example #23
0
        public void Resize(int width, int height)
        {
            mainFBO = new FBOwithDepth(Texture2dGL.Create(width, height, 4, true));
            mainFBO.Attach(Texture2dGL.Create(width, height, 4, true));
            mainFBO.Attach(Texture2dGL.Create(width, height, 4, true));
            mainFBO.Attach(Texture2dGL.Create(width, height, 4, true));
            mainFBO.Attach(Texture2dGL.Create(width, height, 4, true));
            foreach (ITexture2D text in mainFBO.Textures)
            {
                text.WrapFunction = TextureWrapFunction.MirroredRepeat;
            }
            pointLightFBO = new FBOwithDepth(Texture2dGL.Create(width, height, 4, true));
            pointLightFBO.Texture.WrapFunction = TextureWrapFunction.MirroredRepeat;

            lightViewFBO = new FBOwithDepth(Texture2dGL.Create(height, width, 4, true));
            lightViewFBO.Texture.WrapFunction = TextureWrapFunction.Repeat;

            shadowMapFBO = new FBOwithDepth(Texture2dGL.Create(width, height, 4, true));
            shadowMapFBO.Texture.WrapFunction = TextureWrapFunction.Repeat;

            finalPassFBO = new FBOwithDepth(Texture2dGL.Create(width, height, 4, true));

            satFilter = new SATGpuFilter(contentLoader, renderState, 32, 32, width, height, 4, 4);
        }
Example #24
0
 public void Resize(int width, int height)
 {
     renderToTexture = new FBOwithDepth(Texture2dGL.Create(width, height));
     renderToTexture.Texture.WrapFunction = TextureWrapFunction.Repeat;
 }
Example #25
0
 public void UpdateResolution(int width, int height)
 {
     ((FBO)_outputSurface)?.Dispose();
     _outputSurface = new FBO(Texture2dGL.Create(width, height, _fboTexComponentCount, _fboTexFloat));
 }