本文整理汇总了C#中SharpDX.Direct3D11.VertexShader类的典型用法代码示例。如果您正苦于以下问题:C# VertexShader类的具体用法?C# VertexShader怎么用?C# VertexShader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
VertexShader类属于SharpDX.Direct3D11命名空间,在下文中一共展示了VertexShader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TextureShader
public TextureShader(Device device)
{
var vertexShaderByteCode = ShaderBytecode.CompileFromFile(ShaderFileName, "TextureVertexShader", "vs_4_0", ShaderFlags);
var pixelShaderByteCode = ShaderBytecode.CompileFromFile(ShaderFileName, "TexturePixelShader", "ps_4_0", ShaderFlags);
VertexShader = new VertexShader(device, vertexShaderByteCode);
PixelShader = new PixelShader(device, pixelShaderByteCode);
Layout = VertexDefinition.PositionTexture.GetInputLayout(device, vertexShaderByteCode);
vertexShaderByteCode.Dispose();
pixelShaderByteCode.Dispose();
ConstantMatrixBuffer = new Buffer(device, MatrixBufferDesription);
// Create a texture sampler state description.
var samplerDesc = new SamplerStateDescription
{
Filter = Filter.Anisotropic,
AddressU = TextureAddressMode.Mirror,
AddressV = TextureAddressMode.Mirror,
AddressW = TextureAddressMode.Mirror,
MipLodBias = 0,
MaximumAnisotropy = 16,
ComparisonFunction = Comparison.Always,
BorderColor = new Color4(1, 1, 1, 1),
MinimumLod = 0,
MaximumLod = 0
};
// Create the texture sampler state.
SamplerState = new SamplerState(device, samplerDesc);
}
示例2: PathShader
public PathShader(Device device)
{
var vertexShaderByteCode = ShaderBytecode.CompileFromFile(FileName, "VS", "vs_4_0", ShaderFlags);
var pixelShaderByteCode = ShaderBytecode.CompileFromFile(FileName, "PS", "ps_4_0", ShaderFlags);
var geometryShaderByteCode = ShaderBytecode.CompileFromFile(FileName, "GS", "gs_4_0", ShaderFlags);
VertexShader = new VertexShader(device, vertexShaderByteCode);
PixelShader = new PixelShader(device, pixelShaderByteCode);
GeometryShader = new GeometryShader(device, geometryShaderByteCode);
Layout = VertexDefinition.Path.GetInputLayout(device, vertexShaderByteCode);
vertexShaderByteCode.Dispose();
pixelShaderByteCode.Dispose();
geometryShaderByteCode.Dispose();
ConstantMatrixBuffer = new Buffer(device, MatrixBufferDesription);
ConstantPathDataBuffer = new Buffer(device,
new BufferDescription
{
Usage = ResourceUsage.Dynamic,
SizeInBytes = Utilities.SizeOf<PathData>(),
BindFlags = BindFlags.ConstantBuffer,
CpuAccessFlags = CpuAccessFlags.Write,
OptionFlags = ResourceOptionFlags.None,
StructureByteStride = 0
});
SamplerState = new SamplerState(device, WrapSamplerStateDescription);
}
示例3: FilterPixelShader
public FilterPixelShader(Device device, int imageWidth, int imageHeight, int constantBufferSize, string pixelShaderBytecodeFilename)
{
vertexShader = new VertexShader(device, new ShaderBytecode(File.ReadAllBytes("Content/FullScreenQuadVS.cso")));
pixelShader = new PixelShader(device, new ShaderBytecode(File.ReadAllBytes(pixelShaderBytecodeFilename)));
var rasterizerStateDesc = new RasterizerStateDescription()
{
CullMode = CullMode.None,
FillMode = FillMode.Solid,
IsDepthClipEnabled = false,
IsFrontCounterClockwise = true,
IsMultisampleEnabled = false,
};
rasterizerState = new RasterizerState(device, rasterizerStateDesc);
if (constantBufferSize > 0)
{
var constantBufferDesc = new BufferDescription()
{
Usage = ResourceUsage.Dynamic,
BindFlags = BindFlags.ConstantBuffer,
SizeInBytes = constantBufferSize,
CpuAccessFlags = CpuAccessFlags.Write,
StructureByteStride = 0,
OptionFlags = 0,
};
constantBuffer = new Buffer(device, constantBufferDesc);
}
viewport = new Viewport(0, 0, imageWidth, imageHeight); // TODO: get these dimensions
vertexBufferBinding = new VertexBufferBinding(null, 0, 0);
}
示例4: Shader
private Shader(GraphicsDevice device, ShaderStage shaderStage, byte[] shaderBytecode)
: base(device)
{
this.stage = shaderStage;
switch (shaderStage)
{
case ShaderStage.Vertex:
NativeDeviceChild = new VertexShader(device.NativeDevice, shaderBytecode);
NativeInputSignature = shaderBytecode;
break;
case ShaderStage.Hull:
NativeDeviceChild = new HullShader(device.NativeDevice, shaderBytecode);
break;
case ShaderStage.Domain:
NativeDeviceChild = new DomainShader(device.NativeDevice, shaderBytecode);
break;
case ShaderStage.Geometry:
NativeDeviceChild = new GeometryShader(device.NativeDevice, shaderBytecode);
break;
case ShaderStage.Pixel:
NativeDeviceChild = new PixelShader(device.NativeDevice, shaderBytecode);
break;
case ShaderStage.Compute:
NativeDeviceChild = new ComputeShader(device.NativeDevice, shaderBytecode);
break;
default:
throw new ArgumentOutOfRangeException("shaderStage");
}
}
示例5: PhysicsDebugDraw
public PhysicsDebugDraw(DeviceManager manager)
{
device = manager.Direct3DDevice;
inputAssembler = device.ImmediateContext.InputAssembler;
lineArray = new PositionColored[0];
using (var bc = HLSLCompiler.CompileFromFile(@"Shaders\PhysicsDebug.hlsl", "VSMain", "vs_5_0"))
{
vertexShader = new VertexShader(device, bc);
InputElement[] elements = new InputElement[]
{
new InputElement("SV_POSITION", 0, Format.R32G32B32_Float, 0, 0, InputClassification.PerVertexData, 0),
new InputElement("COLOR", 0, Format.R8G8B8A8_UNorm, 12, 0, InputClassification.PerVertexData, 0)
};
inputLayout = new InputLayout(device, bc, elements);
}
vertexBufferDesc = new BufferDescription()
{
Usage = ResourceUsage.Dynamic,
BindFlags = BindFlags.VertexBuffer,
CpuAccessFlags = CpuAccessFlags.Write
};
vertexBufferBinding = new VertexBufferBinding(null, PositionColored.Stride, 0);
using (var bc = HLSLCompiler.CompileFromFile(@"Shaders\PhysicsDebug.hlsl", "PSMain", "ps_5_0"))
pixelShader = new PixelShader(device, bc);
}
示例6: WorldTerrainShader
public WorldTerrainShader(Device device)
{
var vertexShaderByteCode = ShaderBytecode.CompileFromFile(ShaderFileName, "TerrainVertexShader", "vs_4_0", ShaderFlags);
var pixelShaderByteCode = ShaderBytecode.CompileFromFile(ShaderFileName, "TerrainPixelShader", "ps_4_0", ShaderFlags);
VertexShader = new VertexShader(device, vertexShaderByteCode);
PixelShader = new PixelShader(device, pixelShaderByteCode);
Layout = VertexDefinition.PositionTexture.GetInputLayout(device, vertexShaderByteCode);
vertexShaderByteCode.Dispose();
pixelShaderByteCode.Dispose();
ConstantMatrixBuffer = new Buffer(device, MatrixBufferDesription);
var samplerDescMap = new SamplerStateDescription
{
Filter = Filter.MinMagMipPoint,
AddressU = TextureAddressMode.Clamp,
AddressV = TextureAddressMode.Clamp,
AddressW = TextureAddressMode.Clamp,
MipLodBias = 0,
MaximumAnisotropy = 1,
ComparisonFunction = Comparison.Always,
BorderColor = Color.Transparent,
MinimumLod = 0,
MaximumLod = float.MaxValue
};
SamplerStateMap = new SamplerState(device, samplerDescMap);
}
示例7: ProjectiveTexturingShader
public ProjectiveTexturingShader(Device device)
{
var shaderByteCode = new ShaderBytecode(File.ReadAllBytes("Content/DepthAndProjectiveTextureVS.cso"));
vertexShader = new VertexShader(device, shaderByteCode);
geometryShader = new GeometryShader(device, new ShaderBytecode(File.ReadAllBytes("Content/DepthAndColorGS.cso")));
pixelShader = new PixelShader(device, new ShaderBytecode(File.ReadAllBytes("Content/DepthAndColorPS.cso")));
// depth stencil state
var depthStencilStateDesc = new DepthStencilStateDescription()
{
IsDepthEnabled = true,
DepthWriteMask = DepthWriteMask.All,
DepthComparison = Comparison.LessEqual,
IsStencilEnabled = false,
};
depthStencilState = new DepthStencilState(device, depthStencilStateDesc);
// rasterizer states
var rasterizerStateDesc = new RasterizerStateDescription()
{
CullMode = CullMode.None,
FillMode = FillMode.Solid,
IsDepthClipEnabled = true,
IsFrontCounterClockwise = true,
IsMultisampleEnabled = true,
};
rasterizerState = new RasterizerState(device, rasterizerStateDesc);
// constant buffer
var constantBufferDesc = new BufferDescription()
{
Usage = ResourceUsage.Dynamic,
BindFlags = BindFlags.ConstantBuffer,
SizeInBytes = Constants.size,
CpuAccessFlags = CpuAccessFlags.Write,
StructureByteStride = 0,
OptionFlags = 0,
};
constantBuffer = new SharpDX.Direct3D11.Buffer(device, constantBufferDesc);
// user view sampler state
var colorSamplerStateDesc = new SamplerStateDescription()
{
Filter = Filter.MinMagMipLinear,
AddressU = TextureAddressMode.Border,
AddressV = TextureAddressMode.Border,
AddressW = TextureAddressMode.Border,
//BorderColor = new SharpDX.Color4(0.5f, 0.5f, 0.5f, 1.0f),
BorderColor = new SharpDX.Color4(0, 0, 0, 1.0f),
};
colorSamplerState = new SamplerState(device, colorSamplerStateDesc);
vertexInputLayout = new InputLayout(device, shaderByteCode.Data, new[]
{
new InputElement("SV_POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
});
}
示例8: TerrainMinimapShader
public TerrainMinimapShader(Device device)
{
var vertexShaderByteCode = ShaderBytecode.CompileFromFile(ShaderFileName, "MinimapTerrainVertexShader", "vs_4_0", ShaderFlags);
var pixelShaderByteCode = ShaderBytecode.CompileFromFile(ShaderFileName, "MinimapTerrainPixelShader", "ps_4_0", ShaderFlags);
VertexShader = new VertexShader(device, vertexShaderByteCode);
PixelShader = new PixelShader(device, pixelShaderByteCode);
Layout = VertexDefinition.TerrainVertex.GetInputLayout(device, vertexShaderByteCode);
vertexShaderByteCode.Dispose();
pixelShaderByteCode.Dispose();
ConstantMatrixBuffer = new Buffer(device, MatrixBufferDesription);
ConstantSelectionBuffer = new Buffer(device, new BufferDescription
{
Usage = ResourceUsage.Dynamic,
SizeInBytes = Utilities.SizeOf<SelectionBuffer>(),
BindFlags = BindFlags.ConstantBuffer,
CpuAccessFlags = CpuAccessFlags.Write,
OptionFlags = ResourceOptionFlags.None,
StructureByteStride = 0
});
var samplerDescBorder = new SamplerStateDescription
{
Filter = Filter.Anisotropic,
AddressU = TextureAddressMode.MirrorOnce,
AddressV = TextureAddressMode.Clamp,
AddressW = TextureAddressMode.Clamp,
MipLodBias = 0,
MaximumAnisotropy = 16,
ComparisonFunction = Comparison.Always,
BorderColor = Color.Transparent,
MinimumLod = 0,
MaximumLod = float.MaxValue
};
// Create the texture sampler state.
SamplerStateBorder = new SamplerState(device, samplerDescBorder);
var samplerDescColor = new SamplerStateDescription
{
Filter = Filter.Anisotropic,
AddressU = TextureAddressMode.Wrap,
AddressV = TextureAddressMode.Wrap,
AddressW = TextureAddressMode.Wrap,
MipLodBias = 0,
MaximumAnisotropy = 16,
ComparisonFunction = Comparison.Always,
BorderColor = Color.Transparent,
MinimumLod = 0,
MaximumLod = float.MaxValue
};
// Create the texture sampler state.
SamplerStateColor = new SamplerState(device, samplerDescColor);
}
示例9: LightShader
public LightShader(Device device)
{
var vertexShaderByteCode = ShaderBytecode.CompileFromFile(ShaderFileName, "LightVertexShader", "vs_4_0", ShaderFlags);
var pixelShaderByteCode = ShaderBytecode.CompileFromFile(ShaderFileName, "LightPixelShader", "ps_4_0", ShaderFlags);
VertexShader = new VertexShader(device, vertexShaderByteCode);
PixelShader = new PixelShader(device, pixelShaderByteCode);
Layout = VertexDefinition.PositionTextureNormal.GetInputLayout(device, vertexShaderByteCode);
vertexShaderByteCode.Dispose();
pixelShaderByteCode.Dispose();
ConstantMatrixBuffer = new Buffer(device, MatrixBufferDesription);
// Setup the description of the dynamic matrix constant buffer that is in the vertex shader.
var lightBufferDesc = new BufferDescription
{
Usage = ResourceUsage.Dynamic, // Updated each frame
SizeInBytes = Utilities.SizeOf<LightBuffer>(), // Contains three matrices
BindFlags = BindFlags.ConstantBuffer,
CpuAccessFlags = CpuAccessFlags.Write,
OptionFlags = ResourceOptionFlags.None,
StructureByteStride = 0
};
ConstantLightBuffer = new Buffer(device, lightBufferDesc);
// Setup the description of the dynamic matrix constant buffer that is in the vertex shader.
var cameraBufferDesc = new BufferDescription
{
Usage = ResourceUsage.Dynamic, // Updated each frame
SizeInBytes = Utilities.SizeOf<CameraBuffer>(), // Contains three matrices
BindFlags = BindFlags.ConstantBuffer,
CpuAccessFlags = CpuAccessFlags.Write,
OptionFlags = ResourceOptionFlags.None,
StructureByteStride = 0
};
ConstantCameraBuffer = new Buffer(device, cameraBufferDesc);
// Create a texture sampler state description.
var samplerDesc = new SamplerStateDescription
{
Filter = Filter.Anisotropic,
AddressU = TextureAddressMode.Wrap,
AddressV = TextureAddressMode.Wrap,
AddressW = TextureAddressMode.Wrap,
MipLodBias = 0,
MaximumAnisotropy = 16,
ComparisonFunction = Comparison.Always,
BorderColor = new Color4(0, 0, 0, 0),
MinimumLod = 0,
MaximumLod = 10
};
// Create the texture sampler state.
SamplerState = new SamplerState(device, samplerDesc);
}
示例10: CreateShaders
private void CreateShaders()
{
foreach (var shaderBytecode in effectBytecode.Stages)
{
var bytecodeRaw = shaderBytecode.Data;
var reflection = effectBytecode.Reflection;
// TODO CACHE Shaders with a bytecode hash
switch (shaderBytecode.Stage)
{
case ShaderStage.Vertex:
vertexShader = new VertexShader(GraphicsDevice.NativeDevice, bytecodeRaw);
// Note: input signature can be reused when reseting device since it only stores non-GPU data,
// so just keep it if it has already been created before.
if (inputSignature == null)
inputSignature = EffectInputSignature.GetOrCreateLayout(new EffectInputSignature(shaderBytecode.Id, bytecodeRaw));
break;
case ShaderStage.Domain:
domainShader = new DomainShader(GraphicsDevice.NativeDevice, bytecodeRaw);
break;
case ShaderStage.Hull:
hullShader = new HullShader(GraphicsDevice.NativeDevice, bytecodeRaw);
break;
case ShaderStage.Geometry:
if (reflection.ShaderStreamOutputDeclarations != null && reflection.ShaderStreamOutputDeclarations.Count > 0)
{
// Calculate the strides
var soStrides = new List<int>();
foreach (var streamOutputElement in reflection.ShaderStreamOutputDeclarations)
{
for (int i = soStrides.Count; i < (streamOutputElement.Stream + 1); i++)
{
soStrides.Add(0);
}
soStrides[streamOutputElement.Stream] += streamOutputElement.ComponentCount * sizeof(float);
}
var soElements = new StreamOutputElement[0]; // TODO CREATE StreamOutputElement from bytecode.Reflection.ShaderStreamOutputDeclarations
geometryShader = new GeometryShader(GraphicsDevice.NativeDevice, bytecodeRaw, soElements, soStrides.ToArray(), reflection.StreamOutputRasterizedStream);
}
else
{
geometryShader = new GeometryShader(GraphicsDevice.NativeDevice, bytecodeRaw);
}
break;
case ShaderStage.Pixel:
pixelShader = new PixelShader(GraphicsDevice.NativeDevice, bytecodeRaw);
break;
case ShaderStage.Compute:
computeShader = new ComputeShader(GraphicsDevice.NativeDevice, bytecodeRaw);
break;
}
}
}
示例11: Style
public Style(String vertexShaderFilename, String pixelShaderFilename, InputElement[] layoutElements, int floatsPerVertex, DeviceManager deviceManager)
{
var path = Windows.ApplicationModel.Package.Current.InstalledLocation.Path;
// Read pre-compiled shader byte code relative to current directory
var vertexShaderByteCode = NativeFile.ReadAllBytes(path + "\\" + vertexShaderFilename);
this.pixelShader = new PixelShader(deviceManager.DeviceDirect3D, NativeFile.ReadAllBytes(path + "\\" + pixelShaderFilename));
this.vertexShader = new VertexShader(deviceManager.DeviceDirect3D, vertexShaderByteCode);
// Specify the input layout for the new style
this.layout = new InputLayout(deviceManager.DeviceDirect3D, vertexShaderByteCode, layoutElements);
this.floatsPerVertex = floatsPerVertex;
}
示例12: RecordCommands
internal unsafe void RecordCommands(MyRenderableProxy proxy, MyFoliageStream stream, int voxelMatId,
VertexShader vertexShader, InputLayout inputLayout,
int materialIndex, int indexCount, int startIndex, int baseVertex)
{
if (stream.m_stream == VertexBufferId.NULL) return;
//var worldMatrix = proxy.WorldMatrix;
//worldMatrix.Translation = Vector3D.Zero;
//MyObjectData objectData = proxy.ObjectData;
//objectData.LocalMatrix = Matrix.Identity;
var worldMat = proxy.WorldMatrix;
//worldMat.Translation -= MyRender11.Environment.CameraPosition;
MyObjectDataCommon objectData = proxy.CommonObjectData;
objectData.LocalMatrix = worldMat;
MyMapping mapping = MyMapping.MapDiscard(RC, proxy.ObjectBuffer);
mapping.WriteAndPosition(ref proxy.VoxelCommonObjectData);
mapping.WriteAndPosition(ref objectData);
mapping.Unmap();
RC.AllShaderStages.SetConstantBuffer(MyCommon.OBJECT_SLOT, proxy.ObjectBuffer);
BindProxyGeometry(proxy, RC);
RC.VertexShader.Set(vertexShader);
RC.SetInputLayout(inputLayout);
int offset = -1;
if (!stream.Append)
{
offset = 0;
stream.Append = true;
}
RC.SetTarget(stream.m_stream.Buffer, offset);
RC.AllShaderStages.SetConstantBuffer(MyCommon.FOLIAGE_SLOT, MyCommon.FoliageConstants);
float densityFactor = MyVoxelMaterials1.Table[voxelMatId].FoliageDensity * MyRender11.Settings.GrassDensityFactor;
float zero = 0;
mapping = MyMapping.MapDiscard(RC, MyCommon.FoliageConstants);
mapping.WriteAndPosition(ref densityFactor);
mapping.WriteAndPosition(ref materialIndex);
mapping.WriteAndPosition(ref voxelMatId);
mapping.WriteAndPosition(ref zero);
mapping.Unmap();
RC.DrawIndexed(indexCount, startIndex, baseVertex);
}
示例13: InitializeEffect
private void InitializeEffect()
{
var vsBytecode = ShaderBytecode.CompileFromFile(string.Format(@"Content\{0}", FileName), "VS_Main", "vs_5_0");
var psBytecode = ShaderBytecode.CompileFromFile(string.Format(@"Content\{0}", FileName), "PS_Main", "ps_5_0");
_pixelShader = new PixelShader(_myGame.GraphicsDevice, psBytecode);
_vertexShader = new VertexShader(_myGame.GraphicsDevice, vsBytecode);
_layout = new InputLayout(_myGame.GraphicsDevice, ShaderSignature.GetInputSignature(vsBytecode), new[]
{
new InputElement("POSITION", 0, Format.R32G32_Float, 0, 0),
new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 8, 0)
});
}
示例14: ColorShader
public ColorShader(Device device)
{
var vertexShaderByteCode = ShaderBytecode.CompileFromFile(ShaderFileName, "ColorVertexShader", "vs_4_0", ShaderFlags);
var pixelShaderByteCode = ShaderBytecode.CompileFromFile(ShaderFileName, "ColorPixelShader", "ps_4_0", ShaderFlags);
VertexShader = new VertexShader(device, vertexShaderByteCode);
PixelShader = new PixelShader(device, pixelShaderByteCode);
Layout = VertexDefinition.PositionColor.GetInputLayout(device, vertexShaderByteCode);
vertexShaderByteCode.Dispose();
pixelShaderByteCode.Dispose();
ConstantMatrixBuffer = new Buffer(device, MatrixBufferDesription);
}
示例15: ColorShader
public ColorShader(Device device)
{
var vertexShaderByteCode = ShaderBytecode.CompileFromFile(VertexShaderFileName, "ColorVertexShader", "vs_4_0", ShaderFlags.None, EffectFlags.None);
var pixelShaderByteCode = ShaderBytecode.CompileFromFile(PixelShaderFileName, "ColorPixelShader", "ps_4_0", ShaderFlags.None, EffectFlags.None);
VertexShader = new VertexShader(device, vertexShaderByteCode);
PixelShader = new PixelShader(device, pixelShaderByteCode);
var inputElements = new InputElement[]
{
new InputElement
{
SemanticName = "POSITION",
SemanticIndex = 0,
Format = Format.R32G32B32_Float,
Slot = 0,
AlignedByteOffset = 0,
Classification = InputClassification.PerVertexData,
InstanceDataStepRate = 0
},
new InputElement
{
SemanticName = "COLOR",
SemanticIndex = 0,
Format = Format.R32G32B32A32_Float,
Slot = 0,
AlignedByteOffset = ColorShader.Vertex.AppendAlignedElement,
Classification = InputClassification.PerVertexData,
InstanceDataStepRate = 0
}
};
Layout = new InputLayout(device, ShaderSignature.GetInputSignature(vertexShaderByteCode), inputElements);
vertexShaderByteCode.Dispose();
pixelShaderByteCode.Dispose();
// Setup the description of the dynamic matrix constant buffer that is in the vertex shader.
var matrixBufferDesc = new BufferDescription
{
Usage = ResourceUsage.Dynamic, // Updated each frame
SizeInBytes = Utilities.SizeOf<MatrixBuffer>(), // Contains three matrices
BindFlags = BindFlags.ConstantBuffer,
CpuAccessFlags = CpuAccessFlags.Write,
OptionFlags = ResourceOptionFlags.None,
StructureByteStride = 0
};
ConstantMatrixBuffer = new Buffer(device, matrixBufferDesc);
}