예제 #1
0
 public Texture2D Load(AssetLoaderContext context, string assetName)
 {
     using (var stream = context.Open(assetName))
     {
         return(Texture2DExtensions.FromStream(stream, true));
     }
 }
예제 #2
0
파일: Game1.cs 프로젝트: mkbiltek2019/refer
        protected override void OnActivated(object sender, EventArgs args)
        {
            // Recover from tombstoning
            bool newlyCreated = false;

            diskTexture = Texture2DExtensions.LoadFromPhoneServiceState(this.GraphicsDevice,
                                                                        "disk");
            // Or create the Texture2D
            if (diskTexture == null)
            {
                Rectangle clientBounds     = this.GraphicsDevice.Viewport.Bounds;
                int       textureDimension = Math.Min(clientBounds.Width, clientBounds.Height);
                diskTexture = new Texture2D(this.GraphicsDevice, textureDimension,
                                            textureDimension);
                newlyCreated = true;
            }

            pixels        = new uint[diskTexture.Width * diskTexture.Height];
            radius        = diskTexture.Width / 2;
            textureCenter = new Vector2(radius, radius);

            if (newlyCreated)
            {
                ClearPixelArray();
            }
            else
            {
                diskTexture.GetData <uint>(pixels);
            }

            base.OnActivated(sender, args);
        }
예제 #3
0
 public Texture2D Load(AssetLoaderContext context, string assetName)
 {
     using (var stream = context.Open(assetName))
     {
         return(Texture2DExtensions.FromStream(context.GraphicsDevice, stream, context.Settings.PremultiplyAlphaForTextures));
     }
 }
예제 #4
0
 public Frame(int width, int height, TextureFormat format)
 {
     Width  = width;
     Height = height;
     Format = format;
     Depth  = Texture2DExtensions.GetTextureFormatDepth(Format);
     Data   = new byte[Width * Height * Depth];
 }
