本文整理汇总了C#中MatrixBuffer类的典型用法代码示例。如果您正苦于以下问题:C# MatrixBuffer类的具体用法?C# MatrixBuffer怎么用?C# MatrixBuffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MatrixBuffer类属于命名空间,在下文中一共展示了MatrixBuffer类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: SetShaderParameters
private bool SetShaderParameters(DeviceContext deviceContext, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, ShaderResourceView texture)
{
try
{
// Transpose the matrices to prepare them for shader.
worldMatrix.Transpose();
viewMatrix.Transpose();
projectionMatrix.Transpose();
// Lock the constant buffer so it can be written to.
DataStream mappedResource;
deviceContext.MapSubresource(ConstantMatrixBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource);
// Copy the matrices 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.
var 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);
return true;
}
catch (Exception)
{
return false;
}
}
开发者ID:nyx1220,项目名称:sharpdx-examples,代码行数:42,代码来源:TextureShader.cs
示例2: SetShaderParameters
private bool SetShaderParameters(DeviceContext deviceContext, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, ShaderResourceView[] textures, Vector3 lightDirection, Vector4 diffuseColor, Vector3 cameraPosition, Vector4 specularColor, float specularPower)
{
try
{
#region Constant Matrix Buffer
// Transpose the matrices to prepare them for shader.
worldMatrix.Transpose();
viewMatrix.Transpose();
projectionMatrix.Transpose();
// Lock the constant buffer so it can be written to.
DataStream mappedResource;
deviceContext.MapSubresource(ConstantMatrixBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource);
// Copy the matrices 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.
var 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.SetShaderResources(0, textures);
#endregion
#region Constant Light Buffer
// Lock the light constant buffer so it can be written to.
deviceContext.MapSubresource(ConstantLightBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource);
// Copy the lighting variables into the constant buffer.
var lightBuffer = new LightBuffer()
{
diffuseColor = diffuseColor,
lightDirection = lightDirection,
specularColor = specularColor,
specularPower = specularPower,
};
mappedResource.Write(lightBuffer);
// Unlock the constant buffer.
deviceContext.UnmapSubresource(ConstantLightBuffer, 0);
// Set the position of the light constant buffer in the pixel shader.
bufferNumber = 0;
// Finally set the light constant buffer in the pixel shader with the updated values.
deviceContext.PixelShader.SetConstantBuffer(bufferNumber, ConstantLightBuffer);
#endregion
#region Constant Camera Buffer
// Lock the camera constant buffer so it can be written to.
deviceContext.MapSubresource(ConstantCameraBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource);
// Copy the lighting variables into the constant buffer.
var cameraBuffer = new CameraBuffer()
{
cameraPosition = cameraPosition,
padding = 0.0f
};
mappedResource.Write(cameraBuffer);
// Unlock the constant buffer.
deviceContext.UnmapSubresource(ConstantCameraBuffer, 0);
// Set the position of the light constant buffer in the pixel shader.
bufferNumber = 1;
// Now set the camera constant buffer in the vertex shader with the updated values.
deviceContext.VertexShader.SetConstantBuffer(bufferNumber, ConstantCameraBuffer);
#endregion
return true;
}
catch (Exception)
{
return false;
}
}
开发者ID:nyx1220,项目名称:sharpdx-examples,代码行数:92,代码来源:SpecMapShader.cs
示例3: Render
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);
}
开发者ID:ndech,项目名称:PlaneSimulator,代码行数:43,代码来源:TextureShader.cs
示例4: UpdateMatrixBuffer
unsafe void UpdateMatrixBuffer()
{
var mb = new MatrixBuffer() { View = viewMatrix, World = worldMatrix, Text = textMatrix};
deviceContext.UpdateSubresource(matrixBuffer, 0, null, (IntPtr)(&mb), 1, 0);
deviceContext.VertexShader.SetConstantBuffer(0, matrixBuffer);
}
开发者ID:Artentus,项目名称:GameUtils,代码行数:7,代码来源:Renderer_Layer0.cs
示例5: Render
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);
}
开发者ID:ndech,项目名称:PlaneSimulator,代码行数:57,代码来源:TerrainShader.cs
示例6: SetShaderParameters
private void SetShaderParameters(DrawEventArgs args)
{
Geometry shape = core.Actor.Shape;
if (core.UseTurntable)
{
float t = (float)args.TotalTime.TotalSeconds * core.TurntableSpeed;
core.Actor.Rotation = Quaternion.RotationAxis(VSTools.UnitY, t);
}
// Update matrices in the constant buffer
Matrix modelMatrix = Matrix.Scaling(core.Actor.LocalScale) * Matrix.RotationQuaternion(core.Actor.Rotation) * Matrix.Translation(core.Actor.Position);
MatrixBuffer projectionModel = new MatrixBuffer
{
World = Matrix.Transpose((Camera as VSViewerCamera).World),
View = Matrix.Transpose((Camera.View)),
Projection = Matrix.Transpose(Camera.Projection)
};
m_matrixBuffer.Value = projectionModel;
// Set Vertex shader resources
Device.ImmediateContext.VertexShader.SetConstantBuffer(0, m_matrixBuffer.Buffer);
Device.ImmediateContext.UpdateSubresource(shape.instancedVertices, vertexBuffer);
// Set pixel shader resources
Device.ImmediateContext.PixelShader.SetShaderResource(0, m_textureResourceView);
}
开发者ID:MercurialForge,项目名称:VSViewer,代码行数:27,代码来源:RenderSystem.cs
注:本文中的MatrixBuffer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论