public Rectangle(Renderer renderer, Vector2I screenSize, Vector2I position, Vector2I size, Vector4 color, float depth = 0.0f) { _shader = renderer.ColorShader; Position = position; ScreenSize = screenSize; Size = size; _color = color; _changed = true; Depth = depth; int vertexCount = 4; _indexCount = 6; _vertices = new VertexDefinition.PositionColor[vertexCount]; UInt32[] indices = { 0, 1, 2, 0, 3, 1 }; _vertexBuffer = Buffer.Create(renderer.DirectX.Device, _vertices, new BufferDescription { Usage = ResourceUsage.Dynamic, SizeInBytes = Utilities.SizeOf <VertexDefinition.PositionColor>() * vertexCount, BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.Write, OptionFlags = ResourceOptionFlags.None, StructureByteStride = 0 }); _indexBuffer = Buffer.Create(renderer.DirectX.Device, BindFlags.IndexBuffer, indices); }
public OpenGLRenderContext() { try { _colorShader = new ColorShader(); _colorShader.Build(); _textureShaderA8 = new TextureShaderA8(); _textureShaderA8.Build(); _textureShaderRGBA = new TextureShaderRGBA(); _textureShaderRGBA.Build(); _textureShaderRGB = new TextureShaderRGB(); _textureShaderRGB.Build(); _textureShaderSDF = new TextureShaderSDF(); _textureShaderSDF.Build(); _textureShaderStencil = new TextureShaderStencil(); _textureShaderStencil.Build(); } catch (OpenGLException e) { Console.WriteLine($"error: {e.Message}"); throw new ApplicationException(); } }
private bool Render() { // Clear the buffer to begin the scene. D3D.BeginScene(0.1f, 0f, 0f, 1f); // Generate the view matrix based on the camera position. Camera.Render(); // Get the world, view, and projection matrices from camera and d3d objects. var viewMatrix = Camera.ViewMatrix; var worldMatrix = D3D.WorldMatrix; var projectionMatrix = D3D.ProjectionMatrix; // Put the model vertex and index buffers on the graphics pipeline to prepare them for drawing. Model.Render(D3D.DeviceContext); // Render the model using the color shader. if (!ColorShader.Render(D3D.DeviceContext, Model.IndexCount, worldMatrix, viewMatrix, projectionMatrix)) { return(false); } // Present the rendered scene to the screen. D3D.EndScene(); return(true); }
public void Shutdown() { // Release the position object. Position = null; // Release the fps object. FPS = null; // Release the camera object. Camera = null; // Release the text object. Text?.Shutdown(); Text = null; // Release the font shader object. FontShader?.Shuddown(); FontShader = null; // Release the cpu object. CPU?.Shutdown(); CPU = null; // Release the color shader object. ColorShader?.ShutDown(); ColorShader = null; // Release the tree object. Terrain?.ShutDown(); Terrain = null; // Release the input object. Input?.Shutdown(); Input = null; // Release the Direct3D object. D3D?.ShutDown(); D3D = null; }
public Gui(Sdl2Window window, GraphicsDevice device) { LoadSettings(); Window = window; Device = device; Factory = device.ResourceFactory; TextRenderer = new TextRenderer(Device); ColorShader = new ColorShader(Factory); TextureShader = new TextureShader(Factory); // Create pipeline var pipelineDescription = new GraphicsPipelineDescription( BlendStateDescription.SingleAlphaBlend, new DepthStencilStateDescription( depthTestEnabled: true, depthWriteEnabled: true, comparisonKind: ComparisonKind.LessEqual), new RasterizerStateDescription( cullMode: FaceCullMode.Back, fillMode: PolygonFillMode.Solid, frontFace: FrontFace.Clockwise, depthClipEnabled: true, scissorTestEnabled: false), PrimitiveTopology.TriangleStrip, new ShaderSetDescription( vertexLayouts: new VertexLayoutDescription[] { ColorShader.Layout }, shaders: new Shader[] { ColorShader.VertexShader, ColorShader.FragmentShader }), new[] { ColorShader.ResourceLayout }, Device.SwapchainFramebuffer.OutputDescription ); Pipeline = Factory.CreateGraphicsPipeline(pipelineDescription); var texturePipelineDesc = new GraphicsPipelineDescription( BlendStateDescription.SingleAlphaBlend, new DepthStencilStateDescription( depthTestEnabled: true, depthWriteEnabled: true, comparisonKind: ComparisonKind.LessEqual), new RasterizerStateDescription( cullMode: FaceCullMode.Back, fillMode: PolygonFillMode.Solid, frontFace: FrontFace.Clockwise, depthClipEnabled: true, scissorTestEnabled: false), PrimitiveTopology.TriangleStrip, new ShaderSetDescription( vertexLayouts: new VertexLayoutDescription[] { TextureShader.Layout }, shaders: new Shader[] { TextureShader.VertexShader, TextureShader.FragmentShader }), new[] { TextureShader.ProjViewLayout, TextureShader.TextureLayout }, Device.SwapchainFramebuffer.OutputDescription ); TexturePipeline = Factory.CreateGraphicsPipeline(texturePipelineDesc); CommandList = Factory.CreateCommandList(); }
public static void BeginDrawColor(IVertexBuffer vertexBuffer, Matrix4 transform, Vector4 color) { ColorShader.Use(); ColorShader.ModelMatrix.Set(transform); ColorShader.Color.Set(color); vertexBuffer.Bind(); vertexBuffer.BindAttribute(ColorShader.Position, 0); }
public void ShutDown() { // Release the font shader object. FontShader?.Shuddown(); FontShader = null; // Release the texture shader object. ColorShader?.ShutDown(); ColorShader = null; }
public bool RenderColorShader(DeviceContext deviceContext, int indexCount, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix) { // Render the ColoreShader. if (!ColorShader.Render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix)) { return(false); } return(true); }
public void ShutDown() { Camera = null; Timer = null; ColorShader?.ShutDown(); ColorShader = null; Model?.ShutDown(); Model = null; D3D?.ShutDown(); D3D = null; }
protected internal override void OnLoad() { base.OnLoad(); CreateShadowMap(); whiteMap = MMW.GetAsset <Texture2D>("WhiteMap"); depthShader = (DepthShader)MMW.GetAsset <Shader>("Depth"); colorShader = (ColorShader)MMW.GetAsset <Shader>("Color"); depthRT = new RenderTexture(MMW.RenderResolution); depthRT.ColorFormat0 = PixelInternalFormat.Rgba16f; depthRT.Load(); colorRT = new RenderTexture(MMW.RenderResolution); colorRT.ColorFormat0 = MMW.Configuration.DefaultPixelFormat; colorRT.Load(); randColors = new Color4[ushort.MaxValue + 1]; for (var i = 0; i < randColors.Length; i++) { randColors[i] = new Color4( RandomHelper.NextFloat() * 0.5f + 0.5f, RandomHelper.NextFloat() * 0.5f + 0.5f, RandomHelper.NextFloat() * 0.5f + 0.5f, 1.0f); } shadowDepthBias = Matrix4.CreateScale(0.5f) * Matrix4.CreateTranslation(0.5f, 0.5f, 0.5f); velocityShader = (VelocityShader)MMW.GetAsset <Shader>("Velocity"); velocityRT = new RenderTexture(MMW.RenderResolution); velocityRT.ColorFormat0 = PixelInternalFormat.Rgba16f; velocityRT.Load(); sp = new ShaderUniqueParameter() { camera = this, }; getter.Add("Orthographic", obj => Orthographic); getter.Add("Up", obj => Up); getter.Add("Width", obj => Width); getter.Add("Height", obj => Height); getter.Add("Aspect", obj => Aspect); getter.Add("FoV", obj => FoV); getter.Add("Near", obj => Near); getter.Add("Far", obj => Far); getter.Add("Depth", obj => Depth); getter.Add("ClearColor", obj => ClearColor); }
private bool Render() { D3D.BeginScene(0.1f, 0f, 0f, 1f); Camera.Render(); Model.Render(D3D.DeviceContext); if (!ColorShader.Render(D3D.DeviceContext, Model.IndexCount, D3D.WorldMatrix, Camera.ViewMatrix, D3D.ProjectionMatrix)) { return(false); } D3D.EndScene(); return(true); }
public static void DrawLine(Matrix4 transform, Vector4 color, Vector3 p1, Vector3 p2, float thickness = 1f) { ColorShader.Use(); ColorShader.ModelMatrix.Set(transform); ColorShader.Color.Set(color); GL.PushAttrib(AttribMask.LineBit); GL.LineWidth(thickness); GL.Begin(PrimitiveType.Lines); GL.Vertex3(p1); GL.Vertex3(p2); GL.End(); GL.PopAttrib(); }
/// <summary> /// custom constructor /// </summary> public Graphics(int reserveVertexCount) { lineBuffer = new List <PrimitiveVertex>(); polygonBuffer = new List <PrimitiveVertex>(); litPolygonBuffer = new List <PrimitiveVertex>(); texturedPolygonBuffer = new Dictionary <Texture2D, List <PrimitiveVertex> >(); deviceBuffer = new VertexBuffer(); colorShader = new ColorShader(); litColorShader = new LitColorShader(); litTexturerShader = new LitTextureShader(); reservedStartingSpace = reserveVertexCount; beginEndPair = false; }
public static void DrawBoundingBox(Matrix4 transform, BBox box, Vector4 color, float thickness = 1f) { ColorShader.Use(); ColorShader.ModelMatrix.Set(Matrix4.CreateScale(box.Size) * Matrix4.CreateTranslation(box.Center) * transform); ColorShader.Color.Set(color); BoundingBoxBufffer.Bind(); BoundingBoxBufffer.BindAttribute(ColorShader.Position, 0); GL.PushAttrib(AttribMask.LineBit); GL.LineWidth(thickness); BoundingBoxBufffer.DrawElements(PrimitiveType.Lines); GL.PopAttrib(); }
public void ShutDown() { // Release the sky dome shader object. SkyDomeShader.ShutDown(); SkyDomeShader = null; // Release the Terrain Shader ibject. TerrainShader?.ShutDown(); TerrainShader = null; // Release the font shader object. FontShader?.Shuddown(); FontShader = null; // Release the texture shader object. ColorShader?.ShutDown(); ColorShader = null; }
public static IShaderEffect Create(ShaderName name) { IShaderEffect shaderEffect; switch (name) { case ShaderName.Color: shaderEffect = new ColorShader(); break; case ShaderName.Ambient: shaderEffect = new AmbientShader(); break; case ShaderName.Diffuse: shaderEffect = new DiffuseLighting(); break; case ShaderName.Specular: shaderEffect = new SpecularLighting(); break; case ShaderName.Multitexture: shaderEffect = new Multitexturing(); break; case ShaderName.Texture: shaderEffect = new TextureMapping(); break; case ShaderName.Test: shaderEffect = new TestShader(); break; case ShaderName.Bumpmaping: shaderEffect = new BumpMapping(); break; case ShaderName.ParallaxMapping: shaderEffect = new ParallaxMapping(); break; case ShaderName.LightingEffect: shaderEffect = new LightingShader(); break; case ShaderName.DirectionalLightingParallaxMapping: shaderEffect = new DirectionalLightingParallax(); break; case ShaderName.DepthShader: shaderEffect = new DepthShader(); break; default: shaderEffect = null; break; } return shaderEffect; }
public void ShutDown() { // Release the camera object. Camera = null; Timer = null; // Release the color shader object. ColorShader?.ShutDown(); ColorShader = null; // Release the model object. Model?.ShutDown(); Model = null; // Release the Direct3D object. D3D?.ShutDown(); D3D = null; }
public static void DrawRectangle(Matrix4 transform, Vector2 size, Vector4 color, float thickness = 1f) { ColorShader.Use(); ColorShader.ModelMatrix.Set(transform); ColorShader.Color.Set(color); GL.PushAttrib(AttribMask.LineBit); GL.LineWidth(thickness); GL.Begin(PrimitiveType.LineStrip); GL.Vertex3(Vector3.Zero); GL.Vertex3(Vector3.UnitZ * size.Y); GL.Vertex3(Vector3.UnitX * size.X + Vector3.UnitZ * size.Y); GL.Vertex3(Vector3.UnitX * size.X); GL.Vertex3(Vector3.Zero); GL.End(); GL.PopAttrib(); }
private bool RenderGraphics() { // Clear the scene. D3D.BeginScene(0, 0, 0, 1); // Generate the view matrix based on the camera's position. Camera.Render(); // Get the world, view, and projection matrices from camera and d3d objects. var viewMatrix = Camera.ViewMatrix; var worldMatrix = D3D.WorldMatrix; var projectionMatrix = D3D.ProjectionMatrix; var orthoMatrix = D3D.OrthoMatrix; // Render the terrain buffers. Terrain.Render(D3D.DeviceContext); // Render the model using the color shader. if (!ColorShader.Render(D3D.DeviceContext, Terrain.IndexCount, worldMatrix, viewMatrix, projectionMatrix)) { return(false); } // Turn off the Z buffer to begin all 2D rendering. D3D.TurnZBufferOff(); // Turn on the alpha blending before rendering the text. D3D.TurnOnAlphaBlending(); // Render the text string. if (!Text.Render(D3D.DeviceContext, worldMatrix, orthoMatrix)) { return(false); } // Turn off the alpha blending before rendering the text. D3D.TurnOffAlphaBlending(); // Turn on the Z buffer to begin all 2D rendering. D3D.TurnZBufferOn(); // Present the rendered scene to the screen. D3D.EndScene(); return(true); }
private bool RenderGraphics() { // Clear the scene. D3D.BeginScene(0.0f, 0.0f, 0.0f, 1.0f); // Generate the view matrix based on the camera's position. Camera.Render(); // Get the world, view, projection, and ortho matrices from the camera and Direct3D objects. Matrix worldMatrix = D3D.WorldMatrix; Matrix cameraViewMatrix = Camera.ViewMatrix; Matrix projectionMatrix = D3D.ProjectionMatrix; Matrix orthoD3DMatrix = D3D.OrthoMatrix; // Render the terrain buffers. Terrain.Render(D3D.DeviceContext); // Render the model using the color shader. if (!ColorShader.Render(D3D.DeviceContext, Terrain.IndexCount, worldMatrix, cameraViewMatrix, projectionMatrix)) { return(false); } // Turn off the Z buffer to begin all 2D rendering. D3D.TurnZBufferOff(); // Turn on the alpha blending before rendering the text. D3D.TurnOnAlphaBlending(); // Render the text user interface elements. if (!Text.Render(D3D.DeviceContext, FontShader, worldMatrix, orthoD3DMatrix)) { return(false); } // Turn off alpha blending after rendering the text. D3D.TurnOffAlphaBlending(); // Turn the Z buffer back on now that all 2D rendering has completed. D3D.TurnZBufferOn(); // Present the rendered scene to the screen. D3D.EndScene(); return(true); }
public void Dispose() { if (SceneGraph != null) { SceneGraph.DisposeAll(); SceneGraph = null; } if (TextRenderer != null) { TextRenderer.Dispose(); TextRenderer = null; } if (CommandList != null) { CommandList.Dispose(); CommandList = null; } if (TexturePipeline != null) { TexturePipeline.Dispose(); TexturePipeline = null; } if (Pipeline != null) { Pipeline.Dispose(); Pipeline = null; } if (TextureShader != null) { TextureShader.Dispose(); TextureShader = null; } if (ColorShader != null) { ColorShader.Dispose(); ColorShader = null; } }
public static void ReleaseResources() { if (ColorShader != null) { ColorShader.Dispose(); ColorShader = null; } if (WireframeShader != null) { WireframeShader.Dispose(); WireframeShader = null; } if (WireframeShader2 != null) { WireframeShader2.Dispose(); WireframeShader2 = null; } if (ModelShader != null) { ModelShader.Dispose(); ModelShader = null; } if (BoundingBoxBufffer != null) { BoundingBoxBufffer.Dispose(); BoundingBoxBufffer = null; } if (StudConnectionShader != null) { StudConnectionShader.Dispose(); StudConnectionShader = null; } if (SimpleTextureShader != null) { SimpleTextureShader.Dispose(); SimpleTextureShader = null; } }
public static void DrawGizmoAxes(Matrix4 transform, float size, float lineThickness = 1f) { ColorShader.Use(); ColorShader.ModelMatrix.Set(transform); GL.PushAttrib(AttribMask.LineBit); GL.LineWidth(lineThickness); for (int i = 0; i < 3; i++) { ColorShader.Color.Set(DefaultAxisColors[i]); GL.Begin(PrimitiveType.Lines); GL.Vertex3(Vector3.Zero); var axisVector = new Vector3(); axisVector[i] = 1f; GL.Vertex3(axisVector * size); GL.End(); } GL.PopAttrib(); }
public static void InitializeMatrices(Camera camera) { var viewMatrix = camera.GetViewMatrix(); var projection = camera.GetProjectionMatrix(); WireframeShader.Use(); WireframeShader.ViewMatrix.Set(viewMatrix); WireframeShader.Projection.Set(projection); WireframeShader2.Use(); WireframeShader2.ViewMatrix.Set(viewMatrix); WireframeShader2.Projection.Set(projection); ColorShader.Use(); ColorShader.ViewMatrix.Set(viewMatrix); ColorShader.Projection.Set(projection); ModelShader.Use(); ModelShader.ViewMatrix.Set(viewMatrix); ModelShader.Projection.Set(projection); ModelShader.ViewPosition.Set(camera.Position); StudConnectionShader.Use(); StudConnectionShader.ViewMatrix.Set(viewMatrix); StudConnectionShader.Projection.Set(projection); SimpleTextureShader.Use(); SimpleTextureShader.ViewMatrix.Set(viewMatrix); SimpleTextureShader.Projection.Set(projection); if (UIRenderHelper.Freetype6Loaded) { UIRenderHelper.TextRenderer.ProjectionMatrix = projection; UIRenderHelper.TextRenderer.DrawingPrimitives.Clear(); } TextViewMatrix = viewMatrix; GL.UseProgram(0); }
// Called on load public void Init() { Viewport = new GLControl(); Controls.Add(Viewport); Viewport.BringToFront(); Viewport.Paint += Viewport_Paint; Viewport.Resize += Viewport_Resize; Viewport.Dock = DockStyle.Fill; scene = new Scene(Viewport); //dont like doing this need a Renderer.InitShaders() or something ColorShader colorShader = new ColorShader("Shaders\\ColorVertexShader.glsl", "Shaders\\ColorFragmentShader.glsl"); scene.Renderer.ShaderManager.AddShader("Color", colorShader); scene.Renderer.Start(); UpdateSceneUI(); Application.Idle += Application_Idle; Viewport_Resize(Viewport, EventArgs.Empty); }
public Renderer() { CreateWindow(); DirectX = new Dx11(Form); ScreenSize = new Vector2I(ConfigurationManager.Config.Width, ConfigurationManager.Config.Height); Light = new Light { Direction = new Vector3(1.0f, -1.0f, 0.0f), Color = new Vector4(1.0f, 1.0f, 1.0f, 1.0f), AmbiantColor = new Vector4(0.16f, 0.16f, 0.16f, 1.0f), SpecularPower = 32.0f, SpecularColor = new Vector4(1.0f, 1.0f, 0.7f, 1.0f) }; ColorShader = new ColorShader(DirectX.Device); TextureShader = new TextureShader(DirectX.Device); LightShader = new LightShader(DirectX.Device); TranslateShader = new TranslateShader(DirectX.Device); CircleShader = new FontShader(DirectX.Device); FontShader = new FontShader(DirectX.Device); TextManager = new TextManager(DirectX.Device, ConfigurationManager.Config.Width, ConfigurationManager.Config.Height); TextureManager = new TextureManager(DirectX.Device); _renderables = new List <RenderableGameComponent>(); }
public PlainRectangle(IContext context, Vector2I size, Color color) { _shader = context.Shaders.Get <ColorShader>(); DeviceContext = context.DirectX.Device.ImmediateContext; _color = color; const int vertexCount = 4; _vertices = new VertexDefinition.PositionColor[vertexCount]; VertexBuffer = Buffer.Create(context.DirectX.Device, _vertices, new BufferDescription { Usage = ResourceUsage.Dynamic, SizeInBytes = Utilities.SizeOf <VertexDefinition.PositionColor>() * vertexCount, BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.Write, OptionFlags = ResourceOptionFlags.None, StructureByteStride = 0 }); IndexCount = 6; uint[] indices = { 0, 1, 2, 0, 3, 1 }; IndexBuffer = Buffer.Create(context.DirectX.Device, BindFlags.IndexBuffer, indices); Size = size; }
private static AM.SolidColorBrush ToSolidColorBrush(this ColorShader colorShader) { var color = colorShader.Color.ToColor(); return(new AM.SolidColorBrush(color)); }
public bool Initialize(SystemConfiguration configuration, IntPtr windowHandle) { if (Input == null) { Input = new InputClass(); if (!Input.Initialize(configuration, windowHandle)) { MessageBox.Show("Could not initialize input object", "Error", MessageBoxButtons.OK); return(false); } } // Create the Direct3D object. D3D = new DX11(); // Initialize the Direct3D object. if (!D3D.Initialize(configuration, windowHandle)) { MessageBox.Show("Could not initialize Direct3D", "Error", MessageBoxButtons.OK); return(false); } // Create the camera object Camera = new Camera(); // Initialize a base view matrix the camera for 2D user interface rendering. Camera.SetPosition(0, 0, -1); Camera.Render(); var baseViewMatrix = Camera.ViewMatrix; // Set the initial position of the camera. var cameraX = 50f; var cameraY = 2f; var cameraZ = -7f; Camera.SetPosition(cameraX, cameraY, cameraZ); // Create the terrain object. Terrain = new Terrain(); // Initialize the terrain object. if (!Terrain.Initialize(D3D.Device)) { MessageBox.Show("Could not initialize the terrain object", "Error", MessageBoxButtons.OK); return(false); } // Create the light shader object. ColorShader = new ColorShader(); // Initialize the light shader object. if (!ColorShader.Initialize(D3D.Device, windowHandle)) { MessageBox.Show("Could not initialize the light shader", "Error", MessageBoxButtons.OK); return(false); } // Create and initialize Timer. Timer = new Timer(); if (!Timer.Initialize()) { MessageBox.Show("Could not initialize Timer object", "Error", MessageBoxButtons.OK); return(false); } // Create the position object. Position = new Position(); // Set the initial position of the viewer to the same as the initial camera position. Position.SetPosition(new Vector3(cameraX, cameraY, cameraZ)); // Create and initialize the FPS object. FPS = new FPS(); FPS.Initialize(); // Create and initialize the CPU. CPU = new CPU(); CPU.Initialize(); // Create the font shader object. FontShader = new FontShader(); // Initialize the font shader object. if (!FontShader.Initialize(D3D.Device, windowHandle)) { MessageBox.Show("Could not initialize font shader object", "Error", MessageBoxButtons.OK); return(false); } // Create the text object. Text = new Text(); if (!Text.Initialize(D3D.Device, D3D.DeviceContext, windowHandle, configuration.Width, configuration.Height, baseViewMatrix)) { MessageBox.Show("Could not initialize the text object", "Error", MessageBoxButtons.OK); return(false); } if (!Text.SetVideoCard(D3D.VideoCardDescription, D3D.VideoCardMemory, D3D.DeviceContext)) { MessageBox.Show("Could not set video card into the text object", "Error", MessageBoxButtons.OK); return(false); } return(true); }
public void Shutdown() { // Release the text object. if (Text != null) { Text.Shutdown(); Text = null; } // Release the font shader object. if (FontShader != null) { FontShader.Shuddown(); FontShader = null; } // Release the CPU object if (CPU != null) { CPU.Shutdown(); CPU = null; } // Release the FPS object FPS = null; // Release the position object. Position = null; // Release the Timer object Timer = null; // Release the light shader object. if (ColorShader != null) { ColorShader.Shuddown(); ColorShader = null; } // Release the terrain object. if (Terrain != null) { Terrain.Shutdown(); Terrain = null; } // Release the camera object. if (Camera != null) { Camera = null; } // Release the Direct3D object. if (D3D != null) { D3D.Shutdown(); D3D = null; } // Release the input object. if (Input != null) { Input.Shutdown(); Input = null; } }