本文整理汇总了C#中Device.CreateShaderResourceView方法的典型用法代码示例。如果您正苦于以下问题:C# Device.CreateShaderResourceView方法的具体用法?C# Device.CreateShaderResourceView怎么用?C# Device.CreateShaderResourceView使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Device
的用法示例。
在下文中一共展示了Device.CreateShaderResourceView方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShaderResourceView
/// <summary>
/// Creates a <see cref = "T:SharpDX.Direct3D11.ShaderResourceView" /> for accessing resource data.
/// </summary>
/// <param name = "device">The device to use when creating this <see cref = "T:SharpDX.Direct3D11.ShaderResourceView" />.</param>
/// <param name = "resource">The resource that represents the render-target surface. This surface must have been created with the <see cref = "T:SharpDX.Direct3D11.BindFlags">ShaderResource</see> flag.</param>
/// <param name = "description">A structure describing the <see cref = "T:SharpDX.Direct3D11.ShaderResourceView" /> to be created.</param>
/// <msdn-id>ff476519</msdn-id>
/// <unmanaged>HRESULT ID3D11Device::CreateShaderResourceView([In] ID3D11Resource* pResource,[In, Optional] const D3D11_SHADER_RESOURCE_VIEW_DESC* pDesc,[Out, Fast] ID3D11ShaderResourceView** ppSRView)</unmanaged>
/// <unmanaged-short>ID3D11Device::CreateShaderResourceView</unmanaged-short>
public ShaderResourceView(Device device, Resource resource, ShaderResourceViewDescription description)
: base(IntPtr.Zero)
{
device.CreateShaderResourceView(resource, description, this);
}
示例2: ImageGenerator
//.........这里部分代码省略.........
});
// Create the depth buffer view
_depthView = _device.CreateDepthStencilView(depthBuffer);
// Compile Vertex and Pixel shaders
var vertexShaderByteCode = ShaderCompiler.CompileFromFile("Modules/SampleBrowser/TechDemos/Resources/TextureSampling/Texture.fx", "VS", "vs_4_0");
var vertexShader = _device.CreateVertexShader(vertexShaderByteCode);
var pixelShaderByteCode = ShaderCompiler.CompileFromFile("Modules/SampleBrowser/TechDemos/Resources/TextureSampling/Texture.fx", "PS", "ps_4_1");
var pixelShader = _device.CreatePixelShader(pixelShaderByteCode);
// Layout from VertexShader input signature
var layout = _device.CreateInputLayout(
new[]
{
new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
new InputElement("TEXCOORD", 0, Format.R32G32_Float, 0, 16)
}, vertexShaderByteCode);
// Instantiate Vertex buiffer from vertex data
var vertices = _device.CreateBuffer(new BufferDescription(BindFlags.VertexBuffer), new[]
{
// 3D coordinates UV Texture coordinates
-1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f, // Front
-1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 0.0f,
1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 0.0f,
-1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f,
1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 0.0f,
1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f,
-1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 0.0f, // BACK
1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
-1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
-1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f, // Top
-1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
-1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f,
-1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 0.0f, // Bottom
1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
-1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
-1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 0.0f,
1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 0.0f,
1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
-1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f, // Left
-1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
-1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f,
-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
-1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f,
1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 0.0f, // Right
1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 0.0f,
1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 0.0f,
1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f
});
// Create Constant Buffer
_constantBuffer = _device.CreateBuffer(new BufferDescription
{
SizeInBytes = Utilities.SizeOf<Matrix>(),
BindFlags = BindFlags.ConstantBuffer
});
// Load texture and create sampler
var textureStream = resourceLoader.GetStream(
"Modules/SampleBrowser/TechDemos/Resources/TextureSampling/CorrodedTiles.png",
GetType().Assembly.FullName);
var texture = TextureLoader.CreateTextureFromStream(_device, textureStream);
var textureView = _device.CreateShaderResourceView(texture);
// Prepare all the stages
_deviceContext.InputAssembler.InputLayout = layout;
_deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
_deviceContext.InputAssembler.SetVertexBuffers(0,
new VertexBufferBinding(vertices, 0, Utilities.SizeOf<Vector4>() + Utilities.SizeOf<Vector2>()));
_deviceContext.VertexShader.SetConstantBuffers(0, _constantBuffer);
_deviceContext.VertexShader.Shader = vertexShader;
_deviceContext.PixelShader.Shader = pixelShader;
_deviceContext.PixelShader.SetShaderResources(0, textureView);
// Setup targets and viewport for rendering
_deviceContext.Rasterizer.SetViewports(new Viewport(0, 0, _outputBitmap.PixelWidth, _outputBitmap.PixelHeight, 0.0f, 1.0f));
_deviceContext.OutputMerger.SetTargets(_depthView, _renderTargetView);
// Prepare matrices
_view = Matrix.LookAtRH(new Vector3(0.7f, 0, -1.7f), Vector3.BackwardRH, Vector3.UnitY);
_projection = Matrix.PerspectiveFovRH(MathUtil.PiOverFour,
_outputBitmap.PixelWidth / (float) _outputBitmap.PixelHeight, 0.1f, 100.0f);
}
示例3: Initialize
//.........这里部分代码省略.........
new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
new InputElement("TEXCOORD", 0, Format.R32G32_Float, 0, 16)
}, vertexShaderByteCode);
// Instantiate Vertex buiffer from vertex data
var vertices = device.CreateBuffer(new BufferDescription(BindFlags.VertexBuffer), new[]
{
// 3D coordinates UV Texture coordinates
-1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f, // Front
-1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 0.0f,
1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 0.0f,
-1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f,
1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 0.0f,
1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f,
-1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 0.0f, // BACK
1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
-1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
-1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f, // Top
-1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
-1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f,
-1.0f,-1.0f, -1.0f, 1.0f, 1.0f, 0.0f, // Bottom
1.0f,-1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
-1.0f,-1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
-1.0f,-1.0f, -1.0f, 1.0f, 1.0f, 0.0f,
1.0f,-1.0f, -1.0f, 1.0f, 0.0f, 0.0f,
1.0f,-1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
-1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f, // Left
-1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
-1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f,
-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
-1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f,
1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 0.0f, // Right
1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 0.0f,
1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 0.0f,
1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f
});
// Create Constant Buffer
_constantBuffer = device.CreateBuffer(new BufferDescription
{
SizeInBytes = Utilities.SizeOf<Matrix>(),
BindFlags = BindFlags.ConstantBuffer
});
// Load texture and create sampler
var textureStream = _resourceLoader.GetStream(
"Modules/SampleBrowser/Samples/MiniCubeTexture/GeneticaMortarlessBlocks.jpg",
GetType().Assembly.FullName);
var texture = TextureLoader.CreateTextureFromStream(device, textureStream);
var textureView = device.CreateShaderResourceView(texture);
var sampler = device.CreateSamplerState(new SamplerStateDescription
{
Filter = Filter.MinMagMipPoint,
AddressU = TextureAddressMode.Wrap,
AddressV = TextureAddressMode.Wrap,
AddressW = TextureAddressMode.Wrap,
BorderColor = Color4.Black,
ComparisonFunction = Comparison.Never,
MaximumAnisotropy = 16,
MipLodBias = 0,
MinimumLod = 0,
MaximumLod = 16,
});
// Prepare all the stages
_deviceContext.InputAssembler.InputLayout = layout;
_deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
_deviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertices, 0, Utilities.SizeOf<Vector4>() + Utilities.SizeOf<Vector2>()));
_deviceContext.VertexShader.SetConstantBuffers(0, _constantBuffer);
_deviceContext.VertexShader.Shader = vertexShader;
_deviceContext.PixelShader.Shader = pixelShader;
_deviceContext.PixelShader.SetSamplers(0, sampler);
_deviceContext.PixelShader.SetShaderResources(0, textureView);
// Setup targets and viewport for rendering
_deviceContext.Rasterizer.SetViewports(new Viewport(0, 0, width, height, 0.0f, 1.0f));
_deviceContext.OutputMerger.SetTargets(_depthView, _renderTargetView);
// Prepare matrices
_view = Matrix.LookAtLH(new Vector3(0, 0, -5), Vector3.Zero, Vector3.UnitY);
_projection = Matrix.PerspectiveFovLH(MathUtil.PiOverFour,
width / (float) height, 0.1f, 100.0f);
return swapChainPresenter.Bitmap;
}
示例4: AddTextureDiffuse
public void AddTextureDiffuse(Device device, Texture2D texture)
{
DiffuseTexture = texture;
DiffuseTextureView = device.CreateShaderResourceView(DiffuseTexture);
}
示例5: Initialize
public override WriteableBitmap Initialize(Device device)
{
// Create device and swap chain.
var swapChainPresenter = new WpfSwapChainPresenter();
_swapChain = device.CreateSwapChain(Width, Height, swapChainPresenter);
_deviceContext = device.ImmediateContext;
// Create RenderTargetView from the backbuffer.
var backBuffer = Texture2D.FromSwapChain(_swapChain, 0);
_renderTargetView = device.CreateRenderTargetView(backBuffer);
// Create the depth buffer
var depthBuffer = device.CreateTexture2D(new Texture2DDescription
{
ArraySize = 1,
MipLevels = 1,
Width = Width,
Height = Height,
BindFlags = BindFlags.DepthStencil
});
// Create the depth buffer view
_depthView = device.CreateDepthStencilView(depthBuffer);
// Create cube map resources.
var cubeMapTexture = device.CreateTexture2D(new Texture2DDescription
{
Width = CubeMapSize,
Height= CubeMapSize,
ArraySize = 6,
BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
MipLevels = 1
});
_renderTargetViewCube = device.CreateRenderTargetView(cubeMapTexture);
_resourceViewCube = device.CreateShaderResourceView(cubeMapTexture);
var depthBufferCube = device.CreateTexture2D(new Texture2DDescription
{
ArraySize = 6,
MipLevels = 1,
Width = CubeMapSize,
Height = CubeMapSize,
BindFlags = BindFlags.DepthStencil
});
_depthViewCube = device.CreateDepthStencilView(depthBufferCube);
// Load model.
var modelLoader = new ModelLoader(device, TextureLoader.CreateTextureFromStream);
_model = modelLoader.Load("Modules/SampleBrowser/Samples/EnvironmentMapping/teapot.obj");
// Compile Vertex and Pixel shaders
var vertexShaderByteCode = ShaderCompiler.CompileFromFile("Modules/SampleBrowser/Samples/EnvironmentMapping/EnvironmentMapping.fx", "VS_CubeMap", "vs_4_0");
_vertexShaderCubeMap = device.CreateVertexShader(vertexShaderByteCode);
_vertexShaderStandard = device.CreateVertexShader(ShaderCompiler.CompileFromFile("Modules/SampleBrowser/Samples/EnvironmentMapping/EnvironmentMapping.fx", "VS_Standard", "vs_4_0"));
_geometryShaderCubeMap = device.CreateGeometryShader(ShaderCompiler.CompileFromFile("Modules/SampleBrowser/Samples/EnvironmentMapping/EnvironmentMapping.fx", "GS_CubeMap", "gs_4_0"));
_pixelShaderCubeMap = device.CreatePixelShader(ShaderCompiler.CompileFromFile("Modules/SampleBrowser/Samples/EnvironmentMapping/EnvironmentMapping.fx", "PS_CubeMap", "ps_4_0"));
_pixelShaderStandard = device.CreatePixelShader(ShaderCompiler.CompileFromFile("Modules/SampleBrowser/Samples/EnvironmentMapping/EnvironmentMapping.fx", "PS_Standard", "ps_4_0"));
_pixelShaderReflective = device.CreatePixelShader(ShaderCompiler.CompileFromFile("Modules/SampleBrowser/Samples/EnvironmentMapping/EnvironmentMapping.fx", "PS_Reflective", "ps_4_0"));
_model.SetInputLayout(device, vertexShaderByteCode.InputSignature);
var sampler = device.CreateSamplerState(SamplerStateDescription.Default);
// Create constant buffers.
_vertexConstantBuffer = device.CreateBuffer(new BufferDescription
{
SizeInBytes = Utilities.SizeOf<VertexShaderData>(),
BindFlags = BindFlags.ConstantBuffer
});
_geometryConstantBuffer = device.CreateBuffer(new BufferDescription
{
SizeInBytes = Utilities.SizeOf<GeometryShaderData>(),
BindFlags = BindFlags.ConstantBuffer
});
var pixelConstantBuffer = device.CreateBuffer(new BufferDescription
{
SizeInBytes = Utilities.SizeOf<PixelShaderData>(),
BindFlags = BindFlags.ConstantBuffer
});
// Prepare all the stages
_deviceContext.VertexShader.SetConstantBuffers(0, _vertexConstantBuffer);
_deviceContext.GeometryShader.SetConstantBuffers(0, _geometryConstantBuffer);
_deviceContext.PixelShader.SetConstantBuffers(0, pixelConstantBuffer);
_deviceContext.PixelShader.SetSamplers(0, sampler);
_vertexShaderData = new VertexShaderData();
_view1 = Matrix.LookAtLH(Vector3.Zero, new Vector3(1, 0, 0), Vector3.UnitY);
_view2 = Matrix.LookAtLH(Vector3.Zero, new Vector3(-1, 0, 0), Vector3.UnitY);
_view3 = Matrix.LookAtLH(Vector3.Zero, new Vector3(0, 1, 0), -Vector3.UnitZ);
_view4 = Matrix.LookAtLH(Vector3.Zero, new Vector3(0, -1, 0), Vector3.UnitZ);
_view5 = Matrix.LookAtLH(Vector3.Zero, new Vector3(0, 0, 1), Vector3.UnitY);
_view6 = Matrix.LookAtLH(Vector3.Zero, new Vector3(0, 0, -1), Vector3.UnitY);
var from = new Vector3(0, 30, 70);
var to = new Vector3(0, 0, 0);
// Prepare matrices
//.........这里部分代码省略.........