예제 #5
0
        protected override void OnLoad()
        {
            Span <VertexColorTexture> quadsVertex = stackalloc VertexColorTexture[]
            {
                new VertexColorTexture(new Vector3(-0.5f, -0.5f, 0), Color4b.White, new Vector2(0, 1)),
                new VertexColorTexture(new Vector3(-0.5f, 0.5f, 0), Color4b.White, new Vector2(0, 0)),
                new VertexColorTexture(new Vector3(0.5f, -0.5f, 0), Color4b.White, new Vector2(1, 1)),
                new VertexColorTexture(new Vector3(0.5f, 0.5f, 0), Color4b.White, new Vector2(1, 0)),
            };

            quadBuffer = new VertexBuffer <VertexColorTexture>(graphicsDevice, quadsVertex, BufferUsageARB.StaticDraw);

            Span <VertexColorTexture> trianglesVertex = stackalloc VertexColorTexture[]
            {
                new VertexColorTexture(new Vector3(-0.6f, -0.4f, 0), Color4b.White, new Vector2(0.02f, 0.35f)),
                new VertexColorTexture(new Vector3(-0.4f, -0.3f, 0), Color4b.White, new Vector2(0, 0.6f)),
                new VertexColorTexture(new Vector3(-0.6f, -0.2f, 0), Color4b.White, new Vector2(0.2f, 0.35f)),

                new VertexColorTexture(new Vector3(-0.6f, -0.1f, 0), Color4b.White, new Vector2(0.3f, 0.5f)),
                new VertexColorTexture(new Vector3(-0.4f, 0.0f, 0), Color4b.White, new Vector2(0.4f, 1)),
                new VertexColorTexture(new Vector3(-0.6f, 0.1f, 0), Color4b.White, new Vector2(0.6f, 0.55f)),

                new VertexColorTexture(new Vector3(-0.6f, 0.2f, 0), Color4b.White, new Vector2(0.82f, 0.2f)),
                new VertexColorTexture(new Vector3(-0.4f, 0.3f, 0), Color4b.White, new Vector2(0.98f, 0.09f)),
                new VertexColorTexture(new Vector3(-0.6f, 0.4f, 0), Color4b.White, new Vector2(0.89f, 0.26f)),

                new VertexColorTexture(new Vector3(0.6f, -0.4f, 0), Color4b.Lime, new Vector2(0.02f, 0.35f)),
                new VertexColorTexture(new Vector3(0.4f, -0.3f, 0), Color4b.Lime, new Vector2(0, 0.6f)),
                new VertexColorTexture(new Vector3(0.6f, -0.2f, 0), Color4b.Lime, new Vector2(0.2f, 0.35f)),

                new VertexColorTexture(new Vector3(0.6f, -0.1f, 0), Color4b.Red, new Vector2(0.3f, 0.5f)),
                new VertexColorTexture(new Vector3(0.4f, 0.0f, 0), Color4b.Lime, new Vector2(0.4f, 1)),
                new VertexColorTexture(new Vector3(0.6f, 0.1f, 0), Color4b.Blue, new Vector2(0.6f, 0.55f)),

                new VertexColorTexture(new Vector3(0.6f, 0.2f, 0), Color4b.Red, new Vector2(0.82f, 0.2f)),
                new VertexColorTexture(new Vector3(0.4f, 0.3f, 0), Color4b.Red, new Vector2(0.98f, 0.09f)),
                new VertexColorTexture(new Vector3(0.6f, 0.4f, 0), Color4b.Red, new Vector2(0.89f, 0.26f)),
            };

            trianglesBuffer = new VertexBuffer <VertexColorTexture>(graphicsDevice, trianglesVertex, BufferUsageARB.StaticDraw);

            shaderProgram = SimpleShaderProgram.Create <VertexColorTexture>(graphicsDevice);

            background = Texture2DExtensions.FromFile(graphicsDevice, "texture.png");
            background.SetTextureFilters(TextureMinFilter.Linear, TextureMagFilter.Linear);
            background.SetWrapModes(TextureWrapMode.ClampToEdge, TextureWrapMode.ClampToEdge);

            satellite = Texture2DExtensions.FromFile(graphicsDevice, "satellite.png");
            satellite.SetTextureFilters(TextureMinFilter.Nearest, TextureMagFilter.Nearest);
            satellite.SetWrapModes(TextureWrapMode.ClampToEdge, TextureWrapMode.ClampToEdge);

            graphicsDevice.BlendState          = BlendState.NonPremultiplied;
            graphicsDevice.DepthTestingEnabled = false;

            stopwatch = Stopwatch.StartNew();
        }
예제 #6
0
        public int GetLength()
        {
            int length = 0;

            length += sizeof(int);                            //Rows
            length += sizeof(int);                            //Columns
            length += Texture2DExtensions.GetLength(Texture); //Texture

            return(length);
        }
예제 #7
0
파일: Game1.cs 프로젝트: mkbiltek2019/refer
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            viewport = this.GraphicsDevice.Viewport;
            ball     = Texture2DExtensions.CreateBall(this.GraphicsDevice,
                                                      BALL_RADIUS * BALL_SCALE);

            ballCenter   = new Vector2(ball.Width / 2, ball.Height / 2);
            ballPosition = new Vector2(viewport.Width / 2, viewport.Height / 2);
        }
