示例#1
0
        public void Draw(TextureBatcher textureBatcher)
        {
            for (int i = trail.Length - 1; i >= 0; i--)
            {
                byte alpha = (byte)(127 - i * 127 / trail.Length);
                textureBatcher.Draw(texture, trail[i], new Color4b(255, 255, 255, alpha));
            }

            textureBatcher.Draw(texture, position);

            for (int i = trail.Length - 1; i != 0; i--)
            {
                trail[i] = trail[i - 1];
            }
            trail[0] = position;
        }
示例#2
0
        public TrippyRenderer(GraphicsDevice graphicsDevice)
        {
            if (graphicsDevice == null)
            {
                throw new ArgumentNullException(nameof(graphicsDevice));
            }

            _device = graphicsDevice;

            _shaderProgram = SimpleShaderProgram.Create <VertexColorTexture>(graphicsDevice, 0, 0, true);
            UpdateProjection();
            _batch = new TextureBatcher(_device);
            _batch.SetShaderProgram(_shaderProgram);

            AllWidgetsTest.Instance.SizeChanged += Instance_SizeChanged;
        }
        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;
        }
示例#4
0
        protected override void OnLoad()
        {
            graphicsDevice.DepthState         = DepthState.None;
            graphicsDevice.FaceCullingEnabled = false;
            graphicsDevice.BlendState         = BlendState.Opaque;
            graphicsDevice.ClearColor         = new Vector4(0, 0, 0, 1);

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

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

            _white = new Texture2D(graphicsDevice, 1, 1);
            _white.SetTextureFilters(TextureMinFilter.Nearest, TextureMagFilter.Nearest);
            var colors = new Color4b[1];

            colors[0] = Color4b.White;
            _white.SetData <Color4b>(colors);
        }
示例#5
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;
        }
示例#6
0
 public void Draw(TextureBatcher textureBatcher)
 {
     textureBatcher.Draw(texture, position, source, color, 5f, rotation, new Vector2(source.Width, source.Height) / 2f);
 }