private void SetupConstantBuffers() { perObjectConstantShaderBuffer = new D3D11.Buffer(deviceResources.Device, SharpDX.Utilities.SizeOf <PerObjectBuffer>(), D3D11.ResourceUsage.Default, D3D11.BindFlags.ConstantBuffer, D3D11.CpuAccessFlags.None, D3D11.ResourceOptionFlags.None, 0); perFrameConstantShaderBuffer = new D3D11.Buffer(deviceResources.Device, SharpDX.Utilities.SizeOf <PerFrameBuffer>(), D3D11.ResourceUsage.Default, D3D11.BindFlags.ConstantBuffer, D3D11.CpuAccessFlags.None, D3D11.ResourceOptionFlags.None, 0); perObjectBuffer = new PerObjectBuffer(); perFrameBuffer = new PerFrameBuffer(); }
private void UpdatePerObjectBuffer(Matrix modelMatrix, Camera cam) { // Transpose to get Column Major matrixes for Shader Matrix world = Matrix.Transpose(modelMatrix); Matrix view = Matrix.Transpose(cam.View); Matrix proj = Matrix.Transpose(cam.Proj); Matrix mvp = proj * view * world; perObjectBuffer = new PerObjectBuffer(); perObjectBuffer.world = world; perObjectBuffer.view = view; perObjectBuffer.proj = proj; perObjectBuffer.worldViewProj = mvp; perObjectBuffer.normalMatrix = Matrix.Invert(Matrix.Transpose(world)); perObjectBuffer.invProj = Matrix.Invert(proj); deviceResources.DeviceContext.UpdateSubresource(ref perObjectBuffer, perObjectConstantShaderBuffer); }