예제 #8
0
파일: Game1.cs 프로젝트: mkbiltek2019/refer
        protected override void OnActivated(object sender, EventArgs args)
        {
            PhoneApplicationService appService = PhoneApplicationService.Current;

            if (appService.State.ContainsKey("xOrigin") &&
                appService.State.ContainsKey("yOrigin") &&
                appService.State.ContainsKey("resolution"))
            {
                PixelInfo.xPixelCoordAtComplexOrigin = (double)appService.State["xOrigin"];
                PixelInfo.yPixelCoordAtComplexOrigin = (double)appService.State["yOrigin"];
                PixelInfo.unitsPerPixel = (double)appService.State["resolution"];
            }
            else
            {
                // Program running from beginning
                PixelInfo.xPixelCoordAtComplexOrigin = 2 * viewport.Width / 3f;
                PixelInfo.yPixelCoordAtComplexOrigin = viewport.Height / 2;
                PixelInfo.unitsPerPixel = Math.Max(2.5 / viewport.Height,
                                                   3.0 / viewport.Width);
            }

            UpdateCoordinateText();

            // Restore bitmap from tombstoning or recreate it
            texture = Texture2DExtensions.LoadFromPhoneServiceState(this.GraphicsDevice,
                                                                    "mandelbrotBitmap");
            if (texture == null)
            {
                texture = new Texture2D(this.GraphicsDevice, viewport.Width, viewport.Height);
            }

            // Get texture information and pixels array
            PixelInfo.pixelWidth  = texture.Width;
            PixelInfo.pixelHeight = texture.Height;
            int numPixels = PixelInfo.pixelWidth * PixelInfo.pixelHeight;

            pixels = new uint[numPixels];
            texture.GetData <uint>(pixels);

            // Create and initialize PixelInfo array
            pixelInfos = new PixelInfo[numPixels];
            InitializePixelInfo(pixels);

            // Start up the calculation thread
            Thread thread = new Thread(PixelSetterThread);

            thread.Start();

            base.OnActivated(sender, args);
        }
예제 #9
0
        protected override void OnLoad()
        {
            shaderProgram = SimpleShaderProgram.Create <VertexColorTexture>(graphicsDevice, 0, 0, true);

            particleTexture = Texture2DExtensions.FromFile(graphicsDevice, "particles.png");
            particleTexture.SetTextureFilters(TextureMinFilter.Nearest, TextureMagFilter.Nearest);
            rectangleTexture = Texture2DExtensions.FromFile(graphicsDevice, "rectangle.png");
            ballTexture      = Texture2DExtensions.FromFile(graphicsDevice, "ball.png");
            diamondTexture   = Texture2DExtensions.FromFile(graphicsDevice, "diamond.png");

            TextureFont[] fonts = TextureFontExtensions.FromFile(graphicsDevice, "font.tglf");
            comicSansFont = fonts[0];
            arialFont     = fonts[1];

            textureBatcher = new TextureBatcher(graphicsDevice);
            textureBatcher.SetShaderProgram(shaderProgram);

            graphicsDevice.DepthState = DepthState.None;
            graphicsDevice.BlendState = BlendState.NonPremultiplied;
            graphicsDevice.ClearColor = new Vector4(0.1f, 0.65f, 0.5f, 1f);

            MaxX = Window.Size.Width;
            MaxY = Window.Size.Height;

            Particle.texture = particleTexture;
            Diamond.texture  = diamondTexture;
            Ball.texture     = ballTexture;

            particles = new LinkedList <Particle>();

            diamonds = new Diamond[40];
            for (int i = 0; i < diamonds.Length; i++)
            {
                diamonds[i] = new Diamond();
            }

            balls = new Ball[40];
            for (int i = 0; i < balls.Length; i++)
            {
                balls[i] = new Ball();
            }

            stopwatch = Stopwatch.StartNew();

            graphicsDevice.CullFaceMode       = CullFaceMode.Back;
            graphicsDevice.FaceCullingEnabled = true;
        }
