public void SetVertexShader(IVertexShader shader) { var box = (VertexShaderBox)shader; _deviceContext.VertexShader.Set(box.Shader); _deviceContext.InputAssembler.InputLayout = box.InputLayout; }
/// <summary> /// Creates an effect with on technique and one pass. /// </summary> /// <param name="vs">VertexShader to use.</param> /// <param name="ps">PixelShader to use.</param> public ShaderEffect(IVertexShader vs, IPixelShader ps) { Pass pass = new Pass("Pass1", vs, ps); Technique technique = new Technique("Technique1", pass); techniques.Add(technique); }
public static void Render <TVertexShaderIn, TPixelShaderIn>( TVertexShaderIn[] vertices, int[] indices, MemoryResources resources, InputAssembler inputAssembler, OutputMerger outputMerger, IVertexShader <TVertexShaderIn, TPixelShaderIn> vertexShader, IGeometryProcessor <TPixelShaderIn> geometryProcessor, IRasterizer <TPixelShaderIn> rasterizer, IPixelShader <TPixelShaderIn> pixelShader, Bitmap output) where TVertexShaderIn : struct, IVertexShaderInput where TPixelShaderIn : struct, IPixelShaderInput { if (vertices.Length == 0 || indices.Length == 0) { return; } (vertices, indices) = inputAssembler.Assemble(vertices, indices); var vertexShaderOutput = new TPixelShaderIn[vertices.Length]; for (var i = 0; i < vertices.Length; ++i) { vertexShaderOutput[i] = vertexShader.Transform(resources, vertices[i]); } (vertexShaderOutput, indices) = geometryProcessor.Process(vertexShaderOutput, indices); var pixelShaderOutput = rasterizer.Rasterize(resources, vertexShaderOutput, indices, pixelShader, outputMerger, output.Width, output.Height, _outputBuffer, _wBuffer); Helper.SetPixels(pixelShaderOutput, output); }
public override void Initialize() { var vertexBuffer = Context.Create.Buffer(BufferTarget.Array, 3 * 8 * sizeof(float), BufferUsageHint.StaticDraw, new[] { new Vertex { Position = new Vector4(-0.5f, -0.5f, 0f, 1f), Color = new Color4(1, 0, 0, 1) }, new Vertex { Position = new Vector4(0.0f, 0.5f, 0f, 1f), Color = new Color4(0, 1, 0, 1) }, new Vertex { Position = new Vector4(0.5f, -0.5f, 0f, 1f), Color = new Color4(1, 1, 0, 1) } }); var indexBuffer = Context.Create.Buffer(BufferTarget.ElementArray, 3 * sizeof(ushort), BufferUsageHint.StaticDraw, new ushort[] { 0, 1, 2 }); vertexArray = Context.Create.VertexArray(); vertexArray.SetElementArrayBuffer(indexBuffer); vertexArray.SetVertexAttributeF(0, vertexBuffer, VertexAttributeDimension.Four, VertexAttribPointerType.Float, false, 32, 0); vertexArray.SetVertexAttributeF(1, vertexBuffer, VertexAttributeDimension.Four, VertexAttribPointerType.Float, false, 32, 16); IVertexShader vsh = Context.Create.VertexShader(VertexShaderText); IFragmentShader fsh = Context.Create.FragmentShader(FragmentShaderText); program = Context.Create.Program(new ShaderProgramDescription { VertexShaders = new[] { vsh }, FragmentShaders = new[] { fsh }, VertexAttributeNames = new[] { "in_position", "in_color" } }); }
public override void Build(IDevice device) { _indexBuffer = device.CreateIndexBuffer(new int[] { 0, 3, 1, 3, 2, 1 }); _vertexBuffer = device.CreateVertexBuffer(CreateCube()); using var pixelShaderBlob = new Blob(device.TEMPORARYCompiler.CompileShaderFromFile(@"F:\Git\GameDev\resources\shaders\BackBufferPixelShader.hlsl", "main", "ps_5_0")); _pixelShader = device.CreatePixelShader(pixelShaderBlob); using var vertexShaderBlob = new Blob(device.TEMPORARYCompiler.CompileShaderFromFile(@"F:\Git\GameDev\resources\shaders\BackBufferVertexShader.hlsl", "main", "vs_5_0")); _vertexShader = device.CreateVertexShader(vertexShaderBlob); _inputLayout = device.CreateInputLayout(new VertexLayout(2).Append("POSITION", VertexLayoutTypes.Position2D).Append("TEXCOORD", VertexLayoutTypes.Position2D), vertexShaderBlob); _sampler = device.CreateSampler(); }
public RenderMeshPass(IDevice device, ID3DCompiler compiler) { using var vertexShaderBlob = new Blob(compiler.CompileShaderFromFile(@"F:\Git\GameDev\src\Titan.D3D11.Bindings\VertexShader.hlsl", "main", "vs_5_0")); using var pixelShaderBlob = new Blob(compiler.CompileShaderFromFile(@"F:\Git\GameDev\src\Titan.D3D11.Bindings\PixelShader.hlsl", "main", "ps_5_0")); _vertexShader = device.CreateVertexShader(vertexShaderBlob); _pixelShader = device.CreatePixelShader(pixelShaderBlob); _inputLayout = device.CreateInputLayout(new VertexLayout(4).Append("Position", VertexLayoutTypes.Position3D).Append("Normal", VertexLayoutTypes.Position3D).Append("Texture", VertexLayoutTypes.Texture2D).Append("Color", VertexLayoutTypes.Float4Color), vertexShaderBlob); _perFrameConstantBuffer = device.CreateConstantBuffer <PerFrameContantBuffer>(BufferUsage.Dynamic, BufferAccessFlags.Write); _lightsConstantBuffer = device.CreateConstantBuffer <LightsConstantBuffer>(BufferUsage.Dynamic, BufferAccessFlags.Write); _perObjectConstantBuffer = device.CreateConstantBuffer <PerObjectContantBuffer>(BufferUsage.Dynamic, BufferAccessFlags.Write); _sampler = device.CreateSampler(); }
public RenderToBackbufferPass(IDevice device, ID3DCompiler compiler) { _backBuffer = device.BackBuffer; _depthStencil = device.DepthStencil; _indexBuffer = device.CreateIndexBuffer(new int[] { 0, 3, 1, 3, 2, 1 }); _vertexBuffer = device.CreateVertexBuffer(CreateCube()); using var pixelShaderBlob = new Blob(compiler.CompileShaderFromFile(@"F:\Git\GameDev\resources\shaders\BackBufferPixelShader.hlsl", "main", "ps_5_0")); _pixelShader = device.CreatePixelShader(pixelShaderBlob); using var vertexShaderBlob = new Blob(compiler.CompileShaderFromFile(@"F:\Git\GameDev\resources\shaders\BackBufferVertexShader.hlsl", "main", "vs_5_0")); _vertexShader = device.CreateVertexShader(vertexShaderBlob); _inputLayout = device.CreateInputLayout(new VertexLayout(2).Append("POSITION", VertexLayoutTypes.Position2D).Append("TEXCOORD", VertexLayoutTypes.Position2D), vertexShaderBlob); _sampler = device.CreateSampler(); }
public override void Initialize() { var vertexData = new Vertex[MaxVertices]; vertexData[0] = Vertex.Cannon; var vertexBufferSource = Context.Create.Buffer(BufferTarget.TransformFeedback, Vertex.SizeInBytes * MaxVertices, BufferUsageHint.StaticDraw, vertexData); var vertexBufferTarget = Context.Create.Buffer(BufferTarget.TransformFeedback, Vertex.SizeInBytes * MaxVertices, BufferUsageHint.StaticDraw); vertexArraySource = Context.Create.VertexArray(); vertexArraySource.SetVertexAttributeF(0, vertexBufferSource, VertexAttributeDimension.Two, VertexAttribPointerType.Float, false, Vertex.SizeInBytes, 0); vertexArraySource.SetVertexAttributeF(1, vertexBufferSource, VertexAttributeDimension.Two, VertexAttribPointerType.Float, false, Vertex.SizeInBytes, 2 * sizeof(float)); vertexArraySource.SetVertexAttributeF(2, vertexBufferSource, VertexAttributeDimension.One, VertexAttribPointerType.Float, false, Vertex.SizeInBytes, 4 * sizeof(float)); vertexArraySource.SetVertexAttributeI(3, vertexBufferSource, VertexAttributeDimension.One, VertexAttribIPointerType.Int, Vertex.SizeInBytes, 5 * sizeof(float)); vertexArraySource.SetVertexAttributeF(4, vertexBufferSource, VertexAttributeDimension.Three, VertexAttribPointerType.Float, false, Vertex.SizeInBytes, 6 * sizeof(float)); vertexArrayTarget = Context.Create.VertexArray(); vertexArrayTarget.SetVertexAttributeF(0, vertexBufferTarget, VertexAttributeDimension.Two, VertexAttribPointerType.Float, false, Vertex.SizeInBytes, 0); vertexArrayTarget.SetVertexAttributeF(1, vertexBufferTarget, VertexAttributeDimension.Two, VertexAttribPointerType.Float, false, Vertex.SizeInBytes, 2 * sizeof(float)); vertexArrayTarget.SetVertexAttributeF(2, vertexBufferTarget, VertexAttributeDimension.One, VertexAttribPointerType.Float, false, Vertex.SizeInBytes, 4 * sizeof(float)); vertexArrayTarget.SetVertexAttributeI(3, vertexBufferTarget, VertexAttributeDimension.One, VertexAttribIPointerType.Int, Vertex.SizeInBytes, 5 * sizeof(float)); vertexArrayTarget.SetVertexAttributeF(4, vertexBufferTarget, VertexAttributeDimension.Three, VertexAttribPointerType.Float, false, Vertex.SizeInBytes, 6 * sizeof(float)); transformFeedbackSource = Context.Create.TransformFeedback(); transformFeedbackSource.SetBuffer(0, vertexBufferSource); transformFeedbackTarget = Context.Create.TransformFeedback(); transformFeedbackTarget.SetBuffer(0, vertexBufferTarget); timeBuffer = Context.Create.Buffer(BufferTarget.Uniform, 2 * sizeof(float), BufferUsageHint.DynamicDraw); IVertexShader vsh = Context.Create.VertexShader(VertexShaderText); IGeometryShader gsh = Context.Create.GeometryShader(GeometryShaderText); IFragmentShader fsh = Context.Create.FragmentShader(FragmentShaderText); program = Context.Create.Program(new ShaderProgramDescription { VertexShaders = new[] { vsh }, GeometryShaders = new[] { gsh }, FragmentShaders = new[] { fsh }, VertexAttributeNames = new[] { "in_position", "in_velocity", "in_timeToAction", "in_type", "in_color" }, TransformFeedbackAttributeNames = new[] { "g_position", "g_velocity", "g_timeToAction", "g_type", "g_color" }, TransformFeedbackMode = TransformFeedbackMode.InterleavedAttribs, UniformBufferNames = new[] { "Time" } }); }
public SpriteBatchRenderer(IDevice device, IBlobReader blobReader, ICameraFactory cameraFactory) { _device = device; _context = _device.ImmediateContext; _camera = cameraFactory.CreateOrhographicCamera(); _buffer = device.CreateVertexBuffer <Vertex2D>(MaxVertices, BufferUsage.Dynamic, BufferAccessFlags.Write); _indices = device.CreateIndexBuffer(CreateIndices()); _sampler = device.CreateSampler(true); _blendState = device.CreateBlendState(); _cameraBuffer = device.CreateConstantBuffer(new Camera { Transform = _camera.ViewProjection }); using var vertexShaderBlob = blobReader.ReadFromFile("Shaders/VertexShader2D.cso"); _vertexShader = device.CreateVertexShader(vertexShaderBlob); using var pixelShaderBlob = blobReader.ReadFromFile("Shaders/PixelShader2D.cso"); _pixelShader = device.CreatePixelShader(pixelShaderBlob); _inputLayout = device.CreateInputLayout(new VertexLayout(3).Append("Position", VertexLayoutTypes.Position2D).Append("Textures", VertexLayoutTypes.Texture2D).Append("Color", VertexLayoutTypes.Float4Color), vertexShaderBlob); }
private static IVertexLayout CreateVertexLayout(IDevice device, IVertexShader vertexShader) { return device.Create.VertexLayout(vertexShader, new[] { new VertexLayoutElement(ExplicitFormat.R32G32_FLOAT, 0, 0), new VertexLayoutElement(ExplicitFormat.R32G32_FLOAT, 0, 2 * sizeof(float)), new VertexLayoutElement(ExplicitFormat.R32G32B32_FLOAT, 0, 4 * sizeof(float)), new VertexLayoutElement(ExplicitFormat.R32_FLOAT, 0, 7 * sizeof(float)), }); }
/// <summary> /// Creates a new instance of an <see cref="EffectEntity"/>. /// </summary> /// <param name="vs">Vertex shader to use.</param> /// <param name="ps">Pixel shader to use.</param> public EffectEntity(IVertexShader vs, IPixelShader ps) { throw new NotImplementedException("So far ;-)!"); //this.effect = new Effect.XmlEffect(vs, ps); }
public ShaderPipeline(IVertexShader vertexShader, IFragmentShader fragmentShader) { VertexShader = vertexShader; FragmentShader = fragmentShader; }
/// Set the vertex shader. public void SetVertexShader(IVertexShader shader) { m_shader = shader; }
/// Constructor. public VertexProcessor(IRasterizer rasterizer) { m_rasterizer = rasterizer; m_shader = new NullVertexShader(); }
public override void Initialize() { renderTarget = Context.Create.Texture2D(RenderTargetSize, RenderTargetSize, TextureHelper.CalculateMipCount(RenderTargetSize, 1, 1), Format.Rgba8); depthStencil = Context.Create.Renderbuffer(RenderTargetSize, RenderTargetSize, Format.Depth24Stencil8); framebuffer = Context.Create.Framebuffer(); framebuffer.AttachTextureImage(FramebufferAttachmentPoint.Color0, renderTarget, 0); framebuffer.AttachRenderbuffer(FramebufferAttachmentPoint.DepthStencil, depthStencil); var vertexBuffer = Context.Create.Buffer(BufferTarget.Array, 24 * 8 * sizeof(float), BufferUsageHint.StaticDraw, new[] { new Vertex(1f, -1f, 1f, 1f, 0f, 0f, 0f, 0f), new Vertex(1f, 1f, 1f, 1f, 0f, 0f, 1f, 0f), new Vertex(1f, 1f, -1f, 1f, 0f, 0f, 1f, 1f), new Vertex(1f, -1f, -1f, 1f, 0f, 0f, 0f, 1f), new Vertex(1f, 1f, 1f, 0f, 1f, 0f, 0f, 0f), new Vertex(-1f, 1f, 1f, 0f, 1f, 0f, 1f, 0f), new Vertex(-1f, 1f, -1f, 0f, 1f, 0f, 1f, 1f), new Vertex(1f, 1f, -1f, 0f, 1f, 0f, 0f, 1f), new Vertex(-1f, 1f, 1f, -1f, 0f, 0f, 0f, 0f), new Vertex(-1f, -1f, 1f, -1f, 0f, 0f, 1f, 0f), new Vertex(-1f, -1f, -1f, -1f, 0f, 0f, 1f, 1f), new Vertex(-1f, 1f, -1f, -1f, 0f, 0f, 0f, 1f), new Vertex(-1f, -1f, 1f, 0f, -1f, 0f, 0f, 0f), new Vertex(1f, -1f, 1f, 0f, -1f, 0f, 1f, 0f), new Vertex(1f, -1f, -1f, 0f, -1f, 0f, 1f, 1f), new Vertex(-1f, -1f, -1f, 0f, -1f, 0f, 0f, 1f), new Vertex(-1f, -1f, 1f, 0f, 0f, 1f, 0f, 0f), new Vertex(-1f, 1f, 1f, 0f, 0f, 1f, 1f, 0f), new Vertex(1f, 1f, 1f, 0f, 0f, 1f, 1f, 1f), new Vertex(1f, -1f, 1f, 0f, 0f, 1f, 0f, 1f), new Vertex(-1f, 1f, -1f, 0f, 0f, -1f, 0f, 0f), new Vertex(-1f, -1f, -1f, 0f, 0f, -1f, 1f, 0f), new Vertex(1f, -1f, -1f, 0f, 0f, -1f, 1f, 1f), new Vertex(1f, 1f, -1f, 0f, 0f, -1f, 0f, 1f) }); var indexBuffer = Context.Create.Buffer(BufferTarget.ElementArray, 36 * sizeof(ushort), BufferUsageHint.StaticDraw, new ushort[] { 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, 8, 9, 10, 8, 10, 11, 12, 13, 14, 12, 14, 15, 16, 17, 18, 16, 18, 19, 20, 21, 22, 20, 22, 23 }); vertexArray = Context.Create.VertexArray(); vertexArray.SetElementArrayBuffer(indexBuffer); vertexArray.SetVertexAttributeF(0, vertexBuffer, VertexAttributeDimension.Three, VertexAttribPointerType.Float, false, 32, 0); vertexArray.SetVertexAttributeF(1, vertexBuffer, VertexAttributeDimension.Three, VertexAttribPointerType.Float, false, 32, 12); vertexArray.SetVertexAttributeF(2, vertexBuffer, VertexAttributeDimension.Two, VertexAttribPointerType.Float, false, 32, 24); transformBuffer = Context.Create.Buffer(BufferTarget.Uniform, 64, BufferUsageHint.DynamicDraw); cameraBuffer = Context.Create.Buffer(BufferTarget.Uniform, 64, BufferUsageHint.DynamicDraw); #if INTEL_WORKAROUND cameraOutsideBuffer = Context.Create.Buffer(BufferTarget.Uniform, 64, BufferUsageHint.DynamicDraw); #endif cameraExtraBuffer = Context.Create.Buffer(BufferTarget.Uniform, 12, BufferUsageHint.DynamicDraw); lightBuffer = Context.Create.Buffer(BufferTarget.Uniform, 12, BufferUsageHint.DynamicDraw); using (var textureLoader = new TextureLoader("../Textures/DiffuseTest.png")) { diffuseMap = Context.Create.Texture2D(textureLoader.Width, textureLoader.Height, TextureHelper.CalculateMipCount(textureLoader.Width, textureLoader.Height, 1), Format.Rgba8); for (int i = 0; i < diffuseMap.MipCount; i++) { diffuseMap.SetData(i, textureLoader.GetMipData(i), FormatColor.Rgba, FormatType.UnsignedByte); } } sampler = Context.Create.Sampler(); sampler.SetMagFilter(TextureMagFilter.Linear); sampler.SetMinFilter(TextureMinFilter.LinearMipmapLinear); sampler.SetMaxAnisotropy(16f); IVertexShader vsh = Context.Create.VertexShader(VertexShaderText); IFragmentShader fsh = Context.Create.FragmentShader(FragmentShaderText); program = Context.Create.Program(new ShaderProgramDescription { VertexShaders = new[] { vsh }, FragmentShaders = new[] { fsh }, VertexAttributeNames = new[] { "in_position", "in_normal", "in_tex_coord" }, UniformBufferNames = new[] { "Transform", "Camera", "Light" }, SamplerNames = new[] { "DiffuseMap" } }); }