예제 #1
0
        public unsafe void SetVertexShaderConstants(DeviceContext deviceContext, SharpDX.Matrix world, SharpDX.Matrix viewProjection, Vector3 lightPosition)
        {
            // hlsl matrices are default column order
            var constants = new VSConstantBuffer();

            for (int i = 0, col = 0; col < 4; col++)
            {
                for (int row = 0; row < 4; row++)
                {
                    constants.world[i]          = world[row, col];
                    constants.viewProjection[i] = viewProjection[row, col];
                    i++;
                }
            }

            for (int i = 0; i < 3; i++)
            {
                constants.lightPosition[i] = lightPosition[i];
            }

            DataStream dataStream;

            deviceContext.MapSubresource(vertexShaderConstantBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out dataStream);
            dataStream.Write <VSConstantBuffer>(constants);
            deviceContext.UnmapSubresource(vertexShaderConstantBuffer, 0);
        }
예제 #2
0
        public unsafe void SetVertexShaderConstants(DeviceContext deviceContext, SharpDX.Matrix world, SharpDX.Matrix viewProjection, SharpDX.Matrix inverseProjection)
        {
            // hlsl matrices are default column order
            var constants = new VSConstantBuffer();
            for (int i = 0, col = 0; col < 4; col++)
            {
                for (int row = 0; row < 4; row++)
                {
                    constants.world[i] = world[row, col];
                    constants.viewProjection[i] = viewProjection[row, col];
                    constants.inverseProjection[i] = inverseProjection[row, col];
                    i++;
                }
            }

            DataStream dataStream;
            deviceContext.MapSubresource(vertexShaderConstantBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out dataStream);
            dataStream.Write<VSConstantBuffer>(constants);
            deviceContext.UnmapSubresource(vertexShaderConstantBuffer, 0);
        }