예제 #10
0
파일: Game1.cs 프로젝트: mkbiltek2019/refer
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            viewport     = this.GraphicsDevice.Viewport;
            screenCenter = new Vector2(viewport.Width / 2, viewport.Height / 2);

            ball = Texture2DExtensions.CreateBall(this.GraphicsDevice,
                                                  BALL_RADIUS * BALL_SCALE);

            ballCenter   = new Vector2(ball.Width / 2, ball.Height / 2);
            ballPosition = screenCenter;

            tinyTexture = new Texture2D(this.GraphicsDevice, 1, 1);
            tinyTexture.SetData <Color>(new Color[] { Color.White });

            segoe96 = this.Content.Load <SpriteFont>("Segoe96");
        }
    public static Texture2D GenerateNormalFromHeight(this Texture2D tex, float depth = 1000.0f, bool useAlphe = true)
    {
        if (tex == null)
        {
            return(null);
        }
        Texture2D newTexture = new Texture2D(tex.width, tex.height);

        Color32[] NormalMapData = new Color32[tex.width * tex.height];
        Color[]   pixels        = tex.GetPixels();
        for (int x = 0; x < tex.width; x++)
        {
            for (int y = 0; y < tex.height; y++)
            {
                //execute if alpha should be taken into account
                if (useAlphe)
                {
                    //if alpha is 0 store no color and skip normal calculation
                    if (tex.SampleHeightValue(x, y) == 0)
                    {
                        NormalMapData[x + tex.width * y] = new Color32(0, 0, 1, 1);
                        continue;
                    }
                }

                float  dx = -tex.SampleHeightValue(x - 1, y) + tex.SampleHeightValue(x + 1, y);
                float  dy = -tex.SampleHeightValue(x, y - 1) + tex.SampleHeightValue(x, y + 1);
                float3 n  = new float3(-dx * (depth / 1000.0f), dy * (depth / 1000.0f), 0);
                n.z = 1;
                n   = math.normalize(n);

                //       NormalMapData[x + tex.width * y] = Texture2DExtensions.NormalToUV(math.normalize(n));
                NormalMapData[x + tex.width * y] = Texture2DExtensions.NormalToUV(n);
            }
        }
        //store && set data
        newTexture.SetPixels32(NormalMapData);
        newTexture.Apply(false);
        return(newTexture);
    }
예제 #12
0
        static public RenderTexture Load(string path)
        {
            Texture2D tex = Texture2DExtensions.LoadPNG(path);

            if (tex == null)
            {
                Debug.Log("Can't load " + path + " texture");
                return(null);
            }
            var changeFormatTexture = new Texture2D(tex.width, tex.width, TextureFormat.RGBAFloat, false);

            changeFormatTexture.SetPixels(tex.GetPixels());
            changeFormatTexture.Apply();

            var res = DoubleDataTexture.Create("Loaded", tex.width, RenderTextureFormat.ARGBFloat, FilterMode.Point);// was RHalf

            Graphics.CopyTexture(changeFormatTexture, 0, 0, res, 0, 0);
            GameObject.Destroy(tex);
            GameObject.Destroy(changeFormatTexture);

            return(res);
        }
예제 #13
0
        protected override void OnActivated(object sender, EventArgs args)
        {
            // Recover from tombstoning
            bool newlyCreated = false;

            canvas = Texture2DExtensions.LoadFromPhoneServiceState(this.GraphicsDevice,
                                                                   "canvas");
            if (canvas == null)
            {
                // Otherwise create new Texture2D
                canvas = new Texture2D(this.GraphicsDevice, (int)canvasSize.X,
                                       (int)canvasSize.Y);
                newlyCreated = true;
            }

            // Create pixels array
            pixels = new uint[canvas.Width * canvas.Height];
            canvas.GetData <uint>(pixels);

            if (newlyCreated)
            {
                ClearPixelArray();
            }

            // Get drawing color from State, initialize selected ColorBlock
            if (PhoneApplicationService.Current.State.ContainsKey("color"))
            {
                drawingColor = (Color)PhoneApplicationService.Current.State["color"];
            }

            foreach (ColorBlock colorBlock in colorBlocks)
            {
                colorBlock.IsSelected = colorBlock.Color == drawingColor;
            }

            base.OnActivated(sender, args);
        }
