protected override void OnLoad() { Span <VertexTexture> vertices = stackalloc VertexTexture[] { new VertexTexture(new Vector3(-1, -1, 0), new Vector2(0, 1)), new VertexTexture(new Vector3(-1, 1, 0), new Vector2(0, 0)), new VertexTexture(new Vector3(1, -1, 0), new Vector2(1, 1)), new VertexTexture(new Vector3(1, 1, 0), new Vector2(1, 0)) }; vertexBuffer = new VertexBuffer <VertexTexture>(graphicsDevice, vertices, BufferUsageARB.StaticDraw); fbo1 = new Framebuffer2D(graphicsDevice, SimulationWidth, SimulationHeight, DepthStencilFormat.None); //FramebufferObject.Create2D(ref tex1, graphicsDevice, SimulationWidth, SimulationHeight, DepthStencilFormat.None); fbo2 = new Framebuffer2D(graphicsDevice, SimulationWidth, SimulationHeight, DepthStencilFormat.None); //FramebufferObject.Create2D(ref tex2, graphicsDevice, SimulationWidth, SimulationHeight, DepthStencilFormat.None); fbo1.Texture.SetTextureFilters(TextureMinFilter.Nearest, TextureMagFilter.Nearest); fbo2.Texture.SetTextureFilters(TextureMinFilter.Nearest, TextureMagFilter.Nearest); fbo1.Texture.SetWrapModes(TextureWrapMode.Repeat, TextureWrapMode.Repeat); fbo2.Texture.SetWrapModes(TextureWrapMode.Repeat, TextureWrapMode.Repeat); r = new Random(); simProgram = ShaderProgram.FromFiles <VertexTexture>(graphicsDevice, "sim_vs.glsl", "sim_fs.glsl", new string[] { "vPosition", "vTexCoords" }); drawProgram = SimpleShaderProgram.Create <VertexTexture>(graphicsDevice); simProgram.Uniforms["pixelDelta"].SetValueVec2(1f / SimulationWidth, 1f / SimulationHeight); simPrevUniform = simProgram.Uniforms["previous"]; graphicsDevice.BlendingEnabled = false; graphicsDevice.DepthTestingEnabled = false; OnKeyDown(null, Key.Home, 0); OnKeyDown(null, Key.R, 0); }
protected override void OnLoad() { Span <VertexColor> cubeBufferData = stackalloc VertexColor[] { new VertexColor(new Vector3(-0.5f, -0.5f, -0.5f), Color4b.LightBlue), //4 new VertexColor(new Vector3(-0.5f, -0.5f, 0.5f), Color4b.Lime), //3 new VertexColor(new Vector3(-0.5f, 0.5f, -0.5f), Color4b.White), //7 new VertexColor(new Vector3(-0.5f, 0.5f, 0.5f), Color4b.Black), //8 new VertexColor(new Vector3(0.5f, 0.5f, 0.5f), Color4b.Blue), //5 new VertexColor(new Vector3(-0.5f, -0.5f, 0.5f), Color4b.Lime), //3 new VertexColor(new Vector3(0.5f, -0.5f, 0.5f), Color4b.Red), //1 new VertexColor(new Vector3(-0.5f, -0.5f, -0.5f), Color4b.LightBlue), //4 new VertexColor(new Vector3(0.5f, -0.5f, -0.5f), Color4b.Yellow), //2 new VertexColor(new Vector3(-0.5f, 0.5f, -0.5f), Color4b.White), //7 new VertexColor(new Vector3(0.5f, 0.5f, -0.5f), Color4b.Pink), //6 new VertexColor(new Vector3(0.5f, 0.5f, 0.5f), Color4b.Blue), //5 new VertexColor(new Vector3(0.5f, -0.5f, -0.5f), Color4b.Yellow), //2 new VertexColor(new Vector3(0.5f, -0.5f, 0.5f), Color4b.Red), //1 }; vertexBuffer = new VertexBuffer <VertexColor>(graphicsDevice, cubeBufferData, BufferUsage.StaticCopy); shaderProgram = SimpleShaderProgram.Create <VertexColor>(graphicsDevice); shaderProgram.View = Matrix4x4.CreateLookAt(new Vector3(0, 1.0f, -1.5f), Vector3.Zero, Vector3.UnitY); graphicsDevice.DepthState = DepthState.Default; graphicsDevice.BlendState = BlendState.Opaque; stopwatch = Stopwatch.StartNew(); }
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(); }
protected override void OnLoad() { Span <VertexColor> vertexData = stackalloc VertexColor[] { new VertexColor(new Vector3(-0.5f, -0.5f, 0), new Color4b(255, 0, 0, 255)), new VertexColor(new Vector3(0, 0.5f, 0), new Color4b(0, 255, 0, 255)), new VertexColor(new Vector3(0.5f, -0.5f, 0), new Color4b(0, 0, 255, 255)), }; vertexBuffer = new VertexBuffer <VertexColor>(graphicsDevice, vertexData, BufferUsage.StaticDraw); shaderProgram = SimpleShaderProgram.Create <VertexColor>(graphicsDevice); graphicsDevice.ClearColor = new Vector4(0, 0, 0, 1); graphicsDevice.BlendingEnabled = false; graphicsDevice.DepthTestingEnabled = false; }
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; }
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); }
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(); }
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; }