public virtual void Render(DeviceContext context, SharpDX.Direct3D.PrimitiveTopology type, int size, uint offset) { context.InputAssembler.InputLayout = Layout; context.VertexShader.Set(VertexShader); context.PixelShader.Set(PixelShader); context.PixelShader.SetSampler(0, SamplerState); context.DrawIndexed(size, (int)offset, 0); }
public override void Render(DeviceContext deviceContext, SharpDX.Direct3D.PrimitiveTopology type, int numTriangles, uint offset) { deviceContext.InputAssembler.InputLayout = Layout; deviceContext.VertexShader.Set(VertexShader); deviceContext.PixelShader.Set(PixelShader); deviceContext.PixelShader.SetSampler(0, SamplerState); deviceContext.DrawIndexed((int)numTriangles, (int)offset, 0); }
public void Draw(DeviceContext dc, int subsetId) { const int offset = 0; dc.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_vb, _vertexStride, offset)); dc.InputAssembler.SetIndexBuffer(_ib, SharpDX.DXGI.Format.R32_UInt, 0); dc.DrawIndexed(_subsetTable[subsetId].FaceCount * 3, _subsetTable[subsetId].FaceStart * 3, 0); }
public void Render(DeviceContext deviceContext, Transform transform) { Material.Render(deviceContext, transform.WorldMatrix); deviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(m_vertexBuffer, m_sizePerVertex, 0)); deviceContext.InputAssembler.SetIndexBuffer(m_indexBuffer, SharpDX.DXGI.Format.R32_UInt, 0); deviceContext.InputAssembler.PrimitiveTopology = m_primitiveTopology; deviceContext.DrawIndexed(m_indexCount, 0, 0); }
public static void RenderFullscreenGrid(DeviceContext context, int quadCount) { context.InputAssembler.InputLayout = null; context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding()); context.InputAssembler.SetIndexBuffer(m_FullResTriangleGridIndexBuffer, Format.R32_UInt, 0); context.DrawIndexed(6 * quadCount, 0, 0); }
void RenderShader(DeviceContext deviceContext, int indexCount) { deviceContext.InputAssembler.InputLayout = inputLayout; deviceContext.VertexShader.Set(vertexShader); deviceContext.PixelShader.Set(pixelShader); deviceContext.PixelShader.SetSampler(0, samplerState); deviceContext.DrawIndexed(indexCount, 0, 0); }
/// <summary> /// /// </summary> /// <param name="indexCount"></param> /// <param name="firstIndex"></param> /// <param name="baseVertexOffset"></param> public void DrawIndexed(int indexCount, int firstIndex, int baseVertexOffset) { lock (deviceContext) { ApplyGpuState(); //deviceContext.InputAssembler.PrimitiveTopology = Converter.Convert( primitive ); deviceContext.DrawIndexed(indexCount, firstIndex, baseVertexOffset); } }
public static void DrawAllPasses(this EffectTechnique tech, DeviceContext context, int indexCount) { for (var i = 0; i < tech.Description.PassCount; i++) { tech.GetPassByIndex(i).Apply(context); context.DrawIndexed(indexCount, 0, 0); } }
public void RenderWithMaterial(DeviceContext deviceContext, CMaterial material) { System.Diagnostics.Debug.Assert(material != null); material.Render(deviceContext, Matrix.Multiply(Transform.WorldMatrix, ParentTransform.LocalMatrix)); deviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(m_vertexBuffer, m_sizePerVertex, 0)); deviceContext.InputAssembler.SetIndexBuffer(m_indexBuffer, SharpDX.DXGI.Format.R32_UInt, 0); deviceContext.InputAssembler.PrimitiveTopology = m_primitiveTopology; deviceContext.DrawIndexed(m_indexCount, 0, 0); }
public void Draw(DeviceContext context) { context.InputAssembler.InputLayout = InputLayout; context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; context.InputAssembler.SetVertexBuffers(0, vbbinding); context.InputAssembler.SetIndexBuffer(IndexBuffer, Format.R32_UInt, 0); context.DrawIndexed(indexcount, 0, 0); }
public void Render(DeviceContext deviceContext, int indexCount, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix) { UpdateMatrixBuffer(deviceContext, ConstantMatrixBuffer, worldMatrix, viewMatrix, projectionMatrix); deviceContext.VertexShader.SetConstantBuffer(0, ConstantMatrixBuffer); deviceContext.InputAssembler.InputLayout = Layout; deviceContext.VertexShader.Set(VertexShader); deviceContext.PixelShader.Set(PixelShader); deviceContext.DrawIndexed(indexCount, 0, 0); }
public void Render(DeviceContext deviceContext, int indexCount, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix) { UpdateMatrixBuffer(deviceContext, ConstantMatrixBuffer, worldMatrix, viewMatrix, projectionMatrix); deviceContext.VertexShader.SetConstantBuffer(0, ConstantMatrixBuffer); deviceContext.InputAssembler.InputLayout = Layout; deviceContext.VertexShader.Set(VertexShader); deviceContext.PixelShader.Set(PixelShader); deviceContext.DrawIndexed(indexCount, 0, 0); }
public void Draw(ViewModel VM, PrimitiveTopology primitiveTopology = PrimitiveTopology.TriangleList, bool isBlending = false, int startIndex = 0, int baseVetex = 0) { //Установка шейдеров _dx11DeviceContext.VertexShader.Set(_vertexShader); _dx11DeviceContext.PixelShader.Set(_pixelShader); _dx11DeviceContext.GeometryShader.Set(_GShader); _dx11DeviceContext.HullShader.Set(_HShader); _dx11DeviceContext.DomainShader.Set(_DShader); //Устанавливаем самплер текстуры для шейдера _dx11DeviceContext.PixelShader.SetSampler(0, _samplerState); //Задаем тип рисуемых примитивов _dx11DeviceContext.InputAssembler.PrimitiveTopology = primitiveTopology; //Устанавливаем макет для входных данных видеокарты. В нем указано какие данные ожидает шейдер _dx11DeviceContext.InputAssembler.InputLayout = _inputLayout; //Перенос данных буферов в видеокарту _dx11DeviceContext.InputAssembler.SetVertexBuffers(0, VM.VertexBinging); _dx11DeviceContext.InputAssembler.SetIndexBuffer(VM.IndexBuffer, SharpDX.DXGI.Format.R32_UInt, 0); if (VM.ConstantBuffers != null) { for (int i = 0; i < VM.ConstantBuffers.Length; ++i) { _dx11DeviceContext.VertexShader.SetConstantBuffer(i, VM.ConstantBuffers?[i]); _dx11DeviceContext.PixelShader.SetConstantBuffer(i, VM.ConstantBuffers?[i]); _dx11DeviceContext.GeometryShader.SetConstantBuffer(i, VM.ConstantBuffers?[i]); _dx11DeviceContext.DomainShader.SetConstantBuffer(i, VM.ConstantBuffers?[i]); _dx11DeviceContext.HullShader.SetConstantBuffer(i, VM.ConstantBuffers?[i]); } } if (VM.Textures != null) { for (int i = 0; i < VM.Textures.Length; ++i) { //Отправляем текстуру в шейдер _dx11DeviceContext.PixelShader.SetShaderResource(i, VM.Textures?[i]); } } // _dx11DeviceContext.PixelShader.SetShaderResources(0, 1, VM.Textures); _dx11DeviceContext.OutputMerger.SetBlendState(null, null); if (isBlending) { _dx11DeviceContext.OutputMerger.SetBlendState(_blendState, BlendFactor); } //Рисуем в буффер нашего свайпчейна _dx11DeviceContext.DrawIndexed(VM.DrawedVertexCount, startIndex, baseVetex); _dx11DeviceContext.VertexShader.Set(null); _dx11DeviceContext.PixelShader.Set(null); _dx11DeviceContext.GeometryShader.Set(null); _dx11DeviceContext.HullShader.Set(null); _dx11DeviceContext.DomainShader.Set(null); }
void RenderLight(Light light) { lightWorldVar.SetMatrixTranspose(light.World); lightPositionRadiusVar.Set(new Vector4(light.Position, light.Radius)); lightColorVar.Set(light.Color); lightAccumulationPass.Apply(_immediateContext); _immediateContext.DrawIndexed(pointLightVolumeIndices.Length, 0, 0); }
//public int VertexCount; public void Draw(DeviceContext context) { context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; context.InputAssembler.SetIndexBuffer(IndexBuffer, global::SlimDX.DXGI.Format.R32_UInt, 0); //Using int indexbuffers context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(VertexBuffer, DeferredMeshVertex.SizeInBytes, 0)); context.DrawIndexed(PrimitiveCount * 3, 0, 0); //drawCalls = DrawCalls + 1; }
public void DrawAllPasses(DeviceContext context, int indexCount) { Initialize(); for (var i = 0; i < _passCount; i++) { _passes[i].Apply(context); context.DrawIndexed(indexCount, 0, 0); } }
private void RenderShader(DeviceContext deviceContext, int indexCount) { deviceContext.InputAssembler.InputLayout = _layout; deviceContext.VertexShader.Set(_vertexShader); deviceContext.PixelShader.Set(_pixelShader); deviceContext.DrawIndexed(indexCount, 0, 0); return; }
public void Draw(DeviceContext context) { if (buffer == null) { return; } context.InputAssembler.SetIndexBuffer(buffer, SharpDX.DXGI.Format.R32_UInt, 0); context.DrawIndexed(count, 0, 0); }
protected override void DoRender(DeviceContext context) { // Tell the IA we are using triangles context.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList; // Set the index buffer context.InputAssembler.SetIndexBuffer(indexBuffer, Format.R32_UInt, 0); // Pass in the quad vertices (note: only 4 vertices) context.InputAssembler.SetVertexBuffers(0, vertexBinding); // Draw the 36 vertices that make up the two triangles in the quad // using the vertex indices var perObject = new ConstantBuffers.PerObject(); angle = (float)Math.PI * 2 * time * (ID % 2); // move only sphere with even IDs if (angle >= 2 * Math.PI) { angle = 0; } time += 0.016f / 60f; if (time >= 1f) { time = 0; } perObject.World = World * Matrix.RotationY((float)angle) * Scene.Model; perObject.WorldInverseTranspose = Matrix.Transpose(Matrix.Invert(perObject.World)); perObject.WorldViewProjection = perObject.World * Scene.ViewProjection; perObject.Transpose(); context.UpdateSubresource(ref perObject, PerObjectBuffer); var perMaterial = new ConstantBuffers.PerMaterial { Ambient = Color.SaddleBrown, Diffuse = Color.White, Emissive = Color.Black, Specular = Color.White, SpecularPower = 100, HasTexture = 0, UVTransform = Matrix.Identity }; if (EnvironmentMap != null) { perMaterial.IsReflective = reflectionAmount > 0 ? 1u : 0; perMaterial.ReflectionAmount = reflectionAmount; context.PixelShader.SetShaderResource(1, EnvironmentMap.EnvMapSRV); } context.UpdateSubresource(ref perMaterial, PerMaterialBuffer); context.DrawIndexed(totalVertexCount, 0, 0); if (EnvironmentMap != null) { context.PixelShader.SetShaderResource(1, null); } // Note: we have called DrawIndexed so that the index buffer will be used }
public void RenderNoMaterials(DeviceContext context) { // configure the Input Assembler portion of the pipeline with the vertex data context.InputAssembler.InputLayout = m_SceneInputLayout; context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(m_VertexBuffer, 8 * sizeof(System.Single), 0)); context.InputAssembler.SetIndexBuffer(m_IndexBuffer, Format.R32_UInt, 0); context.DrawIndexed(m_ObjectLoader.m_MaterialIndices[m_ObjectLoader.m_MaterialIndices.Count - 1], 0, 0); }
private void DrawingArm(DeviceContext context) { //Prepare DirectX rendering pipeline context.ClearDepthStencilView(_d3dEngine.DepthStencilTarget, DepthStencilClearFlags.Depth, 1.0f, 0); RenderStatesRepo.ApplyStates(context, DXStates.Rasters.Default, DXStates.Blenders.Disabled, DXStates.DepthStencils.DepthReadWriteEnabled); //Compute a "world matrix" for displaying the Arm var screenPosition = Matrix.RotationX(MathHelper.Pi * 1.3f) * Matrix.RotationY(MathHelper.Pi * 0.01f) * //Some rotations Matrix.Scaling(1.7f) * //Adjusting scale Matrix.Translation(0.1f, -1, 0) * //Translation Matrix.Invert(_camManager.ActiveCamera.View_focused) * //Keep the Arm On screen Matrix.Translation(_camManager.ActiveCamera.LookAt.ValueInterp * 2.5f); //Project the arm in the lookat Direction = Inside the screen //Prepare Effect _voxelModelEffect.Begin(context); _voxelModelEffect.CBPerFrame.Values.ViewProjection = Matrix.Transpose(_camManager.ActiveCamera.ViewProjection3D_focused); _voxelModelEffect.CBPerFrame.IsDirty = true; //Assign model variables values _voxelModelEffect.CBPerModel.Values.World = Matrix.Transpose(Matrix.Scaling(1f / 16) * screenPosition); _voxelModelEffect.CBPerModel.Values.LightColor = _lightColor.ValueInterp; _voxelModelEffect.CBPerModel.IsDirty = true; //Don't use the GetTransform of the Part because its linked to the entity body, here we have only the arm to display. _voxelModelEffect.CBPerPart.Values.Transform = Matrix.Transpose(Matrix.Identity); _voxelModelEffect.CBPerPart.IsDirty = true; //Assign color mappings var colorMapping = _player.ModelInstance.VoxelModel.Frames[_handState.ActiveFrame].ColorMapping; if (colorMapping != null) { _voxelModelEffect.CBPerModel.Values.ColorMapping = colorMapping.BlockColors; } else { _voxelModelEffect.CBPerModel.Values.ColorMapping = _player.ModelInstance.VoxelModel.ColorMapping.BlockColors; } _voxelModelEffect.CBPerModel.IsDirty = true; //Assign buffers var vb = _handVisualVoxelModel.VertexBuffer; var ib = _handVisualVoxelModel.IndexBuffer; vb.SetToDevice(context, 0); ib.SetToDevice(context, 0); //Push Effect _voxelModelEffect.Apply(context); //Draw ! context.DrawIndexed(ib.IndicesCount, 0, 0); }
void DrawMesh(Matrix v, Matrix p, RenderTargetView rv, DepthStencilView dv, Viewport vp, ModelSDX model, ShaderResourceView map) { _dx11DeviceContext.InputAssembler.InputLayout = _layout; _dx11DeviceContext.OutputMerger.SetRenderTargets(dv, rv); _dx11DeviceContext.Rasterizer.SetViewport(vp); _dx11DeviceContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList; SetStates(); _pf.World = World * model.World; _pf.WVP = World * model.World * v * p; _pf.CameraPosition = Matrix.Transpose(Matrix.Invert(v)).Column4.ToVector3(); _pf.Trn(); _dx11DeviceContext.UpdateSubresource(ref _pf, _c0); _dx11DeviceContext.PixelShader.Set(_PS1); _dx11DeviceContext.VertexShader.Set(_VS1); _dx11DeviceContext.VertexShader.SetConstantBuffer(0, _c0); _dx11DeviceContext.PixelShader.SetConstantBuffer(0, _c0); _dx11DeviceContext.GeometryShader.Set(null); _dx11DeviceContext.HullShader.Set(null); _dx11DeviceContext.DomainShader.Set(null); _dx11DeviceContext.ComputeShader.Set(null); foreach (var m in model.Meshes3D) { _pm.HasTexture = m?.Texture == null ? 0u : 1u; _dx11DeviceContext.UpdateSubresource(ref _pm, _c1); _dx11DeviceContext.PixelShader.SetConstantBuffer(1, _c1); _dx11DeviceContext.VertexShader.SetConstantBuffer(1, _c1); _dx11DeviceContext.PixelShader.SetShaderResource(0, m.Texture); _dx11DeviceContext.PixelShader.SetShaderResource(1, map); _dx11DeviceContext.InputAssembler.SetVertexBuffers(0, m.VertexBinding); _dx11DeviceContext.InputAssembler.SetIndexBuffer(m.IndexBuffer, Format.R32_UInt, 0); _dx11DeviceContext.DrawIndexed(m.IndexCount, 0, 0); _dx11DeviceContext.PixelShader.SetShaderResource(1, null); } }
public void Draw() { context.InputAssembler.InputLayout = layout; context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer, Vertex. SizeInBytes, 0)); context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; context.InputAssembler.SetIndexBuffer(indexBuffer, SlimDX.DXGI.Format.R16_UInt, 0); context.DrawIndexed(6 * 2 * 3, 0, 0); }
private void RenderShader(DeviceContext deviceContext, int indexCount) { // Set the vertex input layout. deviceContext.InputAssembler.InputLayout = Layout; // Set the vertex and pixel shaders that will be used to render this triangle. deviceContext.VertexShader.Set(VertexShader); deviceContext.PixelShader.Set(PixelShader); // Render the triangle. deviceContext.DrawIndexed(indexCount, 0, 0); }
public void Draw(float elapsedTime, Matrix view, Matrix projection, Matrix world, DeviceContext context) { basicEffect.World = world; basicEffect.View = view; basicEffect.Projection = projection; basicEffect.Apply(context); context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertices, VertexPositionNormalTexture.Size, 0)); context.InputAssembler.SetIndexBuffer(indices, Format.R32_UInt, 0); context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; context.DrawIndexed(indexCount, 0, 0); }
/// <summary> /// スプライトを描画する /// </summary> /// <param name="immediateContext">DeviceContextポインタ。</param> /// <param name="pass">EffectPassポインタ。</param> /// <param name="drawSprite">基本描画スプライト</param> /// <return>通常、エラーが発生しなかった場合は MC_S_OK を返す。</return> public int Render(DeviceContext immediateContext, EffectPass pass, MCDrawSpriteBase drawSprite) { int[] strides = new int[] { System.Runtime.InteropServices.Marshal.SizeOf(new MC_VERTEX_PCTx()) }; int[] offsets = new int[] { 0 }; SharpDX.Direct3D11.Buffer[] vertexBuffers = new SharpDX.Direct3D11.Buffer[] { m_vertexBuffer }; immediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; immediateContext.InputAssembler.SetVertexBuffers(0, vertexBuffers, strides, offsets); immediateContext.InputAssembler.SetIndexBuffer(m_indexBuffer, SharpDX.DXGI.Format.R16_UInt, 0); immediateContext.DrawIndexed(m_drawTriangleNum * 3, 0, 0); return(0); }
public void Render(DeviceContext deviceContext, int indexCount, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, Texture texture, Vector2 translation) { worldMatrix.Transpose(); viewMatrix.Transpose(); projectionMatrix.Transpose(); // Lock the constant memory buffer so it can be written to. DataStream mappedResource; deviceContext.MapSubresource(ConstantMatrixBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource); // Copy the transposed matrices (because they are stored in column-major order on the GPU by default) into the constant buffer. var matrixBuffer = new MatrixBuffer { world = worldMatrix, view = viewMatrix, projection = projectionMatrix }; mappedResource.Write(matrixBuffer); // Unlock the constant buffer. deviceContext.UnmapSubresource(ConstantMatrixBuffer, 0); deviceContext.MapSubresource(ConstantTranslationBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource); mappedResource.Write(new TranslationBuffer { translation = translation }); deviceContext.UnmapSubresource(ConstantMatrixBuffer, 0); // Set the position of the constant buffer in the vertex shader. const int bufferNumber = 0; // Finally set the constant buffer in the vertex shader with the updated values. deviceContext.VertexShader.SetConstantBuffer(bufferNumber, ConstantMatrixBuffer); deviceContext.PixelShader.SetConstantBuffer(0, ConstantTranslationBuffer); // Set shader resource in the pixel shader. deviceContext.PixelShader.SetShaderResource(0, texture.TextureResource); // Set the vertex input layout. deviceContext.InputAssembler.InputLayout = Layout; // Set the vertex and pixel shaders that will be used to render this triangle. deviceContext.VertexShader.Set(VertexShader); deviceContext.PixelShader.Set(PixelShader); // Set the sampler state in the pixel shader. deviceContext.PixelShader.SetSampler(0, SamplerState); // Render the triangle. deviceContext.DrawIndexed(indexCount, 0, 0); }
public void Render(DeviceContext context, VSBuffer cpuBuffer, Buffer vsBuffer) { context.UpdateSubresource(ref cpuBuffer, vsBuffer); context.UpdateSubresource(GetAllTriangleVertices(), vertexBuffer); context.UpdateSubresource(GetBezierVertices(), springBuffer); if (DrawCube) { context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; context.InputAssembler.SetIndexBuffer(triangleIndices, Format.R32_UInt, 0); context.InputAssembler.SetVertexBuffers(0, vertexBinding); context.DrawIndexed(triangleIndicesArray.Length, 0, 0); } if (DrawSprings) { context.InputAssembler.PrimitiveTopology = PrimitiveTopology.LineList; context.InputAssembler.SetIndexBuffer(springIndices, Format.R32_UInt, 0); context.InputAssembler.SetVertexBuffers(0, springBinding); context.DrawIndexed(springIndicesArray.Length, 0, 0); } }
public void Render() { devCon.InputAssembler.InputLayout = layout; devCon.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; devCon.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertices, Utilities.SizeOf <Vector4>() * 2, 0)); devCon.InputAssembler.SetIndexBuffer(indices, Format.R32_UInt, 0); devCon.VertexShader.Set(vShader); devCon.VertexShader.SetConstantBuffer(0, cBuffer); devCon.PixelShader.Set(pShader); devCon.DrawIndexed(36, 0, 0); }
public void Render(DeviceContext context, VSBuffer cpuBuffer, Buffer vsBuffer) { if (!Draw) { return; } context.UpdateSubresource(ref cpuBuffer, vsBuffer); context.InputAssembler.PrimitiveTopology = PrimitiveTopology.LineList; context.InputAssembler.SetIndexBuffer(indexBuffer, Format.R16_UInt, 0); context.InputAssembler.SetVertexBuffers(0, vertexBinding); context.DrawIndexed(24, 0, 0); }
private void DrawChunkWithIndices(Chunk chunk) { if (chunk.Texture != null) { shader.SetDiffuseTexture(chunk.Texture); } deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; deviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(nativeVertexBuffer, vertexSize, 0)); deviceContext.InputAssembler.SetIndexBuffer(nativeIndexBuffer, Format.R16_UInt, chunk.FirstIndexOffsetInBytes); deviceContext.DrawIndexed(chunk.NumberOfIndices, 0, 0); }
public override void Render(DeviceContext deviceContext, OrthogonalCamera camera) { if (!_isVisible) { return; } Matrix view = camera.View; Matrix projection = camera.Projection; float top = Math.Max(_downPos.Y, _curPos.Y); float bottom = Math.Min(_downPos.Y, _curPos.Y); float left = Math.Min(_downPos.X, _curPos.X); float right = Math.Max(_downPos.X, _curPos.X); Matrix world = Matrix.Identity; world.M11 = right - left; world.M22 = top - bottom; world.M41 = left; world.M42 = bottom; Matrix worldViewProjection; Matrix.Multiply(ref world, ref view, out worldViewProjection); Matrix.Multiply(ref worldViewProjection, ref projection, out worldViewProjection); // Transpose local Matrices Matrix.Transpose(ref worldViewProjection, out worldViewProjection); deviceContext.VertexShader.SetConstantBuffers(0, _globalBuffer); deviceContext.PixelShader.SetConstantBuffers(0, _globalBuffer); deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; deviceContext.InputAssembler.InputLayout = _inputLayout; deviceContext.VertexShader.Set(_vertexShader); deviceContext.HullShader.Set(null); deviceContext.DomainShader.Set(null); deviceContext.PixelShader.Set(_pixelShader); deviceContext.InputAssembler.SetIndexBuffer(_indexBuffer, Format.R32_UInt, 0); deviceContext.InputAssembler.SetVertexBuffers(0, _bufferBinding); DataStream dataStream; deviceContext.MapSubresource(_globalBuffer, 0, MapMode.WriteDiscard, MapFlags.None, out dataStream); dataStream.Write(worldViewProjection); dataStream.Write(_color.Vector4); deviceContext.UnmapSubresource(_globalBuffer, 0); deviceContext.DrawIndexed(6, 0, 0); }
public void Draw(DeviceContext context) { foreach (var mesh in _meshes) { if (mesh.PrimitiveTopology != PrimitiveTopology.TriangleList) continue; // TODO context.InputAssembler.InputLayout = mesh.InputLayout; context.InputAssembler.PrimitiveTopology = mesh.PrimitiveTopology; context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(mesh.VertexBuffer, 0, mesh.VertexSize)); context.InputAssembler.SetIndexBuffer(mesh.IndexBuffer, Format.R32_UInt, 0); context.PixelShader.SetShaderResources(0, mesh.DiffuseTextureView); context.DrawIndexed(mesh.IndexCount, 0, 0); } }
//Go through the meshes and render them public void Render(DeviceContext context) { if (!m_inputLayoutSet) throw new Exception("Model::Render(): input layout has not be specified, you must call SetInputLayout() before calling Render()"); foreach (ModelMesh mesh in m_meshes) { //set mesh specific data context.InputAssembler.InputLayout = mesh.InputLayout; context.InputAssembler.PrimitiveTopology = mesh.PrimitiveTopology; context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(mesh.VertexBuffer, mesh.VertexSize, 0)); context.InputAssembler.SetIndexBuffer(mesh.IndexBuffer, Format.R32_UInt, 0); context.PixelShader.SetShaderResource(0, mesh.DiffuseTextureView); //draw context.DrawIndexed(mesh.IndexCount, 0, 0); } }
public void Draw(DeviceContext dc, CameraBase camera) { var eyePos = camera.Position; var t = Matrix.Translation(eyePos); var wvp = t * camera.ViewProj; Effects.SkyFX.SetWorldViewProj(wvp); Effects.SkyFX.SetCubeMap(_cubeMapSRV); var stride = Marshal.SizeOf(typeof(Vector3)); const int Offset = 0; dc.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_vb, stride, Offset)); dc.InputAssembler.SetIndexBuffer(_ib, Format.R32_UInt, 0); dc.InputAssembler.InputLayout = InputLayouts.Pos; dc.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; var tech = Effects.SkyFX.SkyTech; for (var p = 0; p < tech.Description.PassCount; p++) { var pass = tech.GetPassByIndex(p); pass.Apply(dc); dc.DrawIndexed(_indexCount, 0, 0); } }
public void Draw(GeometricPrimitive Primitive, DeviceContext Context) { Context.InputAssembler.PrimitiveTopology = Topology; if (Primitive is SkinnedMeshPrimitive) Context.InputAssembler.InputLayout = SkinnedMeshInputLayout; else Context.InputAssembler.InputLayout = StaticMeshInputLayout; Context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(Primitive.GeometryData.VertexBuffer, Primitive.GeometryData.VertexStride, 0)); Context.InputAssembler.SetIndexBuffer(Primitive.GeometryData.IndexBuffer, Format.R16_UInt, 0); Context.DrawIndexed(Primitive.GeometryData.IndexCount, 0, 0); }
public void Render(DeviceContext deviceContext, int indexCount, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, ShaderResourceView borderTexture, ShaderResourceView provinceColorTexture) { UpdateMatrixBuffer(deviceContext, ConstantMatrixBuffer, worldMatrix, viewMatrix, projectionMatrix); deviceContext.InputAssembler.InputLayout = Layout; deviceContext.VertexShader.Set(VertexShader); deviceContext.VertexShader.SetConstantBuffer(0, ConstantMatrixBuffer); deviceContext.PixelShader.Set(PixelShader); deviceContext.PixelShader.SetSampler(0, SamplerStateBorder); deviceContext.PixelShader.SetSampler(1, SamplerStateColor); deviceContext.PixelShader.SetShaderResource(0, borderTexture); deviceContext.PixelShader.SetShaderResource(1, provinceColorTexture); deviceContext.DrawIndexed(indexCount, 0, 0); }
public static void Render(Device device, DeviceContext context, ShaderResourceView resourceView, SamplerState SSDiffuse, bool InvertUV) { context.InputAssembler.InputLayout = EEEM.layout; context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; context.InputAssembler.SetVertexBuffers(0, _MConteints.binding); context.InputAssembler.SetIndexBuffer(_MConteints.Indices, Format.R32_UInt, 0); //renderTechnique.GetPassByIndex(0).Apply(context); if (!InvertUV) EEEM.renderTechniques[0].GetPassByIndex(0).Apply(context); else EEEM.renderTechniques[0].GetPassByIndex(1).Apply(context); context.PixelShader.SetShaderResource(0, resourceView); context.PixelShader.SetSampler(0, SSDiffuse); var dataBox = ModelViewer.Program.context.MapSubresource(constantsBuffer, 0, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None); Utilities.Write(dataBox.DataPointer, ref constants); ModelViewer.Program.context.UnmapSubresource(constantsBuffer, 0); //Константный буффер передается шейдерам device.ImmediateContext.VertexShader.SetConstantBuffer(0, constantsBuffer); device.ImmediateContext.PixelShader.SetConstantBuffer(0, constantsBuffer); context.DrawIndexed(6, 0, 0); }
public void Render(DeviceContext context, vsBuffer vsBuffer, psBuffer psBuffer) { context.InputAssembler.InputLayout = layout; if (isTesselated) { context.InputAssembler.PrimitiveTopology = PrimitiveTopology.PatchListWith3ControlPoints; } else { context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; } context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(mesh.vertexBuffer, mesh._vertexStream.vertexType.SizeOf(), 0)); context.InputAssembler.SetIndexBuffer(mesh.indexBuffer, SharpDX.DXGI.Format.R16_UInt, 0); context.VertexShader.Set(_shaderSolution.vs); for (int i = 0; i < _shaderSolution.shaders_buffers[Shaders.VertexShader].Length; i++) { context.VertexShader.SetConstantBuffer(i, _shaderSolution.shaders_buffers[Shaders.VertexShader][i]); } context.PixelShader.Set(_shaderSolution.ps); for (int i = 0; i < _shaderSolution.shaders_buffers[Shaders.PixelShader].Length; i++) { context.PixelShader.SetConstantBuffer(i, _shaderSolution.shaders_buffers[Shaders.PixelShader][i]); } if (this.isTesselated) { context.HullShader.Set(_shaderSolution.hs); for (int i = 0; i < _shaderSolution.shaders_buffers[Shaders.HullShader].Length; i++) { context.HullShader.SetConstantBuffer(i, _shaderSolution.shaders_buffers[Shaders.HullShader][i]); } context.DomainShader.Set(_shaderSolution.ds); for (int i = 0; i < _shaderSolution.shaders_buffers[Shaders.DomainShader].Length; i++) { context.DomainShader.SetConstantBuffer(i, _shaderSolution.shaders_buffers[Shaders.DomainShader][i]); } context.UpdateSubresource(ref vsBuffer, _shaderSolution.shaders_buffers[Shaders.DomainShader][0]); } else { context.HullShader.Set(null); context.DomainShader.Set(null); } for(int i = 0; i<material.textures.Count; i++) { context.PixelShader.SetShaderResource(i, material.textures[i]); } context.UpdateSubresource(ref vsBuffer, _shaderSolution.shaders_buffers[Shaders.VertexShader][0]); // !!!!!!!!!!!!!!!!!!!!!!! not normal (be careful of shader being optimized and stripped of unused constant buffer) //context.UpdateSubresource(ref psBuffer, _shaderSolution.shaders_buffers[Shaders.PixelShader][0]); context.PixelShader.SetSampler(0, sampler); context.DrawIndexed(mesh._indexStream.getIndexCount(), 0, 0); }
public void Draw(DeviceContext dc, Vector3 camPos ) { if (IB.Count == 0) { BuildIndices(dc.Device); } var tessLevel = TessFactor(camPos); dc.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_vb, TerrainCP.Stride, 0)); dc.InputAssembler.SetIndexBuffer(IB[tessLevel], Format.R16_UInt, 0); dc.DrawIndexed(IndexCount[tessLevel], 0, 0); }
public void Draw(DeviceContext dc) { var stride = Basic32.Stride; const int Offset = 0; dc.InputAssembler.InputLayout = InputLayouts.Basic32; dc.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; dc.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(D3DApp.GD3DApp.ScreenQuadVB, stride, Offset)); dc.InputAssembler.SetIndexBuffer(D3DApp.GD3DApp.ScreenQuadIB, Format.R32_UInt, 0); // transform from our [0,1] screen cordinates to NDC var world = new Matrix { M11 = Size.X, M22 = Size.Y, M33 = 1.0f, M41 = -1.0f + 2 * ScreenPosition.X + (Size.X), M42 = 1.0f - 2 * ScreenPosition.Y - (Size.Y), M44 = 1.0f }; var tech = Effects.DebugTexFX.ViewArgbTech; for (int p = 0; p < tech.Description.PassCount; p++) { Effects.DebugTexFX.SetWorldViewProj(world); Effects.DebugTexFX.SetTexture(MinimapSRV); tech.GetPassByIndex(p).Apply(dc); dc.DrawIndexed(6, 0, 0); } }
public void Draw(DeviceContext Context) { Context.InputAssembler.PrimitiveTopology = MaterialShader.Topology; if (this is SkinnedMeshPrimitive) Context.InputAssembler.InputLayout = MaterialShader.SkinnedMeshInputLayout; else Context.InputAssembler.InputLayout = MaterialShader.StaticMeshInputLayout; Context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(GeometryData.VertexBuffer, GeometryData.VertexStride, 0)); Context.InputAssembler.SetIndexBuffer(GeometryData.IndexBuffer, SlimDX.DXGI.Format.R16_UInt, 0); Context.DrawIndexed(GeometryData.IndexCount, 0, 0); }
public void Render(DeviceContext context) { context.InputAssembler.InputLayout = layout; context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(mesh.vertexBuffer, mesh._vertexStream.vertexType.SizeOf(), 0)); context.InputAssembler.SetIndexBuffer(mesh.indexBuffer, SharpDX.DXGI.Format.R16_UInt, 0); context.VertexShader.Set(_shaderSolution.vs); context.PixelShader.Set(_shaderSolution.ps); context.HullShader.Set(null); context.DomainShader.Set(null); for(int i = 0; i<material.textures.Count; i++) { context.PixelShader.SetShaderResource(i, material.textures[i]); } context.PixelShader.SetSampler(0, sampler); context.DrawIndexed(mesh._indexStream.getIndexCount(), 0, 0); context.PixelShader.SetShaderResource(0, null); }
/// <summary> /// Draws using the current <see cref="DeviceContext"/>, after the data has been bound. /// </summary> /// <param name="context">The context to draw from.</param> /// <param name="num">The number of indicies to draw.</param> private void RenderShader(DeviceContext context, int num) { context.DrawIndexed(num, 0, 0); }
public void Render(DeviceContext deviceContext, int indexCount, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, ShaderResourceView texture) { worldMatrix.Transpose(); viewMatrix.Transpose(); projectionMatrix.Transpose(); // Lock the constant memory buffer so it can be written to. DataStream mappedResource; deviceContext.MapSubresource(ConstantMatrixBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource); // Copy the transposed matrices (because they are stored in column-major order on the GPU by default) into the constant buffer. var matrixBuffer = new MatrixBuffer { world = worldMatrix, view = viewMatrix, projection = projectionMatrix }; mappedResource.Write(matrixBuffer); // Unlock the constant buffer. deviceContext.UnmapSubresource(ConstantMatrixBuffer, 0); // Set the position of the constant buffer in the vertex shader. const int bufferNumber = 0; // Finally set the constant buffer in the vertex shader with the updated values. deviceContext.VertexShader.SetConstantBuffer(bufferNumber, ConstantMatrixBuffer); // Set shader resource in the pixel shader. deviceContext.PixelShader.SetShaderResource(0, texture); // Set the vertex input layout. deviceContext.InputAssembler.InputLayout = Layout; // Set the vertex and pixel shaders that will be used to render this triangle. deviceContext.VertexShader.Set(VertexShader); deviceContext.PixelShader.Set(PixelShader); // Set the sampler state in the pixel shader. deviceContext.PixelShader.SetSampler(0, SamplerState); // Render the triangle. deviceContext.DrawIndexed(indexCount, 0, 0); }
public void Render(DeviceContext deviceContext, int indexCount, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, Texture texture, Light light, ICamera camera) { DataStream mappedResource; UpdateMatrixBuffer(deviceContext, ConstantMatrixBuffer, worldMatrix, viewMatrix, projectionMatrix); deviceContext.MapSubresource(ConstantLightBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource); mappedResource.Write( new LightBuffer { ambiantColor = light.AmbiantColor, diffuseColor = light.Color, direction = light.Direction, specularPower = light.SpecularPower, specularColor = light.SpecularColor }); deviceContext.UnmapSubresource(ConstantLightBuffer, 0); deviceContext.MapSubresource(ConstantCameraBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource); mappedResource.Write( new CameraBuffer { cameraPosition = camera.Position }); deviceContext.UnmapSubresource(ConstantCameraBuffer, 0); deviceContext.VertexShader.SetConstantBuffer(0, ConstantMatrixBuffer); deviceContext.VertexShader.SetConstantBuffer(1, ConstantCameraBuffer); deviceContext.PixelShader.SetConstantBuffer(0, ConstantLightBuffer); deviceContext.PixelShader.SetShaderResource(0, texture.TextureResource); deviceContext.InputAssembler.InputLayout = Layout; deviceContext.VertexShader.Set(VertexShader); deviceContext.PixelShader.Set(PixelShader); deviceContext.PixelShader.SetSampler(0, SamplerState); deviceContext.DrawIndexed(indexCount, 0, 0); }
private void DrawHierarchy(List<ObjectNode> nodes, int materialIndex, DeviceContext devContext, int depth) { if (depth > 1212) { return; } foreach (var node in nodes) { if (node.DrawGroup != null && node.Enabled) { foreach (var group in node.DrawGroup) { if (group.materialIndex == materialIndex) { devContext.DrawIndexed(group.indexCount, group.startIndex, 0); } } } DrawHierarchy(node.Children, materialIndex, devContext, depth + 1); } }
public static void DrawAllPasses(this EffectTechnique tech, DeviceContext context, int indexCount) { for (var i = 0; i < tech.Description.PassCount; i++) { tech.GetPassByIndex(i).Apply(context); context.DrawIndexed(indexCount, 0, 0); } }
//Draw internal void Draw(DeviceContext context) { context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(VertexBuffer, VertexFormat.Size, 0)); context.InputAssembler.SetIndexBuffer(IndexBuffer, SharpDX.DXGI.Format.R32_UInt, 0); context.DrawIndexed(IndexCount, 0, 0); }
public void ComputeSsao(DeviceContext dc, CameraBase cam, Ssao ssao, DepthStencilView depthStencilView) { ssao.SetNormalDepthRenderTarget(depthStencilView); dc.InputAssembler.PrimitiveTopology = PrimitiveTopology.PatchListWith4ControlPoints; dc.InputAssembler.InputLayout = InputLayouts.TerrainCP; var stride = TerrainCP.Stride; const int offset = 0; dc.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_quadPatchVB, stride, offset)); dc.InputAssembler.SetIndexBuffer(_quadPatchIB, Format.R16_UInt, 0); var viewProj = cam.ViewProj; var planes = cam.FrustumPlanes; Effects.TerrainFX.SetViewProj(viewProj); Effects.TerrainFX.SetEyePosW(cam.Position); Effects.TerrainFX.SetMinDist(MinDist); Effects.TerrainFX.SetMaxDist(MaxDist); Effects.TerrainFX.SetMinTess(MinTess); Effects.TerrainFX.SetMaxTess(MaxTess); Effects.TerrainFX.SetTexelCellSpaceU(1.0f / Info.HeightMapWidth); Effects.TerrainFX.SetTexelCellSpaceV(1.0f / Info.HeightMapHeight); Effects.TerrainFX.SetWorldCellSpace(Info.CellSpacing); Effects.TerrainFX.SetWorldFrustumPlanes(planes); Effects.TerrainFX.SetHeightMap(_heightMapSRV); Effects.TerrainFX.SetView(cam.View); var tech = Effects.TerrainFX.NormalDepthTech; for (int p = 0; p < tech.Description.PassCount; p++) { var pass = tech.GetPassByIndex(p); pass.Apply(dc); dc.DrawIndexed(_numPatchQuadFaces * 4, 0, 0); } dc.HullShader.Set(null); dc.DomainShader.Set(null); ssao.ComputeSsao(cam); ssao.BlurAmbientMap(4); }
public void Render(DeviceContext deviceContext, int indexCount, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, ShaderResourceView terrain, ShaderResourceView water) { UpdateMatrixBuffer(deviceContext, ConstantMatrixBuffer, worldMatrix, viewMatrix, projectionMatrix); deviceContext.VertexShader.SetConstantBuffer(0, ConstantMatrixBuffer); deviceContext.VertexShader.SetShaderResource(0, terrain); deviceContext.VertexShader.SetShaderResource(1, water); deviceContext.VertexShader.SetSampler(1,VertexSamplerState); deviceContext.PixelShader.SetShaderResource(0, terrain); deviceContext.PixelShader.SetShaderResource(1, water); deviceContext.InputAssembler.InputLayout = Layout; deviceContext.VertexShader.Set(VertexShader); deviceContext.PixelShader.Set(PixelShader); deviceContext.PixelShader.SetSampler(0, SamplerState); deviceContext.DrawIndexed(indexCount, 0, 0); }
public void Draw(DeviceContext dc, CameraBase cam, DirectionalLight[] lights) { if (_useTessellation) { dc.InputAssembler.PrimitiveTopology = PrimitiveTopology.PatchListWith4ControlPoints; dc.InputAssembler.InputLayout = InputLayouts.TerrainCP; var stride = TerrainCP.Stride; const int offset = 0; dc.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_quadPatchVB, stride, offset)); dc.InputAssembler.SetIndexBuffer(_quadPatchIB, Format.R16_UInt, 0); var viewProj = cam.ViewProj; var planes = cam.FrustumPlanes; var toTexSpace = Matrix.Scaling(0.5f, -0.5f, 1.0f) * Matrix.Translation(0.5f, 0.5f, 0); Effects.TerrainFX.SetViewProj(viewProj); Effects.TerrainFX.SetEyePosW(cam.Position); Effects.TerrainFX.SetDirLights(lights); Effects.TerrainFX.SetFogColor(Color.Silver); Effects.TerrainFX.SetFogStart(15.0f); Effects.TerrainFX.SetFogRange(175.0f); Effects.TerrainFX.SetMinDist(MinDist); Effects.TerrainFX.SetMaxDist(MaxDist); Effects.TerrainFX.SetMinTess(MinTess); Effects.TerrainFX.SetMaxTess(MaxTess); Effects.TerrainFX.SetTexelCellSpaceU(1.0f / Info.HeightMapWidth); Effects.TerrainFX.SetTexelCellSpaceV(1.0f / Info.HeightMapHeight); Effects.TerrainFX.SetWorldCellSpace(Info.CellSpacing); Effects.TerrainFX.SetWorldFrustumPlanes(planes); Effects.TerrainFX.SetLayerMapArray(_layerMapArraySRV); Effects.TerrainFX.SetBlendMap(_blendMapSRV); Effects.TerrainFX.SetHeightMap(_heightMapSRV); Effects.TerrainFX.SetMaterial(_material); Effects.TerrainFX.SetViewProjTex(viewProj * toTexSpace); var tech = Shadows ? Effects.TerrainFX.Light1ShadowTech: Effects.TerrainFX.Light1Tech; for (int p = 0; p < tech.Description.PassCount; p++) { var pass = tech.GetPassByIndex(p); pass.Apply(dc); dc.DrawIndexed(_numPatchQuadFaces * 4, 0, 0); } dc.HullShader.Set(null); dc.DomainShader.Set(null); if (DebugBvh) { DrawBVHDebug(dc, cam, offset); } } else { dc.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; dc.InputAssembler.InputLayout = InputLayouts.TerrainCP; var viewProj = cam.ViewProj; Effects.TerrainFX.SetViewProj(viewProj); Effects.TerrainFX.SetEyePosW(cam.Position); Effects.TerrainFX.SetDirLights(lights); Effects.TerrainFX.SetFogColor(Color.Silver); Effects.TerrainFX.SetFogStart(15.0f); Effects.TerrainFX.SetFogRange(175.0f); Effects.TerrainFX.SetTexelCellSpaceU(1.0f / Info.HeightMapWidth); Effects.TerrainFX.SetTexelCellSpaceV(1.0f / Info.HeightMapHeight); Effects.TerrainFX.SetWorldCellSpace(Info.CellSpacing); Effects.TerrainFX.SetLayerMapArray(_layerMapArraySRV); Effects.TerrainFX.SetBlendMap(_blendMapSRV); Effects.TerrainFX.SetHeightMap(_heightMapSRV); Effects.TerrainFX.SetMaterial(_material); var tech = Effects.TerrainFX.Light1TechNT; for (var p = 0; p < tech.Description.PassCount; p++) { var pass = tech.GetPassByIndex(p); pass.Apply(dc); for (var i = 0; i < _patches.Count; i++) { var patch = _patches[i]; if (cam.Visible(patch.Bounds)) { var ns = new Dictionary<NeighborDir, Patch>(); if (i < NumPatchVertCols) { ns[NeighborDir.Top] = null; } else { ns[NeighborDir.Top] = _patches[i - NumPatchVertCols + 1]; } if (i%(NumPatchVertCols - 1) == 0) { ns[NeighborDir.Left] = null; } else { ns[NeighborDir.Left] = _patches[i - 1]; } if (Util.IsKeyDown(Keys.N)) { patch.Draw(dc, cam.Position); } else { patch.Draw(dc, cam.Position, ns); } } } } } }
public void Draw(DeviceContext dc, Vector3 camPos, Dictionary<NeighborDir, Patch> neighbors) { var tessLevel = TessFactor(camPos); dc.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_vb, TerrainCP.Stride, 0)); dc.InputAssembler.SetIndexBuffer(CenterIB[tessLevel], Format.R16_UInt, 0); dc.DrawIndexed(CenterIndexCount[tessLevel], 0, 0); var topEdge = neighbors[NeighborDir.Top] != null ? neighbors[NeighborDir.Top].TessFactor(camPos) : tessLevel; var key = new Tuple<int, int>(tessLevel, topEdge); if (EdgeIbs[NeighborDir.Top].ContainsKey(key)) { dc.InputAssembler.SetIndexBuffer(EdgeIbs[NeighborDir.Top][key], Format.R16_UInt, 0); dc.DrawIndexed(EdgeIndiceCount[NeighborDir.Top][key], 0, 0); } var leftEdge = neighbors[NeighborDir.Left] != null ? neighbors[NeighborDir.Left].TessFactor(camPos) : tessLevel; key = new Tuple<int, int>(tessLevel, leftEdge); if (EdgeIbs[NeighborDir.Left].ContainsKey(key)) { dc.InputAssembler.SetIndexBuffer(EdgeIbs[NeighborDir.Left][key], Format.R16_UInt, 0); dc.DrawIndexed(EdgeIndiceCount[NeighborDir.Left][key], 0, 0); } }
public void DrawToShadowMap(DeviceContext dc, ShadowMap sMap, Matrix viewProj) { sMap.BindDsvAndSetNullRenderTarget(dc); dc.InputAssembler.PrimitiveTopology = PrimitiveTopology.PatchListWith4ControlPoints; dc.InputAssembler.InputLayout = InputLayouts.TerrainCP; var stride = TerrainCP.Stride; const int offset = 0; dc.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_quadPatchVB, stride, offset)); dc.InputAssembler.SetIndexBuffer(_quadPatchIB, Format.R16_UInt, 0); var frustum = Frustum.FromViewProj(viewProj); var planes = frustum.Planes; Effects.TerrainFX.SetViewProj(viewProj); Effects.TerrainFX.SetEyePosW(new Vector3(viewProj.M41, viewProj.M42, viewProj.M43)); Effects.TerrainFX.SetMinDist(MinDist); Effects.TerrainFX.SetMaxDist(MaxDist); Effects.TerrainFX.SetMinTess(MinTess); Effects.TerrainFX.SetMaxTess(MaxTess); Effects.TerrainFX.SetWorldCellSpace(Info.CellSpacing); Effects.TerrainFX.SetWorldFrustumPlanes(planes); Effects.TerrainFX.SetHeightMap(_heightMapSRV); var tech = Effects.TerrainFX.TessBuildShadowMapTech; for (int p = 0; p < tech.Description.PassCount; p++) { var pass = tech.GetPassByIndex(p); pass.Apply(dc); dc.DrawIndexed(_numPatchQuadFaces * 4, 0, 0); } dc.HullShader.Set(null); dc.DomainShader.Set(null); }
public void Render(DeviceContext deviceContext, int indexCount, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, ShaderResourceView bumpMap, ShaderResourceView borderTexture, Vector2 translation, Light light) { UpdateMatrixBuffer(deviceContext, ConstantMatrixBuffer, worldMatrix, viewMatrix, projectionMatrix); //Copy translation buffer to GPU DataStream mappedResource; deviceContext.MapSubresource(ConstantTranslationBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource); mappedResource.Write(new TranslationBuffer { translation = translation }); deviceContext.UnmapSubresource(ConstantTranslationBuffer, 0); deviceContext.MapSubresource(ConstantLightBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource); mappedResource.Write(new LightBuffer(light)); deviceContext.UnmapSubresource(ConstantLightBuffer, 0); deviceContext.InputAssembler.InputLayout = Layout; deviceContext.VertexShader.Set(VertexShader); deviceContext.VertexShader.SetConstantBuffer(0, ConstantMatrixBuffer); deviceContext.PixelShader.Set(PixelShader); deviceContext.PixelShader.SetConstantBuffer(1, ConstantTranslationBuffer); deviceContext.PixelShader.SetConstantBuffer(2, ConstantLightBuffer); deviceContext.PixelShader.SetSampler(0, SamplerStateWrap); deviceContext.PixelShader.SetSampler(1, SamplerStateBorder); deviceContext.PixelShader.SetShaderResource(0, bumpMap); deviceContext.PixelShader.SetShaderResource(1, borderTexture); deviceContext.DrawIndexed(indexCount, 0, 0); }
private void DrawBVHDebug(DeviceContext dc, CameraBase cam, int offset) { dc.InputAssembler.PrimitiveTopology = PrimitiveTopology.LineList; dc.InputAssembler.InputLayout = InputLayouts.PosColor; dc.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_bvhVB, VertexPC.Stride, offset)); dc.InputAssembler.SetIndexBuffer(_bvhIB, Format.R32_UInt, 0); //dc.OutputMerger.DepthStencilState = RenderStates.NoDepthDSS; Effects.ColorFX.SetWorldViewProj(cam.ViewProj); for (int p = 0; p < Effects.ColorFX.ColorTech.Description.PassCount; p++) { Effects.ColorFX.ColorTech.GetPassByIndex(p).Apply(dc); dc.DrawIndexed(_bvhIndices.Count, 0, 0); } dc.OutputMerger.DepthStencilState = null; }
public static void FinalRender(Device device, float TimeMili, DeviceContext context, ShaderResourceView DiffuseHDR, ShaderResourceView DepthMap, RenderTargetView renderTarget) { constants.Time = new Vector4(TimeMili, TimeMili, TimeMili, TimeMili)/1000f; ViewportF[] pre = context.Rasterizer.GetViewports(); context.InputAssembler.InputLayout = EEEM.layout; context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; context.InputAssembler.SetVertexBuffers(0, _MConteints.binding); context.InputAssembler.SetIndexBuffer(_MConteints.Indices, Format.R32_UInt, 0); var dataBox = context.MapSubresource(constantsBuffer, 0, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None); Utilities.Write(dataBox.DataPointer, ref constants); context.UnmapSubresource(constantsBuffer, 0); const bool boolHDR = true; if (boolHDR) { context.Rasterizer.SetViewports(DoubleHDRViewport); context.OutputMerger.SetTargets(BufRTV_3); EEEM.renderTechniques[5].GetPassByIndex(0).Apply(context); context.PixelShader.SetShaderResource(0, DiffuseHDR); context.PixelShader.SetSampler(0, BufSS); device.ImmediateContext.VertexShader.SetConstantBuffer(0, constantsBuffer); device.ImmediateContext.PixelShader.SetConstantBuffer(0, constantsBuffer); context.DrawIndexed(6, 0, 0); device.ImmediateContext.GenerateMips(BufSRV_3); /////////////////////////////////////////// //lerp context.Rasterizer.SetViewports(V1x1); context.OutputMerger.SetTargets(RTV1x1); EEEM.renderTechniques[7].GetPassByIndex(0).Apply(context); context.PixelShader.SetShaderResource(0, BufSRV_3); context.PixelShader.SetSampler(0, BufSS); device.ImmediateContext.VertexShader.SetConstantBuffer(0, constantsBuffer); device.ImmediateContext.PixelShader.SetConstantBuffer(0, constantsBuffer); context.DrawIndexed(6, 0, 0); ////////////////////////////////////////// context.Rasterizer.SetViewports(HDRViewport); context.OutputMerger.SetTargets(BufRTV_1); EEEM.renderTechniques[6].GetPassByIndex(0).Apply(context); context.PixelShader.SetShaderResource(0, BufSRV_3); context.PixelShader.SetSampler(0, BufSS); context.PixelShader.SetShaderResource(2, SRV1x1); device.ImmediateContext.VertexShader.SetConstantBuffer(0, constantsBuffer); device.ImmediateContext.PixelShader.SetConstantBuffer(0, constantsBuffer); context.DrawIndexed(6, 0, 0); ////////////////////////////////////////////////////////////////////////// context.Rasterizer.SetViewports(HDRViewport); context.OutputMerger.SetTargets(BufRTV_1); //context.ClearRenderTargetView(HDRTarget, new Color4(0.5f, 0.5f, 1.0f)); /* EEEM.renderTechniques[2].GetPassByIndex(0).Apply(context); context.PixelShader.SetShaderResource(0, BufSRV_2); context.PixelShader.SetSampler(0, BufSS); device.ImmediateContext.VertexShader.SetConstantBuffer(0, constantsBuffer); device.ImmediateContext.PixelShader.SetConstantBuffer(0, constantsBuffer); context.DrawIndexed(6, 0, 0); */ context.OutputMerger.SetTargets(BufRTV_2); EEEM.renderTechniques[3].GetPassByIndex(0).Apply(context); context.PixelShader.SetShaderResource(0, BufSRV_1); context.PixelShader.SetSampler(0, BufSS); device.ImmediateContext.VertexShader.SetConstantBuffer(0, constantsBuffer); device.ImmediateContext.PixelShader.SetConstantBuffer(0, constantsBuffer); context.DrawIndexed(6, 0, 0); context.OutputMerger.SetTargets(BufRTV_1); EEEM.renderTechniques[4].GetPassByIndex(0).Apply(context); context.PixelShader.SetShaderResource(0, BufSRV_2); context.PixelShader.SetSampler(0, BufSS); device.ImmediateContext.VertexShader.SetConstantBuffer(0, constantsBuffer); device.ImmediateContext.PixelShader.SetConstantBuffer(0, constantsBuffer); context.DrawIndexed(6, 0, 0); } context.Rasterizer.SetViewports(pre); context.OutputMerger.SetTargets(renderTarget); EEEM.renderTechniques[1].GetPassByIndex(0).Apply(context); context.PixelShader.SetShaderResource(0, DiffuseHDR); context.PixelShader.SetSampler(0, BufSS); context.PixelShader.SetShaderResource(1, BufSRV_1); context.PixelShader.SetShaderResource(2, SRV1x1); context.PixelShader.SetShaderResource(3, DepthMap); // context.PixelShader.SetSampler(0, BufSS); device.ImmediateContext.VertexShader.SetConstantBuffer(0, constantsBuffer); device.ImmediateContext.PixelShader.SetConstantBuffer(0, constantsBuffer); context.DrawIndexed(6, 0, 0); }
/// <summary> /// Draws our index buffer /// </summary> /// <param name="context">Device context</param> /// <param name="faceCount">Tracked face count</param> public void Draw(DeviceContext context, int faceCount) { context.DrawIndexed(faceCount * (int)FaceModel.TriangleCount * 3, 0, 0); }
private void RenderShader(DeviceContext deviceContext, int indexCount) { // Set the vertex input layout. deviceContext.InputAssembler.InputLayout = Layout; // Set the vertex and pixel shaders that will be used to render this triangle. deviceContext.VertexShader.Set(VertexShader); deviceContext.PixelShader.Set(PixelShader); // Set the sampler state in the pixel shader. deviceContext.PixelShader.SetSampler(0, SampleState); // Render the triangle. deviceContext.DrawIndexed(indexCount, 0, 0); }
public void Render(DeviceContext deviceContext, int indexCount, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, Light light, ShaderResourceView[] textures, Vector4 clippingPlane) { worldMatrix.Transpose(); viewMatrix.Transpose(); projectionMatrix.Transpose(); // Lock the constant memory buffer so it can be written to. DataStream mappedResource; deviceContext.MapSubresource(ConstantMatrixBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource); // Copy the transposed matrices (because they are stored in column-major order on the GPU by default) into the constant buffer. var matrixBuffer = new MatrixBuffer { world = worldMatrix, view = viewMatrix, projection = projectionMatrix }; mappedResource.Write(matrixBuffer); // Unlock the constant buffer. deviceContext.UnmapSubresource(ConstantMatrixBuffer, 0); deviceContext.MapSubresource(ConstantLightBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource); mappedResource.Write( new LightBuffer { ambiantColor = light.AmbiantColor, diffuseColor = light.Color, direction = light.Direction }); deviceContext.UnmapSubresource(ConstantLightBuffer, 0); deviceContext.MapSubresource(ConstantClippingPlaneBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource); mappedResource.Write( new ClippingPlaneBuffer {plane = clippingPlane}); deviceContext.UnmapSubresource(ConstantClippingPlaneBuffer, 0); // Finally set the constant buffers in the vertex shader with the updated values. deviceContext.VertexShader.SetConstantBuffer(0, ConstantMatrixBuffer); deviceContext.VertexShader.SetConstantBuffer(1, ConstantClippingPlaneBuffer); deviceContext.PixelShader.SetConstantBuffer(0, ConstantLightBuffer); deviceContext.PixelShader.SetShaderResources(0, textures); // Set the vertex input layout. deviceContext.InputAssembler.InputLayout = Layout; // Set the vertex and pixel shaders that will be used to render this triangle. deviceContext.VertexShader.Set(VertexShader); deviceContext.PixelShader.Set(PixelShader); deviceContext.PixelShader.SetSampler(0, SamplerState); // Render the triangles. deviceContext.DrawIndexed(indexCount, 0, 0); }