예제 #14
0
        protected override void OnLoad()
        {
            inputManager = new InputManager3D(InputContext)
            {
                CameraMoveSpeed = 2.5f
            };

            Span <VertexColor> crossLines = stackalloc VertexColor[]
            {
                new VertexColor(new Vector3(0, 0, 0), Color4b.Lime),
                new VertexColor(new Vector3(0, 1, 0), Color4b.Lime),
                new VertexColor(new Vector3(0, 0, 0), Color4b.Red),
                new VertexColor(new Vector3(1, 0, 0), Color4b.Red),
                new VertexColor(new Vector3(0, 0, 0), Color4b.Blue),
                new VertexColor(new Vector3(0, 0, 1), Color4b.Blue),
            };

            crossBuffer = new VertexBuffer <VertexColor>(graphicsDevice, crossLines, BufferUsage.StaticDraw);

            Span <VertexPosition> cube = stackalloc VertexPosition[]
            {
                new Vector3(-0.5f, -0.5f, -0.5f),
                new Vector3(-0.5f, -0.5f, 0.5f),
                new Vector3(-0.5f, 0.5f, -0.5f),
                new Vector3(-0.5f, 0.5f, 0.5f),
                new Vector3(0.5f, 0.5f, 0.5f),
                new Vector3(-0.5f, -0.5f, 0.5f),
                new Vector3(0.5f, -0.5f, 0.5f),
                new Vector3(-0.5f, -0.5f, -0.5f),
                new Vector3(0.5f, -0.5f, -0.5f),
                new Vector3(-0.5f, 0.5f, -0.5f),
                new Vector3(0.5f, 0.5f, -0.5f),
                new Vector3(0.5f, 0.5f, 0.5f),
                new Vector3(0.5f, -0.5f, -0.5f),
                new Vector3(0.5f, -0.5f, 0.5f),
            };

            cubeBuffer = new VertexBuffer <VertexPosition>(graphicsDevice, cube, BufferUsage.StaticDraw);

            skyProgram = ShaderProgram.FromFiles <VertexPosition>(graphicsDevice, "skyVs.glsl", "skyFs.glsl", "vPosition");

            VertexColor[] linesArray = CreateLines();
            linesBuffer = new VertexBuffer <VertexColor>(graphicsDevice, linesArray, BufferUsage.StaticDraw);

            linesProgram = SimpleShaderProgram.Create <VertexColor>(graphicsDevice);

            VertexNormal[] dragonModel = OBJLoader.FromFile <VertexNormal>("dragon.obj");
            dragonBuffer = new VertexBuffer <VertexNormal>(graphicsDevice, dragonModel, BufferUsage.StaticDraw);

            VertexNormal[] donutModel = OBJLoader.FromFile <VertexNormal>("donut.obj");
            donutBuffer = new VertexBuffer <VertexNormal>(graphicsDevice, donutModel, BufferUsage.StaticDraw);

            VertexNormal[] sphereModel = OBJLoader.FromFile <VertexNormal>("sphere.obj");
            sphereBuffer = new VertexBuffer <VertexNormal>(graphicsDevice, sphereModel, BufferUsage.StaticDraw);

            modelsProgram = SimpleShaderProgram.Create <VertexNormal>(graphicsDevice, 1, 1);

            lampTexture = Texture2DExtensions.FromFile(graphicsDevice, "lamp_texture.png");

            VertexNormalTexture[] lampModel = OBJLoader.FromFile <VertexNormalTexture>("lamp.obj");
            lampBuffer = new VertexBuffer <VertexNormalTexture>(graphicsDevice, lampModel, BufferUsage.StaticDraw);

            lampProgram = SimpleShaderProgram.Create <VertexNormalTexture>(graphicsDevice);

            lampProgram.Texture = lampTexture;
            lampProgram.Color   = new Vector4(3, 3, 3, 1);

            Vector3 sunlightDir = new Vector3(-1, -1.5f, -1);
            Vector3 sunColor    = new Vector3(0.6f, 0.1f, 1.0f);

            modelsProgram.DirectionalLights[0].Direction        = sunlightDir;
            modelsProgram.DirectionalLights[0].DiffuseColor     = sunColor;
            modelsProgram.DirectionalLights[0].SpecularColor    = sunColor;
            modelsProgram.PositionalLights[0].AttenuationConfig = new Vector3(0, 0.3f, 0.45f);
            modelsProgram.AmbientLightColor = new Vector3(0.1f, 0.1f, 0.3f);
            modelsProgram.SpecularPower     = 8;

            skyProgram.Uniforms["sunDirection"].SetValueVec3(Vector3.Normalize(-sunlightDir));
            skyProgram.Uniforms["sunColor"].SetValueVec3(sunColor);

            lampPosition = new Vector3(2.5f, 1, -1.7f);
            modelsProgram.PositionalLights[0].Position = lampPosition;
            lampProgram.World = Matrix4x4.CreateScale(0.015f) * Matrix4x4.CreateTranslation(lampPosition.X, lampPosition.Y - 0.85f, lampPosition.Z);

            graphicsDevice.DepthState      = DepthState.Default;
            graphicsDevice.BlendingEnabled = false;

            stopwatch = Stopwatch.StartNew();
        }
