本文整理汇总了C#中EffectTechnique.GetPassByIndex方法的典型用法代码示例。如果您正苦于以下问题:C# EffectTechnique.GetPassByIndex方法的具体用法?C# EffectTechnique.GetPassByIndex怎么用?C# EffectTechnique.GetPassByIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EffectTechnique
的用法示例。
在下文中一共展示了EffectTechnique.GetPassByIndex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UserInterfaceRenderCommand
public UserInterfaceRenderCommand(Renderer renderer, Hud hud, RenderableNode rNode)
: base(renderer, new UIMaterial(),
new RenderableCollection(UIMaterial.ItemsDescription, new [] {rNode}))
{
CommandType = CommandType.UserInterfaceRenderCommand;
CommandAttributes |= Graphics.CommandAttributes.MonoRendering;
this.hud = hud;
textMaterial = new TextMaterial();
this.rNode = rNode;
this.rNode.RenderableObject.Material = Material;
tNode = (TransformNode)rNode.Parent;
UpdateSprites(hud.SpriteControls);
textTechnique = textMaterial.EffectDescription.Technique;
textPass = textTechnique.GetPassByIndex(textMaterial.EffectDescription.Pass);
textLayout = new InputLayout(Game.Context.Device, textPass.Description.Signature,
TextItems.Description.InputElements);
}
示例2: TestEffect
/// <summary>
/// Create our test RenderEffect.
/// </summary>
/// <param name="Device"></param>
public TestEffect(Device Device)
{
this.Device = Device;
ImmediateContext = Device.ImmediateContext;
// Compile our shader...
string compileErrors;
var compiledShader = SlimDX.D3DCompiler.ShaderBytecode.CompileFromFile
(
"../../Effects/TestEffect/TestEffect.fx",
null,
"fx_5_0",
SlimDX.D3DCompiler.ShaderFlags.None,
SlimDX.D3DCompiler.EffectFlags.None,
null,
null,
out compileErrors
);
if (compileErrors != null && compileErrors != "")
{
throw new EffectBuildException(compileErrors);
}
Effect = new Effect(Device, compiledShader);
EffectTechnique = Effect.GetTechniqueByName("TestTechnique");
var vertexDesc = new[]
{
new InputElement("POSITION", 0, SlimDX.DXGI.Format.R32G32B32_Float, 0, 0, InputClassification.PerVertexData, 0),
new InputElement("COLOR", 0, SlimDX.DXGI.Format.R32G32B32A32_Float, 12, 0, InputClassification.PerVertexData, 0)
};
WorldViewProj = SlimDX.Matrix.Identity;
CPO_WorldViewProj = Effect.GetVariableByName("gWorldViewProj").AsMatrix();
InputLayout = new InputLayout(Device, EffectTechnique.GetPassByIndex(0).Description.Signature, vertexDesc);
Util.ReleaseCom(ref compiledShader);
}
示例3: Initialize
public void Initialize(Device device) {
_b = EffectUtils.Load("DeferredGObject");
E = new Effect(device, _b);
TechStandardDeferred = E.GetTechniqueByName("StandardDeferred");
TechStandardForward = E.GetTechniqueByName("StandardForward");
TechAmbientShadowDeferred = E.GetTechniqueByName("AmbientShadowDeferred");
TechTransparentDeferred = E.GetTechniqueByName("TransparentDeferred");
TechTransparentForward = E.GetTechniqueByName("TransparentForward");
TechTransparentMask = E.GetTechniqueByName("TransparentMask");
for (var i = 0; i < TechStandardDeferred.Description.PassCount && InputSignaturePNTG == null; i++) {
InputSignaturePNTG = TechStandardDeferred.GetPassByIndex(i).Description.Signature;
}
if (InputSignaturePNTG == null) throw new System.Exception("input signature (DeferredGObject, PNTG, StandardDeferred) == null");
LayoutPNTG = new InputLayout(device, InputSignaturePNTG, InputLayouts.VerticePNTG.InputElementsValue);
for (var i = 0; i < TechAmbientShadowDeferred.Description.PassCount && InputSignaturePT == null; i++) {
InputSignaturePT = TechAmbientShadowDeferred.GetPassByIndex(i).Description.Signature;
}
if (InputSignaturePT == null) throw new System.Exception("input signature (DeferredGObject, PT, AmbientShadowDeferred) == null");
LayoutPT = new InputLayout(device, InputSignaturePT, InputLayouts.VerticePT.InputElementsValue);
FxWorld = E.GetVariableByName("gWorld").AsMatrix();
FxWorldInvTranspose = E.GetVariableByName("gWorldInvTranspose").AsMatrix();
FxWorldViewProj = E.GetVariableByName("gWorldViewProj").AsMatrix();
FxDiffuseMap = E.GetVariableByName("gDiffuseMap").AsResource();
FxNormalMap = E.GetVariableByName("gNormalMap").AsResource();
FxMapsMap = E.GetVariableByName("gMapsMap").AsResource();
FxDetailsMap = E.GetVariableByName("gDetailsMap").AsResource();
FxDetailsNormalMap = E.GetVariableByName("gDetailsNormalMap").AsResource();
FxReflectionCubemap = E.GetVariableByName("gReflectionCubemap").AsResource();
FxEyePosW = E.GetVariableByName("gEyePosW").AsVector();
FxAmbientDown = E.GetVariableByName("gAmbientDown").AsVector();
FxAmbientRange = E.GetVariableByName("gAmbientRange").AsVector();
FxLightColor = E.GetVariableByName("gLightColor").AsVector();
FxDirectionalLightDirection = E.GetVariableByName("gDirectionalLightDirection").AsVector();
FxMaterial = E.GetVariableByName("gMaterial");
}
示例4: CompileShader
private void CompileShader(Device device, string fullPath)
{
_File = fullPath;
_CompiledEffect = ShaderBytecode.CompileFromFile(_File, "SpriteTech", "fx_5_0");
if (_CompiledEffect.HasErrors) {
Log.Write("Shader compilation failed with status code: {0} - {1} | Path: {2}", _CompiledEffect.ResultCode.Code, _CompiledEffect.Message, _File);
return;
}
_Effect = new Effect(device, _CompiledEffect);
_EffectTechnique = _Effect.GetTechniqueByName("SpriteTech");
_SpriteMap = _Effect.GetVariableByName("SpriteTex").AsShaderResource();
var _EffectPass = _EffectTechnique.GetPassByIndex(0).Description.Signature;
InputElement[] _LayoutDescription = {
new InputElement("POSITION", 0, SharpDX.DXGI.Format.R32G32B32_Float, 0, 0, InputClassification.PerVertexData, 0),
new InputElement("TEXCOORD", 0, SharpDX.DXGI.Format.R32G32_Float, 12, 0, InputClassification.PerVertexData, 0),
new InputElement("COLOR", 0, SharpDX.DXGI.Format.R32G32B32A32_Float, 20, 0, InputClassification.PerVertexData, 0)
};
_InputLayout = new InputLayout(device, _EffectPass, _LayoutDescription);
}
示例5: DrawSkullShadowReflection
private void DrawSkullShadowReflection(EffectTechnique activeSkullTech, Matrix viewProj, Color4 blendFactor) {
// draw skull shadow
for (int p = 0; p < activeSkullTech.Description.PassCount; p++) {
var pass = activeSkullTech.GetPassByIndex(p);
ImmediateContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_skullVB, Basic32.Stride, 0));
ImmediateContext.InputAssembler.SetIndexBuffer(_skullIB, Format.R32_UInt, 0);
var shadowPlane = new Plane(new Vector3(0, 1, 0), 0.0f);
var toMainLight = -_dirLights[0].Direction;
var s = Matrix.Shadow(new Vector4(toMainLight, 0), shadowPlane);
var shadowOffsetY = Matrix.Translation(0, 0.001f, 0);
var mirrorPlane = new Plane(new Vector3(0, 0, 1), 0);
var r = Matrix.Reflection(mirrorPlane);
var world = _skullWorld * s * shadowOffsetY * r;
var wit = MathF.InverseTranspose(world);
var wvp = world * viewProj;
Effects.BasicFX.SetWorld(world);
Effects.BasicFX.SetWorldInvTranspose(wit);
Effects.BasicFX.SetWorldViewProj(wvp);
Effects.BasicFX.SetMaterial(_shadowMat);
ImmediateContext.OutputMerger.BlendState = RenderStates.TransparentBS;
ImmediateContext.OutputMerger.BlendFactor = blendFactor;
ImmediateContext.OutputMerger.BlendSampleMask = -1;
var oldLightDirections = _dirLights.Select(l => l.Direction).ToArray();
for (int i = 0; i < _dirLights.Length; i++) {
var l = _dirLights[i];
var lightDir = l.Direction;
var reflectedLightDir = Vector3.Transform(lightDir, r);
_dirLights[i].Direction = new Vector3(reflectedLightDir.X, reflectedLightDir.Y, reflectedLightDir.Z);
}
Effects.BasicFX.SetDirLights(_dirLights);
ImmediateContext.Rasterizer.State = RenderStates.CullClockwiseRS;
ImmediateContext.OutputMerger.DepthStencilState = RenderStates.NoDoubleBlendDSS;
ImmediateContext.OutputMerger.DepthStencilReference = 1;
pass.Apply(ImmediateContext);
ImmediateContext.DrawIndexed(_skullIndexCount, 0, 0);
ImmediateContext.Rasterizer.State = null;
ImmediateContext.OutputMerger.DepthStencilState = null;
ImmediateContext.OutputMerger.DepthStencilReference = 0;
ImmediateContext.OutputMerger.BlendState = null;
ImmediateContext.OutputMerger.BlendFactor = blendFactor;
ImmediateContext.OutputMerger.BlendSampleMask = -1;
for (int i = 0; i < oldLightDirections.Length; i++) {
_dirLights[i].Direction = oldLightDirections[i];
}
Effects.BasicFX.SetDirLights(_dirLights);
}
}
示例6: MarkMirrorOnStencil
private void MarkMirrorOnStencil(EffectTechnique activeTech, Matrix viewProj, Color4 blendFactor) {
// Draw mirror to stencil
for (int p = 0; p < activeTech.Description.PassCount; p++) {
var pass = activeTech.GetPassByIndex(p);
ImmediateContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_roomVB, Basic32.Stride, 0));
var world = _roomWorld;
var wit = MathF.InverseTranspose(world);
var wvp = world * viewProj;
Effects.BasicFX.SetWorld(world);
Effects.BasicFX.SetWorldInvTranspose(wit);
Effects.BasicFX.SetWorldViewProj(wvp);
Effects.BasicFX.SetTexTransform(Matrix.Identity);
ImmediateContext.OutputMerger.BlendState = RenderStates.NoRenderTargetWritesBS;
ImmediateContext.OutputMerger.BlendFactor = blendFactor;
ImmediateContext.OutputMerger.BlendSampleMask = -1;
ImmediateContext.OutputMerger.DepthStencilState = RenderStates.MarkMirrorDSS;
ImmediateContext.OutputMerger.DepthStencilReference = 1;
pass.Apply(ImmediateContext);
ImmediateContext.Draw(6, 24);
ImmediateContext.OutputMerger.DepthStencilState = null;
ImmediateContext.OutputMerger.DepthStencilReference = 0;
ImmediateContext.OutputMerger.BlendState = null;
ImmediateContext.OutputMerger.BlendFactor = blendFactor;
ImmediateContext.OutputMerger.BlendSampleMask = -1;
}
}
示例7: DrawSkullReflection
private void DrawSkullReflection(EffectTechnique activeSkullTech, Matrix viewProj) {
// Draw skull reflection
for (int p = 0; p < activeSkullTech.Description.PassCount; p++) {
var pass = activeSkullTech.GetPassByIndex(p);
ImmediateContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_skullVB, Basic32.Stride, 0));
ImmediateContext.InputAssembler.SetIndexBuffer(_skullIB, Format.R32_UInt, 0);
var mirrorPlane = new Plane(new Vector3(0, 0, 1), 0);
var r = Matrix.Reflection(mirrorPlane);
var world = _skullWorld * r;
var wit = MathF.InverseTranspose(world);
var wvp = world * viewProj;
Effects.BasicFX.SetWorld(world);
Effects.BasicFX.SetWorldInvTranspose(wit);
Effects.BasicFX.SetWorldViewProj(wvp);
Effects.BasicFX.SetMaterial(_skullMat);
var oldLightDirections = _dirLights.Select(l => l.Direction).ToArray();
for (int i = 0; i < _dirLights.Length; i++) {
var l = _dirLights[i];
var lightDir = l.Direction;
var reflectedLightDir = Vector3.Transform(lightDir, r);
_dirLights[i].Direction = new Vector3(reflectedLightDir.X, reflectedLightDir.Y, reflectedLightDir.Z);
}
Effects.BasicFX.SetDirLights(_dirLights);
ImmediateContext.Rasterizer.State = RenderStates.CullClockwiseRS;
ImmediateContext.OutputMerger.DepthStencilState = RenderStates.DrawReflectionDSS;
ImmediateContext.OutputMerger.DepthStencilReference = 1;
pass.Apply(ImmediateContext);
ImmediateContext.DrawIndexed(_skullIndexCount, 0, 0);
ImmediateContext.Rasterizer.State = null;
ImmediateContext.OutputMerger.DepthStencilState = null;
ImmediateContext.OutputMerger.DepthStencilReference = 0;
for (int i = 0; i < oldLightDirections.Length; i++) {
_dirLights[i].Direction = oldLightDirections[i];
}
Effects.BasicFX.SetDirLights(_dirLights);
}
}
示例8: DrawSkull
private void DrawSkull(EffectTechnique activeSkullTech, Matrix viewProj) {
// Draw skull
for (int p = 0; p < activeSkullTech.Description.PassCount; p ++) {
var pass = activeSkullTech.GetPassByIndex(p);
ImmediateContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_skullVB, Basic32.Stride, 0));
ImmediateContext.InputAssembler.SetIndexBuffer(_skullIB, Format.R32_UInt, 0);
var world = _skullWorld;
var wit = MathF.InverseTranspose(world);
var wvp = world * viewProj;
Effects.BasicFX.SetWorld(world);
Effects.BasicFX.SetWorldInvTranspose(wit);
Effects.BasicFX.SetWorldViewProj(wvp);
Effects.BasicFX.SetMaterial(_skullMat);
pass.Apply(ImmediateContext);
ImmediateContext.DrawIndexed(_skullIndexCount, 0, 0);
}
}
示例9: Render
public void Render()
{
//BlendStateDescription desc = new BlendStateDescription();
//desc.RenderTarget[0].SourceBlend = BlendOption.SourceAlpha;
//desc.RenderTarget[0].SourceAlphaBlend = BlendOption.One;
//desc.RenderTarget[0].DestinationBlend = BlendOption.InverseSourceAlpha;
//desc.RenderTarget[0].DestinationAlphaBlend = BlendOption.InverseSourceAlpha;
//SharpDX.Direct3D11.BlendState bs = new BlendState(Global._G.device, desc);
//Global._G.context.OutputMerger.SetBlendState(bs, null, -1);
//bs.Dispose();
// Prepare All the stages
Global._G.context.InputAssembler.InputLayout = layout;
Global._G.context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
//Global._G.dxState.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertices, Utilities.SizeOf<Vector3>() + Utilities.SizeOf<Vector3>() + Utilities.SizeOf<Vector2>(), 0));
int lamez = System.Runtime.InteropServices.Marshal.SizeOf(new VertexPNT());
Global._G.context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertices, lamez, 0));
Global._G.context.InputAssembler.SetIndexBuffer(indexBuffer, Format.R32_UInt, 0);
#if DEBUG
technique = Global._G.effect.GetTechniqueByName(shaderName); // Realtime update shaders if file was changed
#endif
int numPasses = technique.Description.PassCount;
for (int count = 0; count < numPasses; count++)
{
EffectPass pass = technique.GetPassByIndex(count);
pass.Apply(Global._G.context);
Global._G.context.VertexShader.SetConstantBuffer(0, Global._G.constantBuffer);
Global._G.context.PixelShader.SetConstantBuffer(0, Global._G.constantBuffer);
//Global._G.dxState.VertexShader.Set(Global._G.vertexShader);
//Global._G.dxState.PixelShader.Set(Global._G.pixelShader);
//Global._G.context.PixelShader.SetSampler(0, sampler);
Global._G.context.PixelShader.SetShaderResources(0, textureView.Length, textureView);
Global._G.context.DrawIndexed(numIndexes, 0, 0);
}
}
示例10: D3D10Renderer
public D3D10Renderer(Device1 device3D)
{
Contract.Requires(device3D != null);
_Device3D = device3D;
string shader = GetShaderText(Properties.Resources.RenderingEffects);
using(var byteCode = ShaderBytecode.Compile(
shader, "fx_4_0", ShaderFlags.None, EffectFlags.None))
{
_Effect = new Effect(_Device3D, byteCode);
}
_EffectTechnique = _Effect.GetTechniqueByName("WithTexture");
Contract.Assert(_EffectTechnique != null);
_EffectPass = _EffectTechnique.GetPassByIndex(0);
Contract.Assert(_EffectPass != null);
_InputLayout = new InputLayout(
_Device3D, _EffectPass.Description.Signature, _InputLayoutData);
const int byteSize = _Stride * _VertexCount;
using(DataStream stream = new DataStream(byteSize, true, true))
{
for(int i = 0; i < _QuadPrimitiveData.Length; i += 2)
{
float fx = (2.0f * _QuadPrimitiveData[i + 0].X) - 1.0f;
float fy = (2.0f * _QuadPrimitiveData[i + 0].Y) - 1.0f;
stream.Write(new Vector3(fx, -fy, 0.5f));
stream.Write(_QuadPrimitiveData[i + 1]);
}
stream.Seek(0, SeekOrigin.Begin);
BufferDescription description = new BufferDescription
{
BindFlags = BindFlags.VertexBuffer,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None,
Usage = ResourceUsage.Immutable,
SizeInBytes = byteSize
};
description.SizeInBytes = byteSize;
_VertexBuffer = new Buffer(_Device3D, stream, description);
_VertexBufferBinding = new VertexBufferBinding(
_VertexBuffer, _Stride, _Offset);
}
}
示例11: CreateDeviceResources
//.........这里部分代码省略.........
offscreenTexture = device.CreateTexture2D(tex2DDescription);
using (Surface dxgiSurface = offscreenTexture.GetDXGISurface())
{
// Create a D2D render target which can draw into our offscreen D3D surface
renderTarget = d2DFactory.CreateDxgiSurfaceRenderTarget(
dxgiSurface,
props);
}
PixelFormat alphaOnlyFormat = new PixelFormat(Format.A8_UNORM, AlphaMode.Premultiplied);
opacityRenderTarget = renderTarget.CreateCompatibleRenderTarget(CompatibleRenderTargetOptions.None,
alphaOnlyFormat);
// Load pixel shader
// Open precompiled vertex shader
// This file was compiled using DirectX's SDK Shader compilation tool:
// fxc.exe /T fx_4_0 /Fo SciFiText.fxo SciFiText.fx
shader = LoadResourceShader(device, "SciFiTextDemo.SciFiText.fxo");
// Obtain the technique
technique = shader.GetTechniqueByName("Render");
// Obtain the variables
worldMatrixVariable = shader.GetVariableByName("World").AsMatrix();
viewMatrixVariable = shader.GetVariableByName("View").AsMatrix();
projectionMarixVariable = shader.GetVariableByName("Projection").AsMatrix();
diffuseVariable = shader.GetVariableByName("txDiffuse").AsShaderResource();
// Create the input layout
PassDescription passDesc = new PassDescription();
passDesc = technique.GetPassByIndex(0).Description;
vertexLayout = device.CreateInputLayout(
inputLayoutDescriptions,
passDesc.InputAssemblerInputSignature,
passDesc.InputAssemblerInputSignatureSize
);
// Set the input layout
device.IA.SetInputLayout(
vertexLayout
);
IntPtr verticesDataPtr = Marshal.AllocHGlobal(Marshal.SizeOf(VertexArray.VerticesInstance));
Marshal.StructureToPtr(VertexArray.VerticesInstance, verticesDataPtr, true);
BufferDescription bd = new BufferDescription();
bd.Usage = Usage.Default;
bd.ByteWidth = (uint) Marshal.SizeOf(VertexArray.VerticesInstance);
bd.BindFlags = BindFlag.VertexBuffer;
bd.CpuAccessFlags = CpuAccessFlag.Unspecified;
bd.MiscFlags = ResourceMiscFlag.Undefined;
SubresourceData InitData = new SubresourceData()
{
SysMem = verticesDataPtr
};
vertexBuffer = device.CreateBuffer(
bd,
InitData
);
示例12: EffectsInitialization
public void EffectsInitialization()
{
var effectByteCode = ShaderBytecode.CompileFromFile("C:\\Users\\Nat�lia\\Documents\\MPM\\5. ro�n�k\\Diplomovka\\grafika3D\\Grafika3D\\effect.fx", "fx_5_0", ShaderFlags.None, EffectFlags.None);
effect = new Effect(device, effectByteCode);
techniquePosition = effect.GetTechniqueByName("Position");
passPosition = techniquePosition.GetPassByIndex(0);
techniqueTexture = effect.GetTechniqueByName("Texture");
passTextureXY = techniqueTexture.GetPassByIndex(0);
passTextureYZ = techniqueTexture.GetPassByIndex(1);
passTextureZX = techniqueTexture.GetPassByIndex(2);
var signature = passPosition.Description.Signature;
inputLayout = new InputLayout(device, signature, new[]
{
new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0),
new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 12, 0)
});
var signatureTex = passTextureXY.Description.Signature;
inputLayoutTex = new InputLayout(device, signatureTex, new[]
{
new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0),
new InputElement("TEXCOORD", 0, Format.R32G32_Float, 12, 0)
});
var samplerState = new SamplerState(device, new SamplerStateDescription()
{
AddressU = TextureAddressMode.Wrap,
AddressV = TextureAddressMode.Wrap,
AddressW = TextureAddressMode.Wrap,
Filter = Filter.MinMagMipLinear,
});
var effectSampler = effect.GetVariableByName("Sampler").AsSampler();
effectSampler.SetSampler(0, samplerState);
}
示例13: TerrainSubrender
public TerrainSubrender(BTerrain terrain, RenderManager renderer, IRunManager manager)
: base(manager)
{
Renderer = renderer;
FrustumCheck = Manager.Opts.Get<bool>("rndr_terrain_frustumCheck");
NotifyHandlers.Add(Manager.Opts.RegisterChangeNotification("rndr_terrain_frustumCheck", delegate(string key, object value) { FrustumCheck = (bool)value; }));
try
{
Lods = Manager.Opts.Get<int>("rndr_terrain_lods");
if (Lods > 1)
{
LodDistancesSquared = new float[Lods - 1];
LodFactors = new int[Lods -1];
var list = Manager.Opts.Get<List<float>>("rndr_terrain_lodDistances");
var list2 = Manager.Opts.Get<List<int>>("rndr_terrain_lodFactors");
for (int i = 0; i < Lods-1; i++)
{
LodDistancesSquared[i] = list[i] * list[i];
LodFactors[i] = list2[i];
}
}
}
catch (Exception)
{
Console.WriteLine("[Error] Could not read terrain-LOD settings, LOD disabled!");
Lods = 1;
LodDistancesSquared = null;
}
var shaderdeffile = Manager.Files.Get(@"Shaders\Terrain.hlsl", false);
var bbuffer = new byte[shaderdeffile.Length];
shaderdeffile.Read(bbuffer, 0, bbuffer.Length);
shaderdeffile.Dispose();
var bytecode = ShaderBytecode.Compile(
Encoding.ASCII.GetBytes(
Encoding.ASCII.GetString(bbuffer).Replace("%TEXTURECOUNT%", "2").Replace("%OVERLAYCOUNT%", "1"))
, "fx_5_0");
bbuffer = null;
Effect = new Effect(Renderer.D3DDevice, bytecode);
bytecode.Dispose();
_technique = Effect.GetTechniqueByName("Terrain");
_pass = _technique.GetPassByIndex(0);
_vertexLayout = new InputLayout(Renderer.D3DDevice, _pass.Description.Signature, new[]
{ new InputElement("POSITION", 0, Format.R32G32B32_Float, 0),
new InputElement("NORMAL", 0, Format.R32G32B32_Float, 0),
new InputElement("TEXCOORD",0,Format.R32G32_Float, 0) });
Effect.GetVariableByName("texRepeat").AsScalar().Set(new[] { 0.1f, 0.1f });
var sampleMode = SamplerState.FromDescription(Renderer.D3DDevice, new SamplerDescription()
{
AddressU = TextureAddressMode.Wrap,
AddressV = TextureAddressMode.Wrap,
AddressW = TextureAddressMode.Clamp,
BorderColor = new Color4(0, 0, 0, 0),
Filter = Filter.MinMagMipLinear,
ComparisonFunction = Comparison.Always,
MipLodBias = 0f,
MaximumAnisotropy = 8,
MinimumLod = 0f,
MaximumLod = float.MaxValue
});
Effect.GetVariableByName("textureSampler").AsSampler().SetSamplerState(0, sampleMode);
Effect.GetVariableByName("alphaSampler").AsSampler().SetSamplerState(0, sampleMode);
UpdateStaticVars();
CurrentTerrain = terrain;
QuadEdgeLength = Manager.Opts.Get<int>("rndr_terrain_quadVerticesPerEdge");
var verticesX = terrain.PointsX;
var verticesZ = terrain.PointsZ;
var quadsX = (int)Math.Ceiling((double)(verticesX - 1) / (QuadEdgeLength - 1));
var quadsZ = (int)Math.Ceiling((double)(verticesZ - 1) / (QuadEdgeLength - 1));
#if DEBUG
if ((verticesX - 1) % (QuadEdgeLength - 1) != 0)
Console.WriteLine("[Info] The terrain X-Vertices are no multiple of the quad-length, filling to fit IndexBuffers");
if ((verticesZ - 1) % (QuadEdgeLength - 1) != 0)
Console.WriteLine("[Info] The terrain Z-Vertices are no multiple of the quad-length, filling to fit IndexBuffers");
#endif
Quads = new Quad[quadsX*quadsZ];
QuadCountZ = quadsZ;
for (int i = 0; i < quadsX; i++)
{
for (int j = 0; j < quadsZ; j++)
{
Quads[i * quadsZ + j] = new Quad(i * (QuadEdgeLength - 1), (i + 1) * (QuadEdgeLength - 1), j * (QuadEdgeLength - 1), (j + 1) * (QuadEdgeLength - 1), CurrentTerrain, Renderer);
}
}
FrustumTree = new QuadContainer(0,quadsX-1, 0, quadsZ-1, ref Quads, QuadCountZ);
QuadLods = new int[Quads.Length];
Indexbuffers = new Dictionary<uint, KeyValuePair<Buffer, int>>();
}
示例14: LoadEffect
private void LoadEffect(string shaderFileName)
{
_effect = Effect.FromFile(_dxDevice, shaderFileName, "fx_4_0",
ShaderFlags.None, EffectFlags.None, null, null);
_renderTech = _effect.GetTechniqueByName("Render"); //C++ Comparaison// technique = effect->GetTechniqueByName( "Render" );
_eyePosWVar = _effect.GetVariableByName("gEyePosW").AsVector();
_viewProjVar = _effect.GetVariableByName("gViewProj").AsMatrix();
_worldVar = _effect.GetVariableByName("gWorld").AsMatrix();
_fillColorVar = _effect.GetVariableByName("gFillColor").AsVector();
_lightVariable = _effect.GetVariableByName("gLight");
_imageMapVar = _effect.GetVariableByName("gImageMap").AsResource();
_depthMapVar = _effect.GetVariableByName("gDepthMap").AsResource();
_resVar = _effect.GetVariableByName("gRes").AsVector();
_depthToRgbVar = _effect.GetVariableByName("gDepthToRgb").AsMatrix();
_focalLengthDepthVar = _effect.GetVariableByName("gFocalLengthDepth").AsScalar();
_focalLengthImageVar = _effect.GetVariableByName("gFocalLengthImage").AsScalar();
ShaderSignature signature = _renderTech.GetPassByIndex(0).Description.Signature;
_inputLayout = new InputLayout(_dxDevice, signature,
new[] { new InputElement("POSITION", 0, SlimDX.DXGI.Format.R16G16_SInt, 0, 0)
});
}
示例15: LoadResources
public override void LoadResources()
{
if (m_Disposed == true)
{
#region Load Volume Effect
m_Effect = m_Effect = new Effect(GameEnvironment.Device, Bytecode); // Effect.FromFile(GameEnvironment.Device, Helper.ResolvePath(m_ShaderLocation), "fx_4_0", ShaderFlags.None, EffectFlags.None, null, null);
RayStartTechnique = m_Effect.GetTechniqueByName("RayStart");
RayStartOutsidePass = RayStartTechnique.GetPassByName("Outside");
RayStartInsidePass = RayStartTechnique.GetPassByName("Inside");
VolumeLayout = new InputLayout(GameEnvironment.Device, RayStartOutsidePass.Description.Signature, new[] {
new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0),
new InputElement("COLOR", 0, Format.R32G32B32_Float, 12, 0)
});
RayDirectionTechnique = m_Effect.GetTechniqueByName("RayDirection");
RayDirectionPass0 = RayDirectionTechnique.GetPassByIndex(0);
//RayDirectionPass1 = RayDirectionTechnique.GetPassByIndex(1);
BillboardTechnique = m_Effect.GetTechniqueByName("Final");
BillboardPass0 = BillboardTechnique.GetPassByIndex(0);
ImposterTechnique = m_Effect.GetTechniqueByName("Imposter");
ImposterPass0 = ImposterTechnique.GetPassByIndex(0);
BillboardLayout = new InputLayout(GameEnvironment.Device, BillboardPass0.Description.Signature, new[] {
new InputElement("POSITION", 0, Format.R32G32_Float, 0, 0),
new InputElement("TEXCOORD", 0, Format.R32G32_Float, 8, 0)
});
rayStart_texture = m_Effect.GetVariableByName("rayStart_texture").AsResource();
rayDir_texture = m_Effect.GetVariableByName("rayDir_texture").AsResource();
imposter = m_Effect.GetVariableByName("imposter").AsResource();
volume_texture = m_Effect.GetVariableByName("volume_texture").AsResource();
LocationColor = m_Effect.GetVariableByName("locationColor").AsVector();
#endregion
#region Billboard Verts
float minX = -1f;
float miny = -1f;
float maxX = 1f;
float maxY = 1f;
using (DataStream stream = new DataStream(4 * Marshal.SizeOf(typeof(Vertex2D)), true, true))
{
stream.WriteRange(new Vertex2D[] {
new Vertex2D() { Position = new Vector2(maxX, miny), TextureCoords = new Vector2(1.0f, 1.0f) },
new Vertex2D() { Position = new Vector2(minX, miny), TextureCoords = new Vector2(0.0f, 1.0f) },
new Vertex2D() { Position = new Vector2(maxX, maxY), TextureCoords = new Vector2(1.0f, 0.0f) },
new Vertex2D() { Position = new Vector2(minX, maxY), TextureCoords = new Vector2(0.0f, 0.0f) }
});
stream.Position = 0;
BillboardVertices = new SlimDX.Direct3D11.Buffer(GameEnvironment.Device, stream, new BufferDescription()
{
BindFlags = BindFlags.VertexBuffer,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None,
SizeInBytes = 4 * Marshal.SizeOf(typeof(Vertex2D)),
Usage = ResourceUsage.Default
});
}
BillboardVerticesBindings = new VertexBufferBinding(BillboardVertices, Marshal.SizeOf(typeof(UIVertex)), 0);
#endregion
m_Disposed = false;
}
}