本文整理汇总了C#中Effect.GetTechniqueByIndex方法的典型用法代码示例。如果您正苦于以下问题:C# Effect.GetTechniqueByIndex方法的具体用法?C# Effect.GetTechniqueByIndex怎么用?C# Effect.GetTechniqueByIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Effect
的用法示例。
在下文中一共展示了Effect.GetTechniqueByIndex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BasicEffect
/// <summary>
/// Crée une nouvelle instance de BasicEffect.
/// </summary>
public BasicEffect(Device device)
{
m_effect = Ressources.EffectCache.Get("Shaders\\basic_effect2.fx");
float Km = 0.0025f;
float Kr = 0.0015f;
float ESun = Planet.ESun;
float fOuterRadius = Planet.AtmosphereRadius; // 50
float fInnerRadius = Planet.PlanetRadius; // 44
float fScale = 1.0f / (fOuterRadius - fInnerRadius);
float fScaleDepth = Planet.ScaleDepth;
m_effect.GetVariableByName("v3InvWavelength").AsVector().Set(new Vector3(1.0f / (float)Math.Pow(0.650, 4),
1.0f / (float)Math.Pow(0.570f, 4),
1.0f / (float)Math.Pow(0.475f, 4)));
m_effect.GetVariableByName("fOuterRadius").AsScalar().Set(fOuterRadius);
m_effect.GetVariableByName("fOuterRadius2").AsScalar().Set(fOuterRadius * fOuterRadius);
m_effect.GetVariableByName("fInnerRadius").AsScalar().Set(fInnerRadius);
m_effect.GetVariableByName("fInnerRadius2").AsScalar().Set(fInnerRadius * fInnerRadius);
m_effect.GetVariableByName("fKrESun").AsScalar().Set(Kr * ESun);
m_effect.GetVariableByName("fKmESun").AsScalar().Set(Km * ESun);
m_effect.GetVariableByName("fKr4PI").AsScalar().Set(Kr * 4.0f * (float)Math.PI);
m_effect.GetVariableByName("fKm4PI").AsScalar().Set(Km * 4.0f * (float)Math.PI);
m_effect.GetVariableByName("fScaleDepth").AsScalar().Set(fScaleDepth);
m_effect.GetVariableByName("fInvScaleDepth").AsScalar().Set(1.0f / fScaleDepth);
m_effect.GetVariableByName("fScale").AsScalar().Set(fScale);
m_effect.GetVariableByName("fScaleOverScaleDepth").AsScalar().Set(fScale / fScaleDepth);
m_effect.GetVariableByName("xFar").AsScalar().Set(100f);
m_effect.GetVariableByName("xNear").AsScalar().Set(0.1f);
m_inputLayout = new InputLayout(
device,
m_effect.GetTechniqueByIndex(0).GetPassByIndex(0).Description.Signature,
VertexPositionTextureNormal.LayoutElements);
m_device = device;
}
示例2: RenderModel
void RenderModel(Graphics.Content.Model10 model, SlimDX.Matrix entityWorld, Effect effect)
{
throw new NotImplementedException();
//if (model == null || !model.Visible || model.Mesh == null) return;
Matrix world = model.World * entityWorld;
world.M41 = (float)((int)world.M41);
world.M42 = (float)((int)world.M42);
world *= Matrix.Scaling(2f / (float)view.Viewport.Width, 2f / (float)view.Viewport.Height, 1) * Matrix.Translation(-1, -1, 0) * Matrix.Scaling(1, -1, 1);
world.M43 = 0.5f;
effect.GetVariableByName("World").AsMatrix().SetMatrix(world);
effect.GetVariableByName("Texture").AsResource().SetResource(model.TextureShaderView);
effect.GetTechniqueByName("Render").GetPassByIndex(0).Apply();
if (model.Mesh != null)
{
model.Mesh.Setup(view.Device10, view.Content.Acquire<InputLayout>(
new Content.VertexStreamLayoutFromEffect
{
Signature10 = effect.GetTechniqueByIndex(0).GetPassByIndex(0).Description.Signature,
Layout = model.Mesh.VertexStreamLayout
}));
model.Mesh.Draw(device);
}
}
示例3: Draw
internal override void Draw(SlimDX.Direct3D11.DeviceContext context)
{
Effect effect;
using (ShaderBytecode byteCode = ShaderBytecode.CompileFromFile("Graphics/Effects/default.fx", "bidon", "fx_5_0", ShaderFlags.OptimizationLevel3, EffectFlags.None))
{
effect = new Effect(context.Device, byteCode);
}
var technique = effect.GetTechniqueByIndex(1);
var pass = technique.GetPassByIndex(0);
InputLayout inputLayout = new InputLayout(context.Device, pass.Description.Signature, new[] {
new InputElement("POSITION", 0, SlimDX.DXGI.Format.R32G32B32_Float, 0),
new InputElement("COLOR", 0, SlimDX.DXGI.Format.R8G8B8A8_UNorm, InputElement.AppendAligned, 0)
});
DataStream vertices = new DataStream((Vector3.SizeInBytes + 4) * 6, true, true);
vertices.Write(new ColoredVertex(new Vector3(1.0f, 1.0f, 0.0f), new Color4(1.0f, 0.0f, 0.0f, 0.0f).ToArgb()));
vertices.Write(new ColoredVertex(new Vector3(-1.0f, 1.0f, 0.0f), new Color4(1.0f, 0.0f, 0.0f, 0.0f).ToArgb()));
vertices.Write(new ColoredVertex(new Vector3(-1.0f, -1.0f, 0.0f), new Color4(1.0f, 0.0f, 0.0f, 0.0f).ToArgb()));
vertices.Write(new ColoredVertex(new Vector3(-1.0f, -1.0f, 0.0f), new Color4(1.0f, 0.0f, 0.0f, 0.0f).ToArgb()));
vertices.Write(new ColoredVertex(new Vector3(1.0f, 1.0f, 0.0f), new Color4(1.0f, 0.0f, 0.0f, 0.0f).ToArgb()));
vertices.Write(new ColoredVertex(new Vector3(1.0f, -1.0f, 0.0f), new Color4(1.0f, 0.0f, 0.0f, 0.0f).ToArgb()));
vertices.Position = 0;
BufferDescription bd = new BufferDescription()
{
Usage = ResourceUsage.Default,
SizeInBytes = 16 * 6,
BindFlags = BindFlags.VertexBuffer,
CpuAccessFlags = CpuAccessFlags.None
};
var vertexBuffer = new SlimDX.Direct3D11.Buffer(context.Device, vertices, bd);
context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer, 16, 0));
//context.InputAssembler.SetIndexBuffer(indices, Format.R16_UInt, 0);
/* scale * rotation * translation */
Matrix worldMatrix = Matrix.Scaling(Scale) * Matrix.RotationYawPitchRoll(Rotation.Y, Rotation.X, Rotation.Z) * Matrix.Translation(Position);
Matrix viewMatrix = Camera.ViewMatrix;
Matrix projectionMatrix = Camera.ProjectionMatrix;
effect.GetVariableByName("finalMatrix").AsMatrix().SetMatrix(worldMatrix * viewMatrix * projectionMatrix);
context.InputAssembler.InputLayout = inputLayout;
context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleStrip;
pass.Apply(context);
context.Draw(6, 0);
}
示例4: EffectDescription
public EffectDescription(string filename)
{
this.filename = filename;
instanceParameters = new SortedList<string, InstanceParameter>();
staticParameters = new SortedList<string, SharedParameter>();
dynamicParameters = new SortedList<string, SharedParameter>();
effect = EffectManager.LoadEffect(Global.FXPath + filename);
if (effect == null)
Application.Exit();
else
technique = effect.GetTechniqueByIndex(0);
}
示例5: OnRestore
public bool OnRestore()
{
Dispose();
//parse
_mesh_parser.Create(_object_file_path, _device);
_mesh_object = _mesh_parser.GetMeshObj();
// initialize the effect
_effect = Effect.FromFile(_device, @"Shader/MeshFromOBJ10.fx", "fx_4_0", ShaderFlags.EnableStrictness | ShaderFlags.Debug, EffectFlags.None);
EffectTechnique technique = _effect.GetTechniqueByIndex(0);
EffectPass pass = technique.GetPassByIndex(0);
_input_layout = new InputLayout(_device, pass.Description.Signature, PositionNormalTextureVertex.InputElements);
return true;
}
示例6: Main
public static void Main(string[] args)
{
Device device;
Effect effect;
device = new Device(DriverType.Hardware, DeviceCreationFlags.None);
if (args.Length < 1)
{
Console.WriteLine("Usage: dumptech.exe <effect file>");
return;
}
string effect_file = args[0];
if (! File.Exists(effect_file))
{
Console.WriteLine("File not found: " + effect_file);
return;
}
try
{
var shader_bytecode = ShaderBytecode.FromFile(effect_file);
effect = new Effect(device, shader_bytecode);
}
catch (SharpDX.CompilationException e)
{
Console.WriteLine(e.Message + ": " + effect_file);
return;
}
//Console.WriteLine("technique count {0}", effect.Description.TechniqueCount);
for (int i = 0; i < effect.Description.TechniqueCount; i++)
{
var technique = effect.GetTechniqueByIndex(i);
Console.WriteLine("{0}\t{1}", i, technique.Description.Name);
}
if (effect != null)
effect.Dispose();
if (device != null)
device.Dispose();
}
示例7: DefaultRenderer
public DefaultRenderer(Device graphicsDevice, Camera camera, VoxelMeshContainer container)
{
this.graphicsDevice = graphicsDevice;
this.camera = camera;
this.container = container;
#if DEBUG
shader = new Effect(graphicsDevice, ShaderPrecompiler.PrecompileOrLoad(@"Shaders\VoxelMesh.hlsl", "fx_5_0", ShaderFlags.Debug, EffectFlags.None));
#else
shader = new Effect(graphicsDevice, ShaderPrecompiler.PrecompileOrLoad(@"Shaders\VoxelMesh.hlsl", "fx_5_0", ShaderFlags.None, EffectFlags.None));
#endif
layout = new InputLayout(graphicsDevice, shader.GetTechniqueByIndex(0).GetPassByIndex(0).Description.Signature, new[]
{
new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0, InputClassification.PerVertexData, 0),
new InputElement("NORMAL", 0, Format.R32G32B32_Float, 12, 0, InputClassification.PerVertexData, 0),
new InputElement("AMBIENT", 0, Format.R32_Float, 24, 0, InputClassification.PerVertexData, 0)
});
}
示例8: TestTriangle
public TestTriangle(SlimDX.Direct3D11.Device Device)
{
using (ShaderBytecode bytecode = ShaderBytecode.CompileFromFile(@"R:\Users\Rox Cox\Documents\Visual Studio 2013\Projects\LightingEngine_v2\LightingEngine_v2\test.fx", "fx_5_0"))
{
try
{
SampleEffect = new Effect(Device, bytecode);
}
catch (Exception e)
{
throw e;
}
}
using (ShaderBytecode bytecode = ShaderBytecode.CompileFromFile(@"R:\Users\Rox Cox\Documents\Visual Studio 2013\Projects\LightingEngine_v2\LightingEngine_v2\test.fx", "VSTri", "vs_5_0", ShaderFlags.None, EffectFlags.None))
{
VS = new VertexShader(Device, bytecode);
}
EffectTechnique technique = SampleEffect.GetTechniqueByIndex(0);
EffectPass pass = technique.GetPassByIndex(0);
SampleLayout = new InputLayout(Device, pass.Description.Signature, new[] {
new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0)
});
SampleStream = new DataStream(4 * 32, true, true);
SampleStream.WriteRange(new[] {
new Vector4(1.0f, 1.0f, 0.5f, 1.0f), new Vector4(0.0f, 0.8f, 1.0f, 1.0f),
new Vector4(1.0f, -1.0f, 0.5f, 1.0f), new Vector4(0.3f, 1.0f, 0.3f, 1.0f),
new Vector4(-1.0f, -1.0f, 0.5f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
new Vector4(-1.0f, 1.0f, 0.5f, 1.0f), new Vector4(0.0f, 0.8f, 1.0f, 1.0f),
});
SampleStream.Position = 0;
SampleVertices = new SlimDX.Direct3D11.Buffer(Device, SampleStream, new BufferDescription()
{
BindFlags = BindFlags.VertexBuffer,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None,
SizeInBytes = 3 * 32,
Usage = ResourceUsage.Default
});
}
示例9: ThreadView
public ThreadView(Connection conn, Scene scene)
{
m_connection = conn;
m_device = scene.Device;
m_context = m_device.ImmediateContext;
var bytecode = ShaderBytecode.CompileFromFile(RenderSupport.ContentPath + "\\Universe.fx", "fx_5_0", ShaderFlags.None, EffectFlags.None);
m_effect = new Effect(m_device, bytecode);
var pass = m_effect.GetTechniqueByIndex(0).GetPassByIndex(0);
m_layout = new InputLayout(m_device, pass.Description.Signature, QuadVertex.Elements);
m_vertices = new SlimDX.Direct3D11.Buffer(m_device, new BufferDescription()
{
CpuAccessFlags = CpuAccessFlags.Write,
BindFlags = BindFlags.VertexBuffer,
SizeInBytes = 6 * MaxQuads * QuadVertex.SizeBytes,
Usage = ResourceUsage.Dynamic
});
m_texture = Texture2D.FromFile(m_device, RenderSupport.ContentPath + "\\stars.png");
m_textureView = new ShaderResourceView(m_device, m_texture);
}
示例10: InitScene
private void InitScene()
{
_effect = Effect.FromFile(_dev_manager.Device, @"Shader\MiniTri.fx", "fx_4_0");
EffectTechnique technique = _effect.GetTechniqueByIndex(0);
EffectPass pass = technique.GetPassByIndex(0);
_input_layout = new InputLayout(_dev_manager.Device, pass.Description.Signature, ColoredVertex.InputElements);
//Triangle triangle = new Triangle(new Vector3(-1, 0, 0), new Vector3(1, 0, 0), new Vector3(0, 1, 0) );
Vector3[] quad =
{
new Vector3(-0.5f, 0.5f, 0), // top left
new Vector3(0.5f, 0.5f, 0), // top right
new Vector3(-0.5f, -0.5f, 0), // bottom left
new Vector3(0.5f, -0.5f, 0), // bottom right
};
ColoredVertex[] colored_quad = {
new ColoredVertex(quad[0], new Color4(1, 0, 0, 1)),
new ColoredVertex(quad[1], new Color4(1, 0, 0, 1)),
new ColoredVertex(quad[2], new Color4(1, 0, 0, 1)),
new ColoredVertex(quad[3], new Color4(1, 0, 0, 1)),
};
// size in bytes (quad: (3x4)x4 + color:(4x4)x4
DataStream quad_stream = new DataStream(ColoredVertex.SizeOf * quad.Length, true, true);
quad_stream.WriteRange(colored_quad);
quad_stream.Position = 0;
_vbuffer = new Buffer(_dev_manager.Device, quad_stream, new BufferDescription()
{
BindFlags = BindFlags.VertexBuffer,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None,
Usage = ResourceUsage.Default,
SizeInBytes = ColoredVertex.SizeOf * colored_quad.Length
});
}
示例11: PrepareShaders
private void PrepareShaders()
{
using (ShaderBytecode byteCode = ShaderBytecode.CompileFromFile("Effet.fx", "bidon", "fx_5_0", ShaderFlags.OptimizationLevel3, EffectFlags.None))
{
effect = new Effect(device11, byteCode);
}
var technique = effect.GetTechniqueByIndex(0);
var pass = technique.GetPassByIndex(0);
layout = new InputLayout(device11, pass.Description.Signature, new[] {
new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0),
new InputElement("TEXCOORD", 0, Format.R32G32_Float, 12, 0)
});
}
示例12: Render
/// <summary>
/// Renders the bounding box for debugging purposes.
/// </summary>
/// <param name="box">The box to render.</param>
/// <param name="graphicsDevice">The graphics device to use when rendering.</param>
/// <param name="view">The current view matrix.</param>
/// <param name="projection">The current projection matrix.</param>
/// <param name="color">The color to use for drawing the lines of the box.</param>
public static void Render(
BoundingBox box,
Device graphicsDevice,
Matrix world,
Matrix view,
Matrix projection,
Color4 color)
{
if (effect == null)
{
effect = Ressources.EffectCache.Get("Shaders\\basic_effect.fx");
vertexBuffer = new Buffer(Scene.GetGraphicsDevice(), 8 * sizeof(float) * 4, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0);
/*
*
vBuffer = new SlimDX.Direct3D11.Buffer(Scene.GetGraphicsDevice(), vBuffStream, new BufferDescription()
{
BindFlags = BindFlags.VertexBuffer,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None,
SizeInBytes = (int)vBuffStream.Length,
Usage = ResourceUsage.Default
});*/
DataStream stream = new DataStream(sizeof(int) * indices.Length, false, true);
stream.WriteRange<int>(indices);
stream.Position = 0;
indexBuffer = new SlimDX.Direct3D11.Buffer(Scene.GetGraphicsDevice(), stream, new BufferDescription()
{
BindFlags = BindFlags.IndexBuffer,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None,
SizeInBytes = (int)stream.Length,
Usage = ResourceUsage.Default
});
stream.Dispose();
var sign = effect.GetTechniqueByIndex(0).GetPassByIndex(0).Description.Signature;
inLayout = new InputLayout(
Scene.GetGraphicsDevice(),
effect.GetTechniqueByIndex(0).GetPassByIndex(0).Description.Signature,
new InputElement[] {
new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0)
});
}
effect.GetVariableByName("xColor").AsVector().Set(color);
Vector3[] corners = box.GetCorners();
for (int i = 0; i < 8; i++)
{
verts[i] = new Vector4(corners[i], 1.0f);
}
var data = Scene.GetGraphicsDevice().ImmediateContext.MapSubresource(vertexBuffer, 0, MapMode.WriteDiscard, SlimDX.Direct3D11.MapFlags.None);
data.Data.WriteRange(verts);
Scene.GetGraphicsDevice().ImmediateContext.UnmapSubresource(vertexBuffer, 0);
Scene.GetGraphicsDevice().ImmediateContext.InputAssembler.InputLayout = inLayout;
Scene.GetGraphicsDevice().ImmediateContext.InputAssembler.SetIndexBuffer(indexBuffer, Format.R32_UInt, 0);
Scene.GetGraphicsDevice().ImmediateContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer, 16, 0));
Scene.GetGraphicsDevice().ImmediateContext.InputAssembler.PrimitiveTopology = (PrimitiveTopology.LineList);
effect.GetVariableByName("World").AsMatrix().SetMatrix(world);
effect.GetVariableByName("View").AsMatrix().SetMatrix(view);
effect.GetVariableByName("Projection").AsMatrix().SetMatrix(projection);
for (int i = 0; i < effect.GetTechniqueByIndex(0).Description.PassCount; i++)
{
effect.GetTechniqueByIndex(0).GetPassByIndex(i).Apply(Scene.GetGraphicsDevice().ImmediateContext);
Scene.GetGraphicsDevice().ImmediateContext.DrawIndexed(indexBuffer.Description.SizeInBytes / sizeof(int), 0, 0);
}
}
示例13: InitD3D
void InitD3D()
{
D3DDevice = new Device(DriverType.Hardware, DeviceCreationFlags.Debug | DeviceCreationFlags.BgraSupport, FeatureLevel.Level_10_0);
Texture2DDescription colordesc = new Texture2DDescription();
colordesc.BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource;
colordesc.Format = Format.B8G8R8A8_UNorm;
colordesc.Width = WindowWidth;
colordesc.Height = WindowHeight;
colordesc.MipLevels = 1;
colordesc.SampleDescription = new SampleDescription(1, 0);
colordesc.Usage = ResourceUsage.Default;
colordesc.OptionFlags = ResourceOptionFlags.Shared;
colordesc.CpuAccessFlags = CpuAccessFlags.None;
colordesc.ArraySize = 1;
Texture2DDescription depthdesc = new Texture2DDescription();
depthdesc.BindFlags = BindFlags.DepthStencil;
depthdesc.Format = Format.D32_Float_S8X24_UInt;
depthdesc.Width = WindowWidth;
depthdesc.Height = WindowHeight;
depthdesc.MipLevels = 1;
depthdesc.SampleDescription = new SampleDescription(1, 0);
depthdesc.Usage = ResourceUsage.Default;
depthdesc.OptionFlags = ResourceOptionFlags.None;
depthdesc.CpuAccessFlags = CpuAccessFlags.None;
depthdesc.ArraySize = 1;
SharedTexture = new Texture2D(D3DDevice, colordesc);
DepthTexture = new Texture2D(D3DDevice, depthdesc);
SampleRenderView = new RenderTargetView(D3DDevice, SharedTexture);
SampleDepthView = new DepthStencilView(D3DDevice, DepthTexture);
SampleEffect = Effect.FromFile(D3DDevice, "MiniTri.fx", "fx_4_0");
EffectTechnique technique = SampleEffect.GetTechniqueByIndex(0); ;
EffectPass pass = technique.GetPassByIndex(0);
SampleLayout = new InputLayout(D3DDevice, pass.Description.Signature, new[] {
new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0)
});
SampleStream = new DataStream(3 * 32, true, true);
SampleStream.WriteRange(new[] {
new Vector4(0.0f, 0.5f, 0.5f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
new Vector4(0.5f, -0.5f, 0.5f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
new Vector4(-0.5f, -0.5f, 0.5f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f)
});
SampleStream.Position = 0;
SampleVertices = new Buffer(D3DDevice, SampleStream, new BufferDescription()
{
BindFlags = BindFlags.VertexBuffer,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None,
SizeInBytes = 3 * 32,
Usage = ResourceUsage.Default
});
D3DDevice.Flush();
}
示例14: OnLoad
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
SwapChainDescription desc = new SwapChainDescription()
{
BufferCount = 2,
Flags = SwapChainFlags.AllowModeSwitch,
IsWindowed = true,
ModeDescription = new ModeDescription()
{
Format = Format.R8G8B8A8_UNorm,
Height = Height,
Width = Width,
RefreshRate = new Rational(1, 60),
Scaling = DisplayModeScaling.Centered,
ScanlineOrdering = DisplayModeScanlineOrdering.Progressive
},
OutputHandle = Handle,
SampleDescription = new SampleDescription(1, 0),
SwapEffect = SwapEffect.Discard,
Usage = Usage.RenderTargetOutput
};
Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None,
new FeatureLevel[1] { FeatureLevel.Level_11_0 }, desc, out device, out swapChain);
using (Texture2D tex = Texture2D.FromSwapChain<Texture2D>(swapChain, 0))
{
renderTarget = new RenderTargetView(device, tex);
}
using (Texture2D depthTex = new Texture2D(device, new Texture2DDescription()
{
ArraySize = 1,
BindFlags = BindFlags.DepthStencil,
Width = Width,
Height = Height,
SampleDescription = new SampleDescription(1, 0),
Usage = ResourceUsage.Default,
Format = Format.D32_Float,
CpuAccessFlags = CpuAccessFlags.None,
MipLevels = 1,
OptionFlags = ResourceOptionFlags.None
}))
{
depthTarget = new DepthStencilView(device, depthTex);
}
//四角形の頂点を表すリスト
Vector4[] verticies = new Vector4[]
{
new Vector4(-0.5f,0.75f,5f,1f),//左上手前の三角形
new Vector4(0f,0f,5f,1f),
new Vector4(-1f,0f,5f,1f),
new Vector4(0f,1f,10f,1f),//中央奥の大きい三角形
new Vector4(1f,-0.5f,10f,1f),
new Vector4(-1f,-0.5f,10f,1f),
};
using (DataStream ds = new DataStream(verticies, true, true))
{
vertexBuffer = new Buffer(device, ds, new BufferDescription()
{
BindFlags = BindFlags.VertexBuffer,
SizeInBytes = (int)ds.Length,
});
}
using (ShaderBytecode compiledCode = ShaderBytecode.CompileFromFile("shader.fx", "fx_5_0", ShaderFlags.Debug, EffectFlags.None))
{
effect = new Effect(device, compiledCode);
}
inputLayout = new InputLayout(device, effect.GetTechniqueByIndex(0).GetPassByIndex(0).Description.Signature, new InputElement[]
{
new InputElement()
{
SemanticName = "POSITION",
Format = Format.R32G32B32A32_Float
},
});
device.ImmediateContext.Rasterizer.SetViewports(new Viewport[] { new Viewport(0, 0, Width, Height, 0, 1), });
projection = Matrix.PerspectiveFovLH((float)Math.PI / 4f, Width/Height, 0.1f, 15);
}
示例15: Initialize
private void Initialize()
{
// デバイスとスワップチェイン
SlimDX.Direct3D11.Device.CreateWithSwapChain(
DriverType.Hardware,
DeviceCreationFlags.None,
new SwapChainDescription
{
BufferCount = 1,
OutputHandle = Handle,
IsWindowed = true,
SampleDescription = new SampleDescription
{
Count = 1,
Quality = 0,
},
ModeDescription = new ModeDescription
{
Width = ClientSize.Width,
Height = ClientSize.Height,
RefreshRate = new Rational(60, 1),
Format = Format.B8G8R8A8_UNorm,
},
Usage = Usage.RenderTargetOutput,
},
out graphicsDevice,
out swapChain);
// レンダーターゲット
using (var backBuffer =
SlimDX.Direct3D11.Resource.FromSwapChain<Texture2D>(swapChain, 0))
{
renderTarget = new RenderTargetView(graphicsDevice, backBuffer);
graphicsDevice.ImmediateContext.OutputMerger.SetTargets(renderTarget);
}
// ビューポート
graphicsDevice.ImmediateContext.Rasterizer
.SetViewports(
new Viewport
{
Width = ClientSize.Width,
Height = ClientSize.Height,
});
// エフェクト
using (var shaderByteCode =
ShaderBytecode.CompileFromFile(
"Resources/MyEffect.fx", "fx_5_0",
ShaderFlags.None, EffectFlags.None))
{
effect =
new Effect(graphicsDevice, shaderByteCode);
}
// 入力レイアウト
inputLayout = new InputLayout(
graphicsDevice,
effect.GetTechniqueByIndex(0).GetPassByIndex(0)
.Description.Signature,
new[]
{
new InputElement
{
SemanticName = "SV_Position",
Format = Format.R32G32B32_Float,
},
});
// 頂点バッファー
using (var vertexStream =
new DataStream(new[]
{
new Vector3(0, 0.5f, 0),
new Vector3(0.5f, 0, 0),
new Vector3(-0.5f, 0, 0),
}, true, true))
{
vertexBuffer =
new Buffer(graphicsDevice, vertexStream,
new BufferDescription
{
SizeInBytes = (int)vertexStream.Length,
BindFlags = BindFlags.VertexBuffer,
});
}
}