예제 #15
0
파일: Game1.cs 프로젝트: mkbiltek2019/refer
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            viewport = this.GraphicsDevice.Viewport;

            // Create texture for the walls of the maze
            tinyTexture = new Texture2D(this.GraphicsDevice, 1, 1);
            tinyTexture.SetData <Color>(new Color[] { Color.White });

            // Create ball
            ball = Texture2DExtensions.CreateBall(this.GraphicsDevice,
                                                  BALL_RADIUS * BALL_SCALE);

            ballCenter   = new Vector2(ball.Width / 2, ball.Height / 2);
            ballPosition = new Vector2((viewport.Width / mazeGrid.Width) / 2,
                                       (viewport.Height / mazeGrid.Height) / 2);

            // Initialize borders collection
            borders.Clear();

            // Create Line2D objects for walls of the maze
            int cellWidth     = viewport.Width / mazeGrid.Width;
            int cellHeight    = viewport.Height / mazeGrid.Height;
            int halfWallWidth = WALL_WIDTH / 2;

            for (int x = 0; x < mazeGrid.Width; x++)
            {
                for (int y = 0; y < mazeGrid.Height; y++)
                {
                    MazeCell mazeCell = mazeGrid.Cells[x, y];
                    Vector2  ll       = new Vector2(x * cellWidth, (y + 1) * cellHeight);
                    Vector2  ul       = new Vector2(x * cellWidth, y * cellHeight);
                    Vector2  ur       = new Vector2((x + 1) * cellWidth, y * cellHeight);
                    Vector2  lr       = new Vector2((x + 1) * cellWidth, (y + 1) * cellHeight);
                    Vector2  right    = halfWallWidth * Vector2.UnitX;
                    Vector2  left     = -right;
                    Vector2  down     = halfWallWidth * Vector2.UnitY;
                    Vector2  up       = -down;

                    if (mazeCell.HasLeft)
                    {
                        borders.Add(new Line2D(ll + down, ll + down + right));
                        borders.Add(new Line2D(ll + down + right, ul + up + right));
                        borders.Add(new Line2D(ul + up + right, ul + up));
                    }
                    if (mazeCell.HasTop)
                    {
                        borders.Add(new Line2D(ul + left, ul + left + down));
                        borders.Add(new Line2D(ul + left + down, ur + right + down));
                        borders.Add(new Line2D(ur + right + down, ur + right));
                    }
                    if (mazeCell.HasRight)
                    {
                        borders.Add(new Line2D(ur + up, ur + up + left));
                        borders.Add(new Line2D(ur + up + left, lr + down + left));
                        borders.Add(new Line2D(lr + down + left, lr + down));
                    }
                    if (mazeCell.HasBottom)
                    {
                        borders.Add(new Line2D(lr + right, lr + right + up));
                        borders.Add(new Line2D(lr + right + up, ll + left + up));
                        borders.Add(new Line2D(ll + left + up, ll + left));
                    }
                }
            }
        }
예제 #16
0
        protected override void OnLoad()
        {
            stopwatch.Restart();
            inputManager = new InputManager3D(InputContext);

            chunkManager = new ChunkManager(GeneratorSeed.Default, 12, 0, 0);

            Vector3 startCoords = new Vector3(TerrainGenerator.ChunkSize / 2f, 0f, TerrainGenerator.ChunkSize / 2f);

            startCoords.Y = Math.Max(NoiseGenerator.GenHeight(chunkManager.GeneratorSeed, new Vector2(startCoords.X, startCoords.Z)), 0) + 32f;
            inputManager.CameraPosition  = startCoords;
            inputManager.CameraMoveSpeed = 100;

            Span <VertexPosition> skyVertices = stackalloc VertexPosition[]
            {
                new Vector3(0, -1, 1),
                new Vector3(1, -1, -1),
                new Vector3(-1, -1, -1),
                new Vector3(0, 1, 0),
                new Vector3(0, -1, 1),
                new Vector3(1, -1, -1),
            };

            skyBuffer              = new VertexBuffer <VertexPosition>(graphicsDevice, skyVertices, BufferUsageARB.StaticDraw);
            skyProgram             = ShaderProgram.FromFiles <VertexPosition>(graphicsDevice, "data/skyVs.glsl", "data/skyFs.glsl", "vPosition");
            skySunDirectionUniform = skyProgram.Uniforms["sunDirection"];
            skySunColorUniform     = skyProgram.Uniforms["sunColor"];
            skyViewUniform         = skyProgram.Uniforms["View"];

            terrainProgram          = ShaderProgram.FromFiles <TerrainVertex>(graphicsDevice, "data/terrainVs.glsl", "data/terrainFs.glsl", "vPosition", "vNormal", "vColor", "vLightingConfig");
            terrainViewUniform      = terrainProgram.Uniforms["View"];
            terrainCameraPosUniform = terrainProgram.Uniforms["cameraPos"];

            waterDistortMap = Texture2DExtensions.FromFile(graphicsDevice, "data/distortMap.png");
            waterNormalsMap = Texture2DExtensions.FromFile(graphicsDevice, "data/normalMap.png");
            waterDistortMap.SetWrapModes(TextureWrapMode.Repeat, TextureWrapMode.Repeat);
            waterDistortMap.SetTextureFilters(TextureMinFilter.Linear, TextureMagFilter.Linear);
            waterNormalsMap.SetWrapModes(TextureWrapMode.Repeat, TextureWrapMode.Repeat);
            waterNormalsMap.SetTextureFilters(TextureMinFilter.Linear, TextureMagFilter.Linear);

            waterReflectFbo = new Framebuffer2D(graphicsDevice, (uint)Window.Size.Width, (uint)Window.Size.Height, PreferredDepthFormat);
            waterRefractFbo = new Framebuffer2D(graphicsDevice, (uint)Window.Size.Width, (uint)Window.Size.Height, PreferredDepthFormat, 0, TextureImageFormat.Color4b, true);
            waterReflectFbo.Texture.SetWrapModes(TextureWrapMode.ClampToEdge, TextureWrapMode.ClampToEdge);
            waterRefractFbo.Texture.SetWrapModes(TextureWrapMode.ClampToEdge, TextureWrapMode.ClampToEdge);

            waterProgram = ShaderProgram.FromFiles <VertexNormalColor>(graphicsDevice, "data/waterVs.glsl", "data/waterFs.glsl", "vPosition");
            waterProgram.Uniforms["distortMap"].SetValueTexture(waterDistortMap);
            waterProgram.Uniforms["normalsMap"].SetValueTexture(waterNormalsMap);
            waterProgram.Uniforms["reflectSamp"].SetValueTexture(waterReflectFbo);
            waterProgram.Uniforms["refractSamp"].SetValueTexture(waterRefractFbo);
            waterRefractFbo.Framebuffer.TryGetTextureAttachment(FramebufferAttachmentPoint.Depth, out FramebufferTextureAttachment rtdpt);
            ((Texture2D)rtdpt.Texture).SetWrapModes(TextureWrapMode.ClampToEdge, TextureWrapMode.ClampToEdge);
            waterProgram.Uniforms["depthSamp"].SetValueTexture(rtdpt.Texture);
            waterCameraPosUniform     = waterProgram.Uniforms["cameraPos"];
            waterDistortOffsetUniform = waterProgram.Uniforms["distortOffset"];
            waterSunlightColorUniform = waterProgram.Uniforms["sunlightColor"];
            waterSunlightDirUniform   = waterProgram.Uniforms["sunlightDir"];
            waterViewUniform          = waterProgram.Uniforms["View"];

            Span <VertexColor> lines = stackalloc VertexColor[]
            {
                new VertexColor(new Vector3(0, 0, 0), Color4b.Red),
                new VertexColor(new Vector3(1, 0, 0), Color4b.Red),
                new VertexColor(new Vector3(0, 0, 0), Color4b.Lime),
                new VertexColor(new Vector3(0, 1, 0), Color4b.Lime),
                new VertexColor(new Vector3(0, 0, 0), Color4b.Blue),
                new VertexColor(new Vector3(0, 0, 1), Color4b.Blue),
            };

            linesBuffer  = new VertexBuffer <VertexColor>(graphicsDevice, lines, BufferUsageARB.StaticDraw);
            linesProgram = SimpleShaderProgram.Create <VertexColor>(graphicsDevice);

            mainFramebuffer = new Framebuffer2D(graphicsDevice, (uint)Window.Size.Width, (uint)Window.Size.Height, PreferredDepthFormat, 0, TextureImageFormat.Color4b, true);
            mainFramebuffer.TryGetDepthTexture(out mainFramebufferDepthTexture);
            mainFramebuffer.Texture.SetTextureFilters(TextureMinFilter.Linear, TextureMagFilter.Linear);
            mainFramebuffer.Texture.SetWrapModes(TextureWrapMode.ClampToEdge, TextureWrapMode.ClampToEdge);
            mainFramebufferDepthTexture.SetTextureFilters(TextureMinFilter.Linear, TextureMagFilter.Linear);
            mainFramebufferDepthTexture.SetWrapModes(TextureWrapMode.ClampToEdge, TextureWrapMode.ClampToEdge);

            textureProgram = SimpleShaderProgram.Create <VertexColorTexture>(graphicsDevice, 0, 0, true);

            underwaterShader = ShaderProgram.FromFiles <VertexColorTexture>(graphicsDevice, "data/postprocessVs.glsl", "data/underwaterFs.glsl", "vPosition", "vColor", "vTexCoords");
            underwaterShaderTextureUniform = underwaterShader.Uniforms["textureSamp"];
            underwaterShaderDepthUniform   = underwaterShader.Uniforms["depthSamp"];
            underwaterViewDistanceUniform  = underwaterShader.Uniforms["maxDistance"];
            underwaterColorUniform         = underwaterShader.Uniforms["waterColor"];

            textureBatcher = new TextureBatcher(graphicsDevice);

            SetSun(new Vector3(-1, 0.6f, 0.5f), Color4b.LightGoldenrodYellow.ToVector3());

            graphicsDevice.BlendState = BlendState.NonPremultiplied;
            graphicsDevice.DepthState = new DepthState(true, DepthFunction.Lequal);
            graphicsDevice.ClearColor = Vector4.UnitW;
        }