public TextureArraySetSlice(DX11RenderContext context) { this.context = context; this.shader = ShaderUtils.GetShader(context, "SetSlice"); this.quad = context.Primitives.FullScreenQuad; this.quad.ValidateLayout(this.shader.GetPass(0), out this.layout); }
public void Update(DX11RenderContext context) { if (this.FInvalidate || this.FEmpty) { for (int i = 0; i < this.scenes.Count; i++) { if (scenes[i] != null) { AssimpScene scene = scenes[i]; for (int j = 0; j < scene.MeshCount; j++) { AssimpMesh assimpmesh = scene.Meshes[j]; DataStream vS = assimpmesh.Vertices; vS.Position = 0; List <int> inds = assimpmesh.Indices; if (inds.Count > 0 && assimpmesh.VerticesCount > 0) { var vertices = new SlimDX.Direct3D11.Buffer(context.Device, vS, new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = (int)vS.Length, Usage = ResourceUsage.Default }); var indexstream = new DataStream(inds.Count * 4, true, true); indexstream.WriteRange(inds.ToArray()); indexstream.Position = 0; DX11IndexedGeometry geom = new DX11IndexedGeometry(context); geom.VertexBuffer = vertices; geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true); geom.InputLayout = assimpmesh.GetInputElements().ToArray(); geom.Topology = PrimitiveTopology.TriangleList; geom.VerticesCount = assimpmesh.VerticesCount; geom.VertexSize = assimpmesh.CalculateVertexSize(); geom.HasBoundingBox = true; geom.BoundingBox = assimpmesh.BoundingBox; this.FOutGeom[i][j][context] = geom; } } } } this.FEmpty = false; this.FInvalidate = false; } }
public void Update(IPluginIO pin, DX11RenderContext context) { if (this.FInvalidate || !this.FOutput[0].Data.ContainsKey(context)) { for (int i = 0; i < oldSpreadMax; i++) { DX11IndexedGeometry geom = this.GetGeom(context, i); this.FOutput[i][context] = geom; } } }
public void Update(IPluginIO pin, DX11RenderContext context) { if (this.FInvalidate || !this.FOutput[0].Data.ContainsKey(context)) { for (int i = 0; i < this.FOutput.SliceCount; i++) { if (this.FOutput[i].Contains(context)) { this.FOutput[i].Dispose(context); } } for (int i = 0; i < this.FOutput.SliceCount; i++) { Pos4Norm3Tex2Vertex[] vertices = this.FVertex[i]; int[] indices = this.FIndices[i]; DataStream ds = new DataStream(vertices.Length * Pos4Norm3Tex2Vertex.VertexSize, true, true); ds.Position = 0; ds.WriteRange(vertices); ds.Position = 0; var vbuffer = new SlimDX.Direct3D11.Buffer(context.Device, ds, new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = (int)ds.Length, Usage = ResourceUsage.Default }); ds.Dispose(); var indexstream = new DataStream(indices.Length * 4, true, true); indexstream.WriteRange(indices); indexstream.Position = 0; DX11IndexedGeometry geom = new DX11IndexedGeometry(context); geom.VertexBuffer = vbuffer; geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true); geom.InputLayout = Pos4Norm3Tex2Vertex.Layout; geom.Topology = PrimitiveTopology.TriangleList; geom.VerticesCount = vertices.Length; geom.VertexSize = Pos4Norm3Tex2Vertex.VertexSize; geom.HasBoundingBox = false; this.FOutput[i][context] = geom; } } this.FInvalidate = false; }
public DX11IndexedGeometry QuadNormals(Quad settings) { DX11IndexedGeometry geom = new DX11IndexedGeometry(context); geom.Tag = settings; geom.PrimitiveType = settings.PrimitiveType; Vector2 size = settings.Size; DataStream ds = new DataStream(4 * Pos4Norm3Tex2Vertex.VertexSize, true, true); ds.Position = 0; float sx = 0.5f * size.X; float sy = 0.5f * size.Y; Pos4Norm3Tex2Vertex v = new Pos4Norm3Tex2Vertex(); v.Position = new Vector4(-sx, sy, 0.0f, 1.0f); v.Normals = new Vector3(0, 0, 1); v.TexCoords = new Vector2(0, 0); ds.Write <Pos4Norm3Tex2Vertex>(v); v.Position = new Vector4(sx, sy, 0.0f, 1.0f); v.TexCoords = new Vector2(1, 0); ds.Write <Pos4Norm3Tex2Vertex>(v); v.Position = new Vector4(-sx, -sy, 0.0f, 1.0f); v.TexCoords = new Vector2(0, 1); ds.Write <Pos4Norm3Tex2Vertex>(v); v.Position = new Vector4(sx, -sy, 0.0f, 1.0f); v.TexCoords = new Vector2(1, 1); ds.Write <Pos4Norm3Tex2Vertex>(v); var vertices = BufferHelper.CreateVertexBuffer(context, ds, true); var indexstream = new DataStream(24, true, true); indexstream.WriteRange(new int[] { 0, 1, 3, 3, 2, 0 }); geom.VertexBuffer = vertices; geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true); geom.InputLayout = Pos4Norm3Tex2Vertex.Layout; geom.Topology = PrimitiveTopology.TriangleList; geom.VerticesCount = 4; geom.VertexSize = Pos4Norm3Tex2Vertex.VertexSize; geom.HasBoundingBox = true; geom.BoundingBox = new BoundingBox(new Vector3(-sx, -sy, 0.0f), new Vector3(sx, sy, 0.0f)); return(geom); }
public static IDX11Geometry CreateIndexedGeometry(DX11RenderContext context, List <Vector3> points, List <Vector3> normals, List <Vector2> tex, int[] indices) { var count = points.Count; Pos3Norm3Tex2Vertex[] vertices = new Pos3Norm3Tex2Vertex[count]; for (int i = 0; i < count; i++) { vertices[i] = new Pos3Norm3Tex2Vertex() { Position = points[i], Normals = normals[i % normals.Count], TexCoords = tex[i % tex.Count] }; } DataStream ds = new DataStream(vertices.Length * Pos3Norm3Tex2Vertex.VertexSize, true, true); ds.Position = 0; ds.WriteRange(vertices); ds.Position = 0; var vbuffer = new SlimDX.Direct3D11.Buffer(context.Device, ds, new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = (int)ds.Length, Usage = ResourceUsage.Default }); ds.Dispose(); var indexstream = new DataStream(indices.Length * 4, true, true); indexstream.WriteRange(indices); indexstream.Position = 0; DX11IndexedGeometry geom = new DX11IndexedGeometry(context); geom.VertexBuffer = vbuffer; geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true); geom.InputLayout = Pos3Norm3Tex2Vertex.Layout; geom.Topology = PrimitiveTopology.TriangleList; geom.VerticesCount = count; geom.VertexSize = Pos3Norm3Tex2Vertex.VertexSize; geom.HasBoundingBox = false; return(geom); }
public void Update(DX11RenderContext context) { if (this.FInvalidate || !this.FOutput[0].Contains(context)) { for (int i = 0; i < oldSpreadMax; i++) { DX11IndexedGeometry geom = this.GetGeom(context, i); this.FOutput[i][context] = geom; } this.FInvalidate = false; } }
public PrimitivesManager(RenderDevice device) { this.device = device; this.quad = this.QuadTextured(); this.fulltri = new DX11NullGeometry(device, 3); this.fulltri.Topology = PrimitiveTopology.TriangleList; this.LinearSampler = device.SamplerStates.LinearClamp; this.cbLuma = new ConstantBuffer <float>(device, true); this.InitializeDelegates(); this.PrepareBasicShaders(); }
public DX11IndexedGeometry Tetrahedron(Tetrahedron settings) { DX11IndexedGeometry geom = new DX11IndexedGeometry(context); geom.Tag = settings; geom.PrimitiveType = settings.PrimitiveType; geom.VerticesCount = 4; geom.InputLayout = Pos3Norm3Tex2Vertex.Layout; geom.VertexSize = Pos3Norm3Tex2Vertex.VertexSize; geom.Topology = PrimitiveTopology.TriangleList; DataStream ds = new DataStream(4 * Pos3Norm3Tex2Vertex.VertexSize, false, true); Pos3Norm3Tex2Vertex v = new Pos3Norm3Tex2Vertex(); v.Position = Vector3.Normalize(new Vector3(1, 1, 1)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); v.Position *= settings.Radius; ds.Write <Pos3Norm3Tex2Vertex>(v); v.Position = Vector3.Normalize(new Vector3(-1, -1, 1)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); v.Position *= settings.Radius; ds.Write <Pos3Norm3Tex2Vertex>(v); v.Position = Vector3.Normalize(new Vector3(1, -1, -1)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); v.Position *= settings.Radius; ds.Write <Pos3Norm3Tex2Vertex>(v); v.Position = Vector3.Normalize(new Vector3(-1, 1, -1)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); v.Position *= settings.Radius; ds.Write <Pos3Norm3Tex2Vertex>(v); geom.VertexBuffer = BufferHelper.CreateVertexBuffer(context, ds, true); var indexstream = new DataStream(12 * 4, true, true); int[] inds = new int[] { 0, 1, 2, 1, 2, 3, 2, 3, 0, 3, 0, 1 }; indexstream.WriteRange(inds); geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true); geom.HasBoundingBox = true; geom.BoundingBox = new BoundingBox(new Vector3(-1, -1, -1), new Vector3(1, 1, 1)); return(geom); }
public DX11IndexedGeometry IcoSphere(IcoSphere settings) { float radius = settings.Radius; IcoSphereBuilder builder = new IcoSphereBuilder(); PrimitiveInfo info = builder.GetPrimitiveInfo(settings); ListGeometryAppender appender = new ListGeometryAppender(); builder.Construct(settings, appender.AppendVertex, appender.AppendIndex); DX11IndexedGeometry geom = FromAppender(settings, appender, info); geom.BoundingBox = new BoundingBox(new Vector3(-radius), new Vector3(radius)); return(geom); }
public DX11IndexedGeometry Tetrahedron(Vector3 size) { DX11IndexedGeometry geom = new DX11IndexedGeometry(context); geom.VerticesCount = 4; geom.InputLayout = Pos3Norm3Tex2Vertex.Layout; geom.VertexSize = Pos3Norm3Tex2Vertex.VertexSize; geom.Topology = PrimitiveTopology.TriangleList; // This is the golden ratio float t = (1.0f + (float)Math.Sqrt(5.0f)) / 2.0f; DataStream ds = new DataStream(4 * Pos3Norm3Tex2Vertex.VertexSize, false, true); Pos3Norm3Tex2Vertex v = new Pos3Norm3Tex2Vertex(); // TODO fibo 2012-03-21: // should be nice to have the four tetrahedra embedded in a dodecahedron // that's why I just commented the coordinates of the dodecahedron points //v.Position = new Vector3(-1, t, 0); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v); v.Position = new Vector3(1, t, 0); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v); //v.Position = new Vector3(-1, -t, 0); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v); //v.Position = new Vector3(1, -t, 0); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v); //v.Position = new Vector3(0, -1, t); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v); v.Position = new Vector3(0, 1, t); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v); //v.Position = new Vector3(0, -1, -t); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v); //v.Position = new Vector3(0, 1, -t); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v); //v.Position = new Vector3(t, 0, -1); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v); v.Position = new Vector3(t, 0, 1); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v); //v.Position = new Vector3(-t, 0, -1); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v); //v.Position = new Vector3(-t, 0, 1); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v); geom.VertexBuffer = BufferHelper.CreateVertexBuffer(context, ds, true); var indexstream = new DataStream(12 * 4, true, true); int[] inds = new int[] { 0,1,2, 1,2,3, 2,3,0, 3,0,1 }; indexstream.WriteRange(inds); geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true); geom.HasBoundingBox = true; geom.BoundingBox = new BoundingBox(new Vector3(-1, -1, -1), new Vector3(1, 1, 1)); return geom; }
public DX11IndexedGeometry QuadNormals(Quad settings) { DX11IndexedGeometry geom = new DX11IndexedGeometry(context); geom.Tag = settings; geom.PrimitiveType = settings.PrimitiveType; Vector2 size = settings.Size; DataStream ds = new DataStream(4 * Pos4Norm3Tex2Vertex.VertexSize, true, true); ds.Position = 0; float sx = 0.5f * size.X; float sy = 0.5f * size.Y; Pos4Norm3Tex2Vertex v = new Pos4Norm3Tex2Vertex(); v.Position = new Vector4(-sx, sy, 0.0f, 1.0f); v.Normals = new Vector3(0, 0, 1); v.TexCoords = new Vector2(0, 0); ds.Write<Pos4Norm3Tex2Vertex>(v); v.Position = new Vector4(sx, sy, 0.0f, 1.0f); v.TexCoords = new Vector2(1, 0); ds.Write<Pos4Norm3Tex2Vertex>(v); v.Position = new Vector4(-sx, -sy, 0.0f, 1.0f); v.TexCoords = new Vector2(0, 1); ds.Write<Pos4Norm3Tex2Vertex>(v); v.Position = new Vector4(sx, -sy, 0.0f, 1.0f); v.TexCoords = new Vector2(1, 1); ds.Write<Pos4Norm3Tex2Vertex>(v); var vertices = BufferHelper.CreateVertexBuffer(context, ds, true); var indexstream = new DataStream(24, true, true); indexstream.WriteRange(new int[] { 0, 1, 3, 3, 2, 0 }); geom.VertexBuffer = vertices; geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true); geom.InputLayout = Pos4Norm3Tex2Vertex.Layout; geom.Topology = PrimitiveTopology.TriangleList; geom.VerticesCount = 4; geom.VertexSize = Pos4Norm3Tex2Vertex.VertexSize; geom.HasBoundingBox = true; geom.BoundingBox = new BoundingBox(new Vector3(-sx, -sy, 0.0f), new Vector3(sx, sy, 0.0f)); return geom; }
public DX11IndexedGeometry RoundRect(RoundRect settings) { Vector2 inner = settings.InnerRadius; float outer = settings.OuterRadius; int ires = settings.CornerResolution; DX11IndexedGeometry geom = new DX11IndexedGeometry(device); geom.PrimitiveType = settings.PrimitiveType; geom.Tag = settings; List <Pos4Norm3Tex2Vertex> vl = new List <Pos4Norm3Tex2Vertex>(); List <int> il = new List <int>(); int idx = 0; float ucy = Convert.ToSingle(inner.Y + outer); float ucx = Convert.ToSingle(inner.X + outer); float mx = ucx * 2.0f; float my = ucy * 2.0f; //Need 1 quad for center if (settings.EnableCenter) { idx = SetQuad(vl, il, 0.0f, 0.0f, inner.X, inner.Y, idx, mx, my); } //Need 2 quads up/down idx = SetQuad(vl, il, 0.0f, ucy, inner.X, (float)outer, idx, mx, my); idx = SetQuad(vl, il, 0.0f, -ucy, inner.X, (float)outer, idx, mx, my); //Need 2 quads left/right idx = SetQuad(vl, il, -ucx, 0.0f, (float)outer, inner.Y, idx, mx, my); idx = SetQuad(vl, il, ucx, 0.0f, (float)outer, inner.Y, idx, mx, my); float radius = (float)outer * 2.0f; //Add the 4 corners idx = SetSegment(vl, il, inner.X, inner.Y, 0.0f, radius, ires, idx, mx, my); idx = SetSegment(vl, il, -inner.X, inner.Y, 0.25f, radius, ires, idx, mx, my); idx = SetSegment(vl, il, -inner.X, -inner.Y, 0.5f, radius, ires, idx, mx, my); idx = SetSegment(vl, il, inner.X, -inner.Y, 0.75f, radius, ires, idx, mx, my); geom.VertexBuffer = DX11VertexBuffer.CreateImmutable <Pos4Norm3Tex2Vertex>(device, vl.ToArray()); geom.IndexBuffer = DX11IndexBuffer.CreateImmutable(device, il.ToArray()); geom.InputLayout = Pos4Norm3Tex2Vertex.Layout; geom.Topology = PrimitiveTopology.TriangleList; geom.HasBoundingBox = false; return(geom); }
private DX11IndexedGeometry FromAppender(AbstractPrimitiveDescriptor descriptor, ListGeometryAppender appender, PrimitiveInfo info) { DX11IndexedGeometry geom = new DX11IndexedGeometry(device); geom.Tag = descriptor; geom.PrimitiveType = descriptor.PrimitiveType; geom.VertexBuffer = DX11VertexBuffer.CreateImmutable(device, appender.Vertices.ToArray()); geom.IndexBuffer = DX11IndexBuffer.CreateImmutable(device, appender.Indices.ToArray()); geom.InputLayout = Pos4Norm3Tex2Vertex.Layout; geom.Topology = PrimitiveTopology.TriangleList; geom.HasBoundingBox = info.IsBoundingBoxKnown; geom.BoundingBox = info.BoundingBox; return(geom); }
public BulletImmediateWorldDebugRenderer(DX11RenderContext context) { if (context == null) { throw new ArgumentNullException("context"); } this.context = context; this.solidColorShader = new SolidColorTransformed(context); this.box = context.Primitives.Box(new FeralTic.DX11.Geometry.Box()); this.sphere = context.Primitives.Sphere(new FeralTic.DX11.Geometry.Sphere() { Radius = 1.0f }); this.cylinder = context.Primitives.Cylinder(new Cylinder() { Length = 2.0f, Radius1 = 1.0f, Radius2 = 1.0f, }); this.box.ValidateLayout(this.solidColorShader.EffectPass, out this.boxSphereColorLayout); this.dynamicLine = new DX11VertexGeometry(context); this.dynamicLine.InputLayout = Pos3Vertex.Layout; this.dynamicLine.Topology = PrimitiveTopology.LineList; this.dynamicLine.VertexBuffer = BufferHelper.CreateDynamicVertexBuffer(context, 12 * 2); this.dynamicLine.VertexSize = Pos3Vertex.VertexSize; this.dynamicLine.VerticesCount = 2; this.dynamicLineTriangle = new DX11VertexGeometry(context); this.dynamicLineTriangle.InputLayout = Pos3Vertex.Layout; this.dynamicLineTriangle.Topology = PrimitiveTopology.LineStrip; this.dynamicLineTriangle.VertexBuffer = BufferHelper.CreateDynamicVertexBuffer(context, 12 * 3); this.dynamicLineTriangle.VertexSize = Pos3Vertex.VertexSize; this.dynamicLineTriangle.VerticesCount = 3; this.arcLine = new DX11VertexGeometry(context); this.arcLine.InputLayout = Pos3Vertex.Layout; this.arcLine.Topology = PrimitiveTopology.LineStrip; this.arcLine.VertexBuffer = BufferHelper.CreateDynamicVertexBuffer(context, 12 * 2048); this.arcLine.VertexSize = Pos3Vertex.VertexSize; this.arcLine.VerticesCount = 2048; this.dynamicLine.ValidateLayout(this.solidColorShader.EffectPass, out this.lineLayout); }
public DX11IndexedGeometry Octahedron(Octahedron settings) { DX11IndexedGeometry geom = new DX11IndexedGeometry(context); geom.PrimitiveType = settings.PrimitiveType; geom.Tag = settings; geom.VerticesCount = 6; geom.InputLayout = Pos3Norm3Tex2Vertex.Layout; geom.VertexSize = Pos3Norm3Tex2Vertex.VertexSize; geom.Topology = PrimitiveTopology.TriangleList; DataStream ds = new DataStream(6 * Pos3Norm3Tex2Vertex.VertexSize, false, true); Pos3Norm3Tex2Vertex v = new Pos3Norm3Tex2Vertex(); Vector3 size = settings.Size; v.Position = Vector3.Normalize(new Vector3(1.0f,0,0)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v); v.Position = Vector3.Normalize(new Vector3(-1.0f,0,0)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v); v.Position = Vector3.Normalize(new Vector3(0,1.0f,0)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v); v.Position = Vector3.Normalize(new Vector3(0,-1.0f,0)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v); v.Position = Vector3.Normalize(new Vector3(0,0,-1.0f)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v); v.Position = Vector3.Normalize(new Vector3(0,0, 1.0f)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v); geom.VertexBuffer = BufferHelper.CreateVertexBuffer(context, ds, true); var indexstream = new DataStream(24 * 4, true, true); int[] inds = new int[] { 0,4,2, 0,2,5, 0,3,4, 0,5,3, 1,2,4, 1,5,2, 1,4,3, 1,3,5 }; indexstream.WriteRange(inds); geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true); geom.HasBoundingBox = true; geom.BoundingBox = new BoundingBox(new Vector3(-1, -1, -1), new Vector3(1, 1, 1)); return geom; }
public DX11IndexedGeometry Box(Box settings) { DX11IndexedGeometry geom = new DX11IndexedGeometry(context); geom.Tag = settings; geom.PrimitiveType = settings.PrimitiveType; int vertexcount = 24; DataStream vertexstream = new DataStream(24 * Pos4Norm3Tex2Vertex.VertexSize, true, true); vertexstream.Position = 0; var indexstream = new DataStream(36 * 4, true, true); float sx = 0.5f * settings.Size.X; float sy = 0.5f * settings.Size.Y; float sz = 0.5f * settings.Size.Z; Vector3 s3 = new Vector3(sx, sy, sz); Vector4 size = new Vector4(sx, sy, sz, 1.0f); this.WriteFrontFace(vertexstream, indexstream, size); this.WriteBackFace(vertexstream, indexstream, size); this.WriteRightFace(vertexstream, indexstream, size); this.WriteLeftFace(vertexstream, indexstream, size); this.WriteTopFace(vertexstream, indexstream, size); this.WriteBottomFace(vertexstream, indexstream, size); var vertices = BufferHelper.CreateVertexBuffer(context, vertexstream, true); geom.VertexBuffer = vertices; geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true); geom.InputLayout = Pos4Norm3Tex2Vertex.Layout; geom.Topology = PrimitiveTopology.TriangleList; geom.VerticesCount = vertexcount; geom.VertexSize = Pos4Norm3Tex2Vertex.VertexSize; geom.HasBoundingBox = true; geom.BoundingBox = new BoundingBox(-s3, s3); return(geom); }
public void Update(DX11RenderContext context) { for (int i = 0; i < this.FOutGeom.SliceCount; i++) { DX11IndexedGeometry geom = (DX11IndexedGeometry)this.FInGeom[i][context].ShallowCopy(); if (this.FInEnabled[i]) { DX11InstancedIndexedDrawer d = new DX11InstancedIndexedDrawer(); d.InstanceCount = this.FInCnt[i]; d.StartIndexLocation = this.FInSI[0]; d.StartInstanceLocation = this.FInSL[0]; d.BaseVertexLocation = this.FInVL[0]; geom.AssignDrawer(d); //geom.Topology = this.FInTopology[i]; } this.FOutGeom[i][context] = geom; } }
public void Update(IPluginIO pin, DX11RenderContext context) { for (int i = 0; i < this.FOutGeom.SliceCount; i++) { IDX11Geometry g = this.FInGeom[i][context]; bool done = false; if (g is DX11IndexedGeometry) { DX11IndexedGeometry geom = (DX11IndexedGeometry)this.FInGeom[i][context].ShallowCopy(); if (this.FInEnabled[i]) { DX11InstancedIndexedDrawer d = new DX11InstancedIndexedDrawer(); d.InstanceCount = this.FInCnt[i]; d.StartInstanceLocation = this.FInSL[0]; geom.AssignDrawer(d); } this.FOutGeom[i][context] = geom; done = true; } if (g is DX11VertexGeometry) { DX11VertexGeometry geom = (DX11VertexGeometry)this.FInGeom[i][context].ShallowCopy(); if (this.FInEnabled[i]) { DX11InstancedVertexDrawer d = new DX11InstancedVertexDrawer(); d.InstanceCount = this.FInCnt[i]; d.StartInstanceLocation = this.FInSL[0]; geom.AssignDrawer(d); } this.FOutGeom[i][context] = geom; done = true; } if (!done) { this.FOutGeom[i][context] = g; } } }
private DX11IndexedGeometry QuadTextured() { DX11IndexedGeometry geom = new DX11IndexedGeometry(this.device); float sx = 1.0f; float sy = 1.0f; Pos4Tex2Vertex[] vertices = new Pos4Tex2Vertex[] { new Pos4Tex2Vertex() { Position = new Vector4(-sx, sy, 0.0f, 1.0f), TexCoords = new Vector2(0, 0) }, new Pos4Tex2Vertex() { Position = new Vector4(sx, sy, 0.0f, 1.0f), TexCoords = new Vector2(1, 0) }, new Pos4Tex2Vertex() { Position = new Vector4(-sx, -sy, 0.0f, 1.0f), TexCoords = new Vector2(0, 1) }, new Pos4Tex2Vertex() { Position = new Vector4(sx, -sy, 0.0f, 1.0f), TexCoords = new Vector2(1, 1) }, }; int[] indices = new int[] { 0, 1, 3, 3, 2, 0 }; geom.VertexBuffer = DX11VertexBuffer.CreateImmutable(device, vertices);; geom.IndexBuffer = DX11IndexBuffer.CreateImmutable(device, indices); geom.InputLayout = Pos4Tex2Vertex.Layout; geom.VertexBuffer.InputLayout = geom.InputLayout; geom.Topology = PrimitiveTopology.TriangleList; geom.HasBoundingBox = true; geom.BoundingBox = new BoundingBox(new Vector3(-sx, -sy, 0.0f), new Vector3(sx, sy, 0.0f)); return(geom); }
public void Update(IPluginIO pin, DX11RenderContext context) { Device device = context.Device; for (int i = 0; i < this.FOutGeom.SliceCount; i++) { if (this.FInEnabled[i] && this.FInGeom[i].Contains(context)) { DX11IndexedGeometry v = (DX11IndexedGeometry)this.FInGeom[i][context].ShallowCopy(); DX11PerVertexIndexedDrawer drawer = new DX11PerVertexIndexedDrawer(); v.AssignDrawer(drawer); this.FOutGeom[i][context] = v; } else { this.FOutGeom[i][context] = this.FInGeom[i][context]; } } }
public DX11IndexedGeometry Box(Box settings) { DX11IndexedGeometry geom = new DX11IndexedGeometry(device); geom.Tag = settings; geom.PrimitiveType = settings.PrimitiveType; DataStream vertexstream = new DataStream(24 * Pos4Norm3Tex2Vertex.VertexSize, true, true); vertexstream.Position = 0; var indexstream = new DataStream(36 * 4, true, true); float sx = 0.5f * settings.Size.X; float sy = 0.5f * settings.Size.Y; float sz = 0.5f * settings.Size.Z; Vector3 s3 = new Vector3(sx, sy, sz); Vector4 size = new Vector4(sx, sy, sz, 1.0f); this.WriteFrontFace(vertexstream, indexstream, size); this.WriteBackFace(vertexstream, indexstream, size); this.WriteRightFace(vertexstream, indexstream, size); this.WriteLeftFace(vertexstream, indexstream, size); this.WriteTopFace(vertexstream, indexstream, size); this.WriteBottomFace(vertexstream, indexstream, size); geom.VertexBuffer = DX11VertexBuffer.CreateImmutable(device, 24, Pos4Norm3Tex2Vertex.VertexSize, vertexstream); geom.IndexBuffer = DX11IndexBuffer.CreateImmutable(device, 36, indexstream, true); geom.InputLayout = Pos4Norm3Tex2Vertex.Layout; geom.VertexBuffer.InputLayout = geom.InputLayout; geom.Topology = PrimitiveTopology.TriangleList; geom.HasBoundingBox = true; geom.BoundingBox = new BoundingBox(-s3, s3); vertexstream.Dispose(); indexstream.Dispose(); return(geom); }
public DX11IndexedGeometry Box(BoxSettings settings) { DX11IndexedGeometry geom = new DX11IndexedGeometry(context); int vertexcount = 24; DataStream vertexstream = new DataStream(24 * Pos4Norm3Tex2Vertex.VertexSize, true, true); vertexstream.Position = 0; var indexstream = new DataStream(36 * 4, true, true); float sx = 0.5f * settings.Size.X; float sy = 0.5f * settings.Size.Y; float sz = 0.5f * settings.Size.Z; Vector3 s3 = new Vector3(sx, sy, sz); Vector4 size = new Vector4(sx, sy, sz,1.0f); this.WriteFrontFace(vertexstream, indexstream, size); this.WriteBackFace(vertexstream, indexstream, size); this.WriteRightFace(vertexstream, indexstream, size); this.WriteLeftFace(vertexstream, indexstream, size); this.WriteTopFace(vertexstream, indexstream, size); this.WriteBottomFace(vertexstream, indexstream, size); var vertices = BufferHelper.CreateVertexBuffer(context, vertexstream, true); geom.VertexBuffer = vertices; geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true); geom.InputLayout = Pos4Norm3Tex2Vertex.Layout; geom.Topology = PrimitiveTopology.TriangleList; geom.VerticesCount = vertexcount; geom.VertexSize = Pos4Norm3Tex2Vertex.VertexSize; geom.HasBoundingBox = true; geom.BoundingBox = new BoundingBox(-s3, s3); return geom; }
public void Dispose() { if (this.solidColorShader != null) { this.solidColorShader.Dispose(); this.solidColorShader = null; } if (this.dynamicLine != null) { this.dynamicLine.Dispose(); this.dynamicLine = null; } if (this.dynamicLineTriangle != null) { this.dynamicLineTriangle.Dispose(); this.dynamicLineTriangle = null; } if (this.boxSphereColorLayout != null) { this.boxSphereColorLayout.Dispose(); this.boxSphereColorLayout = null; } if (this.box != null) { this.box.Dispose(); this.box = null; } if (this.sphere != null) { this.sphere.Dispose(); this.sphere = null; } if (this.cylinder != null) { this.cylinder.Dispose(); this.cylinder = null; } }
public void Update(IPluginIO pin, DX11RenderContext context) { if (this.FInvalidate) { if (this.FOutput[0].Contains(context)) { this.FOutput[0].Dispose(context); } DX11IndexedGeometry geom = new DX11IndexedGeometry(context); geom.InputLayout = this.inputlayout; geom.VertexSize = this.vertexsize; var vertices = new SlimDX.Direct3D11.Buffer(context.Device, this.FVertexStream, new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = (int)this.FVertexStream.Length, Usage = ResourceUsage.Default }); geom.HasBoundingBox = false; geom.IndexBuffer = new DX11IndexBuffer(context, this.FIndexStream, false, false); geom.InputLayout = this.inputlayout; geom.Topology = this.FInTopology[0]; geom.VertexBuffer = vertices; geom.VertexSize = this.vertexsize; geom.VerticesCount = this.FInVerticesCount[0]; this.FOutput[0][context] = geom; this.FInvalidate = false; } }
public void Update(IPluginIO pin, DX11RenderContext context) { if (quadshader == null) { string basepath = "VVVV.DX11.Nodes.effects.quad.fx"; DX11Effect effect = DX11Effect.FromResource(Assembly.GetExecutingAssembly(), basepath); quadshader = new DX11ShaderInstance(context, effect); texturevariable = quadshader.Effect.GetVariableBySemantic("INPUTTEXTURE").AsResource(); samplervariable = quadshader.Effect.GetVariableBySemantic("SAMPLERSTATE").AsSampler(); Quad quad = new Quad(); quad.Size = new Vector2(1.0f); quadgeometry = context.Primitives.QuadNormals(quad); quadlayouts = new List <InputLayout>(); for (int i = 0; i < 4; i++) { InputLayout layout; quadshader.SelectTechnique(i); bool res = quadgeometry.ValidateLayout(quadshader.GetPass(0), out layout); quadlayouts.Add(layout); } } if (this.spmax > 0) { if (!this.FOutLayer[0].Contains(context)) { this.FOutLayer[0][context] = new DX11Layer(); this.FOutLayer[0][context].Render = this.Render; } } }
public override IDxGeometry Convolute(IDxGeometry input) { IDxGeometry result = input.ShallowCopy(); if (result is DX11IndexedGeometry) { DX11IndexedGeometry indexed = (DX11IndexedGeometry)result; DX11InstancedIndexedDrawer d = new DX11InstancedIndexedDrawer(); indexed.AssignDrawer(d); d.InstanceCount = this.InstanceCount; indexed.AssignDrawer(d); } if (result is DX11VertexGeometry) { DX11VertexGeometry vertex = (DX11VertexGeometry)result; DX11InstancedVertexDrawer d = new DX11InstancedVertexDrawer(); vertex.AssignDrawer(d); d.InstanceCount = this.InstanceCount; vertex.AssignDrawer(d); } return(result); }
private int GetVertexCount(IDxGeometry geometry) { if (this.UseMaxElements) { return(this.MaxElements); } if (geometry is DX11VertexGeometry) { DX11VertexGeometry vd = (DX11VertexGeometry)geometry; return(vd.VerticesCount); } if (geometry is DX11IndexedGeometry) { DX11IndexedGeometry id = (DX11IndexedGeometry)geometry; return(id.VertexBuffer.VerticesCount); } if (geometry is DX11NullGeometry) { return(this.MaxElements); } throw new NotSupportedException("Can't set Vertices count from provided geometry"); }
public DX11IndexedGeometry Segment(Segment settings) { SegmentBuilder builder = new SegmentBuilder(); ListGeometryAppender appender = new ListGeometryAppender(); PrimitiveInfo info = builder.GetPrimitiveInfo(settings); Vector3 max = new Vector3(float.MinValue, float.MinValue, float.MinValue); Vector3 min = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue); builder.Construct(settings, (v, n, u) => { appender.AppendVertex(v, n, u); min = Vector3.Min(min, v); max = Vector3.Max(max, v); }, appender.AppendIndex); DX11IndexedGeometry geom = new DX11IndexedGeometry(device); geom.Tag = settings; geom.PrimitiveType = settings.PrimitiveType; geom.VertexBuffer = DX11VertexBuffer.CreateImmutable(device, appender.Vertices.ToArray()); geom.IndexBuffer = DX11IndexBuffer.CreateImmutable(device, appender.Indices.ToArray()); geom.InputLayout = Pos4Norm3Tex2Vertex.Layout; geom.Topology = PrimitiveTopology.TriangleList; geom.HasBoundingBox = true; geom.BoundingBox = new BoundingBox(min, max); return(geom); }
public DX11IndexedGeometry Isocahedron(Vector3 size) { DX11IndexedGeometry geom = new DX11IndexedGeometry(context); geom.VerticesCount = 12; geom.InputLayout = Pos3Norm3Tex2Vertex.Layout; geom.VertexSize = Pos3Norm3Tex2Vertex.VertexSize; geom.Topology = PrimitiveTopology.TriangleList; float t = (1.0f + (float)Math.Sqrt(5.0f)) / 2.0f; DataStream ds = new DataStream(12 * Pos3Norm3Tex2Vertex.VertexSize, false, true); Pos3Norm3Tex2Vertex v = new Pos3Norm3Tex2Vertex(); v.Position = Vector3.Normalize(new Vector3(-1, t, 0))*0.5f; v.Normals = v.Position*2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v); v.Position = Vector3.Normalize(new Vector3(1, t, 0)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v); v.Position = Vector3.Normalize(new Vector3(-1, -t, 0)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v); v.Position = Vector3.Normalize(new Vector3(1, -t, 0)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v); v.Position = Vector3.Normalize(new Vector3(0, -1, t)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v); v.Position = Vector3.Normalize(new Vector3(0, 1, t)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v); v.Position = Vector3.Normalize(new Vector3(0, -1, -t)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v); v.Position = Vector3.Normalize(new Vector3(0, 1, -t)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v); v.Position = Vector3.Normalize(new Vector3(t, 0, -1)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v); v.Position = Vector3.Normalize(new Vector3(t, 0, 1)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v); v.Position = Vector3.Normalize(new Vector3(-t, 0, -1)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v); v.Position = Vector3.Normalize(new Vector3(-t, 0, 1)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v); geom.VertexBuffer = BufferHelper.CreateVertexBuffer(context, ds, true); var indexstream = new DataStream(60 * 4, true, true); int[] inds = new int[] { 0,11,5, 0,5,1, 0,1,7, 0,7,10, 0,10,11, 1,5,9, 5,11,4, 11,10,2, 10,7,6, 7,1,8, 3,9,4, 3,4,2, 3,2,6, 3,6,8, 3,8,9, 4,9,5, 2,4,11, 6,2,10, 8,6,7, 9,8,1 }; indexstream.WriteRange(inds); geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true); geom.HasBoundingBox = true; geom.BoundingBox = new BoundingBox(new Vector3(-1, -1, -1), new Vector3(1, 1, 1)); return geom; }
public void Update(IPluginIO pin, DX11RenderContext context) { if (this.FInvalidate || this.FEmpty) { for (int i = 0; i < this.scenes.Count; i++) { if (scenes[i] != null) { AssimpScene scene = scenes[i]; for (int j = 0; j < scene.MeshCount; j++) { AssimpMesh assimpmesh = scene.Meshes[j]; DataStream vS = assimpmesh.Vertices; vS.Position = 0; List<int> inds = assimpmesh.Indices; if (inds.Count > 0 && assimpmesh.VerticesCount > 0) { var vertices = new SlimDX.Direct3D11.Buffer(context.Device, vS, new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = (int)vS.Length, Usage = ResourceUsage.Default }); var indexstream = new DataStream(inds.Count * 4, true, true); indexstream.WriteRange(inds.ToArray()); indexstream.Position = 0; DX11IndexedGeometry geom = new DX11IndexedGeometry(context); geom.VertexBuffer = vertices; geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true); geom.InputLayout = assimpmesh.GetInputElements().ToArray(); geom.Topology = PrimitiveTopology.TriangleList; geom.VerticesCount = assimpmesh.VerticesCount; geom.VertexSize = assimpmesh.CalculateVertexSize(); geom.HasBoundingBox = true; geom.BoundingBox = assimpmesh.BoundingBox; this.FOutGeom[i][j][context] = geom; } } } } this.FEmpty = false; this.FInvalidate = false; } }
public void Update(DX11RenderContext context) { if (!this.FTextureOutput[0].Contains(context)) { this.FTextureOutput[0][context] = new DX11DynamicTexture2D(context, this.width, this.height, SlimDX.DXGI.Format.R8G8B8A8_UNorm); this.FPCOut[0][context] = new DX11DynamicStructuredBuffer <float>(context, 640 * 480 * 6); } if (this.FInvalidate) { fixed(int *f = &this.pic[0]) { IntPtr ptr = new IntPtr(f); this.FTextureOutput[0][context].WriteData(ptr, this.width * this.height * 4); } /*fixed (float* f = &this.piccloud[0]) * {* * IntPtr ptr = new IntPtr(f);*/ DX11DynamicStructuredBuffer <float> db = (DX11DynamicStructuredBuffer <float>) this.FPCOut[0][context]; db.WriteData(this.piccloud); //} this.FInvalidate = false; } if (this.FInVoxels[0]) { if (this.FOutVoxels[0].Contains(context)) { this.FOutVoxels[0].Dispose(context); } short[] data = new short[this.VoxelResolutionX * this.VoxelResolutionY * this.VoxelResolutionZ]; this.volume.ExportVolumeBlock(0, 0, 0, this.VoxelResolutionX, this.VoxelResolutionY, this.VoxelResolutionZ, 1, data); DX11DynamicStructuredBuffer <int> b = new DX11DynamicStructuredBuffer <int>(context, this.VoxelResolutionX * this.VoxelResolutionY * this.VoxelResolutionZ); int[] idata = new int[this.VoxelResolutionX * this.VoxelResolutionY * this.VoxelResolutionZ]; for (int i = 0; i < this.VoxelResolutionX * this.VoxelResolutionY * this.VoxelResolutionZ; i++) { idata[i] = data[i]; } b.WriteData(idata); this.FOutVoxels[0][context] = b; } if (this.FInExport[0]) { if (this.FGeomOut[0].Contains(context)) { this.FGeomOut[0].Dispose(context); } if (this.volume != null) { Mesh m = this.volume.CalculateMesh(this.FInGeomVoxelStep[0]); DX11IndexedGeometry geom = new DX11IndexedGeometry(context); ReadOnlyCollection <int> inds = m.GetTriangleIndexes(); DataStream ds = new DataStream(inds.Count * 4, true, true); ds.WriteRange <int>(inds.ToArray()); ds.Position = 0; DX11IndexBuffer ibo = new DX11IndexBuffer(context, ds, false, true); ReadOnlyCollection <Microsoft.Kinect.Fusion.Vector3> pos = m.GetVertices(); ReadOnlyCollection <Microsoft.Kinect.Fusion.Vector3> norm = m.GetNormals(); //ReadOnlyCollection<int> col = m.GetColors(); DataStream dsv = new DataStream(Pos3Norm3Vertex.VertexSize * pos.Count, true, true); SlimDX.Vector3 bmin = new SlimDX.Vector3(float.MaxValue, float.MaxValue, float.MaxValue); SlimDX.Vector3 bmax = new SlimDX.Vector3(float.MinValue, float.MinValue, float.MinValue); for (int i = 0; i < pos.Count; i++) { Microsoft.Kinect.Fusion.Vector3 p = pos[i]; Microsoft.Kinect.Fusion.Vector3 n = norm[i]; dsv.Write <Microsoft.Kinect.Fusion.Vector3>(p); dsv.Write <Microsoft.Kinect.Fusion.Vector3>(n); //dsv.Write<int>(col[i]); if (p.X < bmin.X) { bmin.X = p.X; } if (p.Y < bmin.Y) { bmin.Y = p.Y; } if (p.Z < bmin.Z) { bmin.Z = p.Z; } if (p.X > bmax.X) { bmax.X = p.X; } if (p.Y > bmax.Y) { bmax.Y = p.Y; } if (p.Z > bmax.Z) { bmax.Z = p.Z; } } geom.IndexBuffer = ibo; geom.HasBoundingBox = true; geom.InputLayout = Pos3Norm3Vertex.Layout; // FusionColoredVertex.Layout; geom.Topology = SlimDX.Direct3D11.PrimitiveTopology.TriangleList; geom.VertexSize = Pos3Norm3Vertex.VertexSize; // FusionColoredVertex.VertexSize; geom.VertexBuffer = BufferHelper.CreateVertexBuffer(context, dsv, false, true); geom.VerticesCount = pos.Count; geom.BoundingBox = new BoundingBox(bmin, bmax); this.FGeomOut[0][context] = geom; m.Dispose(); } } }
private DX11IndexedGeometry QuadTextured() { DX11IndexedGeometry geom = new DX11IndexedGeometry(this.context); DataStream ds = new DataStream(4 * Pos4Tex2Vertex.VertexSize, true, true); ds.Position = 0; float sx = 1.0f; float sy = 1.0f; Pos4Tex2Vertex v = new Pos4Tex2Vertex(); v.Position = new Vector4(-sx, sy, 0.0f, 1.0f); v.TexCoords = new Vector2(0, 0); ds.Write<Pos4Tex2Vertex>(v); v.Position = new Vector4(sx, sy, 0.0f, 1.0f); v.TexCoords = new Vector2(1, 0); ds.Write<Pos4Tex2Vertex>(v); v.Position = new Vector4(-sx, -sy, 0.0f, 1.0f); v.TexCoords = new Vector2(0, 1); ds.Write<Pos4Tex2Vertex>(v); v.Position = new Vector4(sx, -sy, 0.0f, 1.0f); v.TexCoords = new Vector2(1, 1); ds.Write<Pos4Tex2Vertex>(v); ds.Position = 0; var vertices = new SlimDX.Direct3D11.Buffer(context.Device, ds, new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = (int)ds.Length, Usage = ResourceUsage.Default }); ds.Dispose(); var indexstream = new DataStream(24, true, true); indexstream.WriteRange(new int[] { 0, 1, 3, 3, 2, 0 }); indexstream.Position = 0; geom.VertexBuffer = vertices; geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true); geom.InputLayout = Pos4Tex2Vertex.Layout; geom.Topology = PrimitiveTopology.TriangleList; geom.VerticesCount = 4; geom.VertexSize = Pos4Tex2Vertex.VertexSize; geom.HasBoundingBox = true; geom.BoundingBox = new BoundingBox(new Vector3(-sx, -sy, 0.0f), new Vector3(sx, sy, 0.0f)); return geom; }
public DX11IndexedGeometry RoundRect(Vector2 inner, float outer, int ires) { DX11IndexedGeometry geom = new DX11IndexedGeometry(context); List<Pos4Norm3Tex2Vertex> vl = new List<Pos4Norm3Tex2Vertex>(); List<int> il = new List<int>(); int idx = 0; float ucy = Convert.ToSingle(inner.Y + outer); float ucx = Convert.ToSingle(inner.X + outer); float mx = ucx * 2.0f; float my = ucy * 2.0f; //Need 1 quad for center idx = SetQuad(vl, il, 0.0f, 0.0f, inner.X, inner.Y, idx, mx, my); //Need 2 quads up/down idx = SetQuad(vl, il, 0.0f, ucy, inner.X, (float)outer, idx, mx, my); idx = SetQuad(vl, il, 0.0f, -ucy, inner.X, (float)outer, idx, mx, my); //Need 2 quads left/right idx = SetQuad(vl, il, -ucx, 0.0f, (float)outer, inner.Y, idx, mx, my); idx = SetQuad(vl, il, ucx, 0.0f, (float)outer, inner.Y, idx, mx, my); float radius = (float)outer * 2.0f; //Add the 4 corners idx = SetSegment(vl, il, inner.X, inner.Y, 0.0f, radius, ires, idx, mx, my); idx = SetSegment(vl, il, -inner.X, inner.Y, 0.25f, radius, ires, idx, mx, my); idx = SetSegment(vl, il, -inner.X, -inner.Y, 0.5f, radius, ires, idx, mx, my); idx = SetSegment(vl, il, inner.X, -inner.Y, 0.75f, radius, ires, idx, mx, my); DataStream ds = new DataStream(vl.Count * Pos4Norm3Tex2Vertex.VertexSize, true, true); ds.Position = 0; ds.WriteRange(vl.ToArray()); ds.Position = 0; var vbuffer = new SlimDX.Direct3D11.Buffer(context.Device, ds, new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = (int)ds.Length, Usage = ResourceUsage.Default }); ds.Dispose(); var indexstream = new DataStream(il.Count * 4, true, true); indexstream.WriteRange(il.ToArray()); indexstream.Position = 0; geom.VertexBuffer = vbuffer; geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true); geom.InputLayout = Pos4Norm3Tex2Vertex.Layout; geom.Topology = PrimitiveTopology.TriangleList; geom.VerticesCount = vl.Count; geom.VertexSize = Pos4Norm3Tex2Vertex.VertexSize; geom.HasBoundingBox = false; return geom; }
public void Update(IPluginIO pin, DX11RenderContext context) { for (int i = 0; i < this.FOutput.SliceCount; i++) { if (this.FOutput[i].Contains(context)) { this.FOutput[i].Dispose(context); } } if (this.FBodies.SliceCount > 0) { int cnt = this.FBodies.SliceCount; for (int i = 0; i < cnt; i++) { SoftBody body = this.FBodies[i]; SoftBodyCustomData sc = (SoftBodyCustomData)body.UserObject; AlignedFaceArray faces = body.Faces; if (FValid[i]) { if (body.Faces.Count > 0) { #region Build from Faces DX11IndexedGeometry geom = new DX11IndexedGeometry(context); geom.VerticesCount = faces.Count*3; if (sc.HasUV) { geom.InputLayout = Pos3Norm3Tex2Vertex.Layout; geom.VertexSize = Pos3Norm3Tex2Vertex.VertexSize; } else { geom.InputLayout = Pos3Norm3Vertex.Layout; geom.VertexSize = Pos3Norm3Vertex.VertexSize; } //Mesh mesh = new Mesh(OnDevice, faces.Count, faces.Count * 3, MeshFlags.SystemMemory | MeshFlags.Use32Bit, decl); SlimDX.DataStream verts = new SlimDX.DataStream(geom.VerticesCount * geom.VertexSize*3, false, true); SlimDX.DataStream indices = new SlimDX.DataStream(faces.Count * sizeof(int)*3, false, true); int j; int uvcnt = 0; for (j = 0; j < faces.Count; j++) { NodePtrArray nodes = faces[j].N; verts.Write(nodes[0].X); verts.Write(nodes[0].Normal); //verts.Position += 12; if (sc.HasUV) { verts.Write(sc.UV[uvcnt]); uvcnt++; verts.Write(sc.UV[uvcnt]); uvcnt++; } verts.Write(nodes[1].X); verts.Write(nodes[1].Normal); //verts.Position += 12; if (sc.HasUV) { verts.Write(sc.UV[uvcnt]); uvcnt++; verts.Write(sc.UV[uvcnt]); uvcnt++; } verts.Write(nodes[2].X); verts.Write(nodes[2].Normal); //verts.Position += 12; if (sc.HasUV) { verts.Write(sc.UV[uvcnt]); uvcnt++; verts.Write(sc.UV[uvcnt]); uvcnt++; } indices.Write(j * 3); indices.Write(j * 3 + 1); indices.Write(j * 3 + 2); } geom.VertexBuffer = BufferHelper.CreateVertexBuffer(context, verts, false, true); geom.HasBoundingBox = false; DX11IndexBuffer ibo = new DX11IndexBuffer(context, indices,false,true); geom.IndexBuffer = ibo; this.FOutput[i][context] = geom; #endregion } } } } }
public DX11IndexedGeometry Torus(Torus settings) { int resX = settings.ResolutionX; int resY = settings.ResolutionY; float radius = settings.Radius; float thick = settings.Thickness; float phasey = settings.PhaseY; float phasex = settings.PhaseX; float rot = settings.Rotation; float cy = settings.CY; List <Pos4Norm3Tex2Vertex> vertices = new List <Pos4Norm3Tex2Vertex>(); List <int> indices = new List <int>(); float pi = (float)Math.PI; float pidiv2 = pi * 0.5f; float twopi = pi * 2.0f; int stride = resY + 1; for (int i = 0; i <= resY; i++) { float u = (float)i / (float)resY; //u *= cy; float outerAngle = (float)i * twopi / (float)resY - pidiv2; Matrix transform = Matrix.Translation(radius, 0, 0) * Matrix.RotationY(outerAngle * rot); for (int j = 0; j <= resX; j++) { float fj = (float)j * cy; float v = 1 - (float)j / resX; float innerAngle = fj * twopi / (float)resX + pi; float dy = (float)Math.Sin(innerAngle) * phasey; float dx = (float)Math.Cos(innerAngle) * phasex; Pos4Norm3Tex2Vertex vertex = new Pos4Norm3Tex2Vertex(); Vector3 normal = new Vector3(dx, dy, 0); Vector3 position = normal * thick / 2; vertex.TexCoords = new Vector2(u, v); vertex.Normals = Vector3.TransformNormal(normal, transform); position = Vector3.TransformCoordinate(position, transform); vertex.Position = new Vector4(position.X, position.Y, position.Z, 1.0f); vertices.Add(vertex); int nextI = (i + 1) % stride; int nextJ = (j + 1) % stride; indices.Add(j * stride + i); indices.Add(nextJ * stride + i); indices.Add(j * stride + nextI); indices.Add(j * stride + nextI); indices.Add(nextJ * stride + i); indices.Add(nextJ * stride + nextI); } } DX11IndexedGeometry geom = DX11IndexedGeometry.CreateFrom <Pos4Norm3Tex2Vertex>(context, vertices.ToArray(), indices.ToArray(), Pos4Norm3Tex2Vertex.Layout); geom.Tag = settings; geom.PrimitiveType = settings.PrimitiveType; geom.HasBoundingBox = false; geom.BoundingBox = new BoundingBox(new Vector3(-radius), new Vector3(radius)); return(geom); }
public DX11IndexedGeometry Segment(float phase, float cycles, float inner, int res, bool flat) { DX11IndexedGeometry geom = new DX11IndexedGeometry(context); int vcount = res * 2; int icount = (res - 1) * 6; DataStream ds = new DataStream(vcount * Pos4Norm3Tex2Vertex.VertexSize, true, true); ds.Position = 0; float inc = Convert.ToSingle((Math.PI * 2.0 * cycles) / (res - 1.0)); float phi = Convert.ToSingle(phase * (Math.PI * 2.0)); Pos4Norm3Tex2Vertex innerv = new Pos4Norm3Tex2Vertex(); innerv.Normals = new Vector3(0.0f, 0.0f, 1.0f); Pos4Norm3Tex2Vertex outerv = new Pos4Norm3Tex2Vertex(); outerv.Normals = new Vector3(0.0f, 0.0f, 1.0f); Pos4Norm3Tex2Vertex[] vertices = new Pos4Norm3Tex2Vertex[res * 2]; for (int i = 0; i < res; i++) { float x = Convert.ToSingle(0.5 * inner * Math.Cos(phi)); float y = Convert.ToSingle(0.5 * inner * Math.Sin(phi)); innerv.Position = new Vector4(x, y, 0.0f, 1.0f); if (flat) { innerv.TexCoords = new Vector2(0.5f - x, 0.5f - y); } else { innerv.TexCoords = new Vector2((1.0f * (float)i) / ((float)res - 1.0f), 0.0f); } x = Convert.ToSingle(0.5 * Math.Cos(phi)); y = Convert.ToSingle(0.5 * Math.Sin(phi)); outerv.Position = new Vector4(x, y, 0.0f, 1.0f); if (flat) { outerv.TexCoords = new Vector2(0.5f - x, 0.5f - y); } else { outerv.TexCoords = new Vector2((1.0f * (float)i) / ((float)res - 1.0f), 1.0f); } vertices[i] = innerv; vertices[i + res] = outerv; phi += inc; } ds.WriteRange(vertices); ds.Position = 0; var vbuffer = new SlimDX.Direct3D11.Buffer(context.Device, ds, new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = (int)ds.Length, Usage = ResourceUsage.Default }); ds.Dispose(); int indstep = 0; int[] indices = new int[icount]; for (int i = 0; i < res - 1; i++) { //Triangle from low to high indices[indstep] = i; indices[indstep + 2] = res + i; indices[indstep + 1] = i + 1; //Triangle from high to low indices[indstep + 3] = i + 1; indices[indstep + 5] = res + i; indices[indstep + 4] = res + i + 1; indstep += 6; } var indexstream = new DataStream(icount * 4, true, true); indexstream.WriteRange(indices); indexstream.Position = 0; geom.VertexBuffer = vbuffer; geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true); geom.InputLayout = Pos4Norm3Tex2Vertex.Layout; geom.Topology = PrimitiveTopology.TriangleList; geom.VerticesCount = vcount; geom.VertexSize = Pos4Norm3Tex2Vertex.VertexSize; geom.HasBoundingBox = false; return geom; }
public DX11IndexedGeometry Cylinder(Cylinder settings) { float radius1 = settings.Radius1; float radius2 = settings.Radius2; float cycles = settings.Cycles; float length = settings.Length; int resX = settings.ResolutionX; int resY = settings.ResolutionY; bool caps = settings.Caps; DX11IndexedGeometry geom = new DX11IndexedGeometry(context); geom.Tag = settings; geom.PrimitiveType = settings.PrimitiveType; int vcount = resX * (resY + 1); int icount = vcount * 6; if (caps) { //Add vertices (+1 for center) vcount += (resX + 1 * 2); //Add Triangles (on each side icount += (resX * 6); } float lenstart = -length * 0.5f; //Start at half bottom float lenstep = (float)length / (float)resY; float y = lenstart; List<Pos4Norm3Tex2Vertex> verts = new List<Pos4Norm3Tex2Vertex>(); List<int> inds = new List<int>(); float phi = 0.0f; float inc = Convert.ToSingle((Math.PI * 2.0 * cycles) / (double)resX); float fres = Convert.ToSingle(resY); #region Add Vertices tube for (int i = 0; i < resY + 1; i++) { float ystep = (float)i / fres; float radius = Map(ystep, 0, 1, radius1, radius2); for (int j = 0; j < resX; j++) { float x = Convert.ToSingle(radius1 * Math.Cos(phi)) * radius; float z = Convert.ToSingle(radius1 * Math.Sin(phi)) * radius; Pos4Norm3Tex2Vertex v = new Pos4Norm3Tex2Vertex(); v.Position = new Vector4(x, y, z, 1.0f); v.Normals = new Vector3(x, 0.0f, z); v.Normals.Normalize(); verts.Add(v); phi += inc; } y += lenstep; phi = 0.0f; } #endregion #region Add Indices Tube int indstart; for (int i = 0; i < resY; i++) { indstart = resX * i; int j; for (j = 0; j < resX - 1; j++) { inds.Add(indstart + j); inds.Add(indstart + resX + j); inds.Add(indstart + j + 1); inds.Add(indstart + j + 1); inds.Add(indstart + j + resX); inds.Add(indstart + j + resX + 1); } inds.Add(indstart + j); inds.Add(indstart + resX + j); inds.Add(indstart); inds.Add(indstart + j + resX); inds.Add(indstart + resX); inds.Add(indstart); } if (caps) { indstart = verts.Count; y = -length * 0.5f; Pos4Norm3Tex2Vertex v = new Pos4Norm3Tex2Vertex(); v.Position = new Vector4(0, y, 0, 1.0f); v.Normals = new Vector3(0.0f, -1.0f, 0.0f); v.Normals.Normalize(); verts.Add(v); phi = 0.0f; for (int j = 0; j < resX; j++) { float x = Convert.ToSingle(radius1 * Math.Cos(phi)) * radius1; float z = Convert.ToSingle(radius1 * Math.Sin(phi)) * radius1; v.Position = new Vector4(x, y, z, 1.0f); verts.Add(v); phi += inc; } for (int j = 1; j < resX + 1; j++) { inds.Add(indstart); inds.Add(indstart + j); if (j == resX) { inds.Add(indstart + 1); } else { inds.Add(indstart + j + 1); } } indstart += (resX + 1); y = length * 0.5f; v = new Pos4Norm3Tex2Vertex(); v.Position = new Vector4(0, y, 0, 1.0f); v.Normals = new Vector3(0.0f, 1.0f, 0.0f); v.Normals.Normalize(); verts.Add(v); phi = 0.0f; for (int j = 0; j < resX; j++) { float x = Convert.ToSingle(radius1 * Math.Cos(phi)) * radius2; float z = Convert.ToSingle(radius1 * Math.Sin(phi)) * radius2; v.Position = new Vector4(x, y, z, 1.0f); verts.Add(v); phi += inc; } for (int j = 1; j < resX + 1; j++) { inds.Add(indstart + j); inds.Add(indstart); if (j == resX) { inds.Add(indstart + 1); } else { inds.Add(indstart + j + 1); } } } #endregion DataStream ds = new DataStream(verts.Count * Pos4Norm3Tex2Vertex.VertexSize, true, true); ds.Position = 0; ds.WriteRange(verts.ToArray()); ds.Position = 0; var vbuffer = new SlimDX.Direct3D11.Buffer(context.Device, ds, new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = (int)ds.Length, Usage = ResourceUsage.Default }); ds.Dispose(); var indexstream = new DataStream(inds.Count * 4, true, true); indexstream.WriteRange(inds.ToArray()); indexstream.Position = 0; geom.VertexBuffer = vbuffer; geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true); geom.InputLayout = Pos4Norm3Tex2Vertex.Layout; geom.Topology = PrimitiveTopology.TriangleList; geom.VerticesCount = vcount; geom.VertexSize = Pos4Norm3Tex2Vertex.VertexSize; //Since cylinder can be a cone, max box is max of radius float maxrad = radius1 > radius2 ? radius1 : radius2; geom.HasBoundingBox = true; geom.BoundingBox = new BoundingBox(new Vector3(-maxrad, -lenstart, -maxrad), new Vector3(maxrad, lenstart, maxrad)); return geom; }
public DX11IndexedGeometry Isocahedron(Isocahedron settings) { DX11IndexedGeometry geom = new DX11IndexedGeometry(context); geom.PrimitiveType = settings.PrimitiveType; geom.Tag = settings; geom.VerticesCount = 12; geom.InputLayout = Pos3Norm3Tex2Vertex.Layout; geom.VertexSize = Pos3Norm3Tex2Vertex.VertexSize; geom.Topology = PrimitiveTopology.TriangleList; // This is the golden ratio float t = (1.0f + (float)Math.Sqrt(5.0f)) / 2.0f; DataStream ds = new DataStream(12 * Pos3Norm3Tex2Vertex.VertexSize, false, true); Pos3Norm3Tex2Vertex v = new Pos3Norm3Tex2Vertex(); v.Position = Vector3.Normalize(new Vector3(-1, t, 0)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); v.Position *= settings.Radius; ds.Write <Pos3Norm3Tex2Vertex>(v); v.Position = Vector3.Normalize(new Vector3(1, t, 0)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); v.Position *= settings.Radius; ds.Write <Pos3Norm3Tex2Vertex>(v); v.Position = Vector3.Normalize(new Vector3(-1, -t, 0)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); v.Position *= settings.Radius; ds.Write <Pos3Norm3Tex2Vertex>(v); v.Position = Vector3.Normalize(new Vector3(1, -t, 0)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); v.Position *= settings.Radius; ds.Write <Pos3Norm3Tex2Vertex>(v); v.Position = Vector3.Normalize(new Vector3(0, -1, t)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); v.Position *= settings.Radius; ds.Write <Pos3Norm3Tex2Vertex>(v); v.Position = Vector3.Normalize(new Vector3(0, 1, t)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); v.Position *= settings.Radius; ds.Write <Pos3Norm3Tex2Vertex>(v); v.Position = Vector3.Normalize(new Vector3(0, -1, -t)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); v.Position *= settings.Radius; ds.Write <Pos3Norm3Tex2Vertex>(v); v.Position = Vector3.Normalize(new Vector3(0, 1, -t)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); v.Position *= settings.Radius; ds.Write <Pos3Norm3Tex2Vertex>(v); v.Position = Vector3.Normalize(new Vector3(t, 0, -1)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); v.Position *= settings.Radius; ds.Write <Pos3Norm3Tex2Vertex>(v); v.Position = Vector3.Normalize(new Vector3(t, 0, 1)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); v.Position *= settings.Radius; ds.Write <Pos3Norm3Tex2Vertex>(v); v.Position = Vector3.Normalize(new Vector3(-t, 0, -1)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); v.Position *= settings.Radius; ds.Write <Pos3Norm3Tex2Vertex>(v); v.Position = Vector3.Normalize(new Vector3(-t, 0, 1)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); v.Position *= settings.Radius; ds.Write <Pos3Norm3Tex2Vertex>(v); geom.VertexBuffer = BufferHelper.CreateVertexBuffer(context, ds, true); var indexstream = new DataStream(60 * 4, true, true); int[] inds = new int[] { 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11, 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8, 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9, 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1 }; indexstream.WriteRange(inds); geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true); geom.HasBoundingBox = true; geom.BoundingBox = new BoundingBox(new Vector3(-1, -1, -1), new Vector3(1, 1, 1)); return(geom); }
public void Update(IPluginIO pin, DX11RenderContext context) { if (this.FInvalidate || !this.FOutput[0].Data.ContainsKey(context)) { for (int i = 0; i < this.FOutput.SliceCount; i++) { if (this.FOutput[i].Contains(context)) { this.FOutput[i].Dispose(context); } } for (int i = 0; i < this.FOutput.SliceCount; i++) { Pos4Norm3Tex2Vertex[] vertices = this.FVertex[i]; int[] indices = this.FIndices[i]; DataStream ds = new DataStream(vertices.Length * Pos4Norm3Tex2Vertex.VertexSize, true, true); ds.Position = 0; ds.WriteRange(vertices); ds.Position = 0; var vbuffer = new SlimDX.Direct3D11.Buffer(context.Device, ds, new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = (int)ds.Length, Usage = ResourceUsage.Default }); ds.Dispose(); var indexstream = new DataStream(indices.Length * 4, true, true); indexstream.WriteRange(indices); indexstream.Position = 0; DX11IndexedGeometry geom = new DX11IndexedGeometry(context); geom.VertexBuffer = vbuffer; geom.IndexBuffer = new DX11IndexBuffer(context, indexstream,false, true); geom.InputLayout = Pos4Norm3Tex2Vertex.Layout; geom.Topology = PrimitiveTopology.TriangleList; geom.VerticesCount = vertices.Length ; geom.VertexSize = Pos4Norm3Tex2Vertex.VertexSize; geom.HasBoundingBox = false; this.FOutput[i][context] = geom; } } this.FInvalidate = false; }
public void Update(IPluginIO pin, DX11RenderContext context) { if (!this.FGeom[0].Contains(context)) { update = true; } if (update) { this.FGeom[0].Dispose(context); if (update) { try { DX11IndexedGeometry geom = new DX11IndexedGeometry(context); geom.VerticesCount = NumVertices; geom.VertexSize = Pos3Norm3Vertex.VertexSize; geom.InputLayout = Pos3Norm3Vertex.Layout; geom.Topology = SlimDX.Direct3D11.PrimitiveTopology.TriangleList; // lock buffers geom.VertexBuffer = BufferHelper.CreateDynamicVertexBuffer(context, Pos3Norm3Vertex.VertexSize * NumVertices); sVx = context.CurrentDeviceContext.MapSubresource(geom.VertexBuffer, SlimDX.Direct3D11.MapMode.WriteDiscard, SlimDX.Direct3D11.MapFlags.None).Data; //sIx = context.CurrentDeviceContext.MapSubresource(geom.IndexBuffer.Buffer, SlimDX.Direct3D11.MapMode.WriteDiscard, SlimDX.Direct3D11.MapFlags.DoNotWait).Data; // write buffers unsafe { fixed (sVxBuffer* FixTemp = &VxBuffer[0]) { IntPtr VxPointer = new IntPtr(FixTemp); sVx.WriteRange(VxPointer, sizeof(sVxBuffer) * NumVertices); } /*fixed (int* FixTemp = &IxBuffer[0]) { IntPtr IxPointer = new IntPtr(FixTemp); sIx.WriteRange(IxPointer, sizeof(int) * NumIndices); }*/ } context.CurrentDeviceContext.UnmapSubresource(geom.VertexBuffer, 0); unsafe { fixed (int* FixTemp = &IxBuffer[0]) { IntPtr IxPointer = new IntPtr(FixTemp); DataStream ds = new DataStream(IxPointer, sizeof(int) * NumIndices, true, true); geom.IndexBuffer = new DX11IndexBuffer(context, ds, true, false); } } this.FGeom[0][context] = geom; } finally { update = false; } } } }
public void Update(IPluginIO pin, DX11RenderContext context) { if (quadshader == null) { string basepath = "VVVV.DX11.Nodes.effects.quad.fx"; DX11Effect effect = DX11Effect.FromResource(Assembly.GetExecutingAssembly(), basepath); quadshader = new DX11ShaderInstance(context, effect); texturevariable = quadshader.Effect.GetVariableBySemantic("INPUTTEXTURE").AsResource(); samplervariable = quadshader.Effect.GetVariableBySemantic("SAMPLERSTATE").AsSampler(); Quad quad = new Quad(); quad.Size = new Vector2(1.0f); quadgeometry = context.Primitives.QuadNormals(quad); quadlayouts = new List<InputLayout>(); for (int i = 0; i < 4; i++) { InputLayout layout; quadshader.SelectTechnique(i); bool res = quadgeometry.ValidateLayout(quadshader.GetPass(0), out layout); quadlayouts.Add(layout); } } if (this.spmax > 0) { if (!this.FOutLayer[0].Contains(context)) { this.FOutLayer[0][context] = new DX11Layer(); this.FOutLayer[0][context].Render = this.Render; } } }
public void Update(IPluginIO pin, DX11RenderContext context) { if (this.CalculateSpreadMax() == 0) { return; } Device device = context.Device; DeviceContext ctx = context.CurrentDeviceContext; if (!this.deviceshaderdata.ContainsKey(context)) { this.deviceshaderdata.Add(context, new DX11ShaderData(context)); this.deviceshaderdata[context].SetEffect(this.FShader); } DX11ShaderData shaderdata = this.deviceshaderdata[context]; if (this.shaderupdated) { shaderdata.SetEffect(this.FShader); shaderdata.Update(this.FInTechnique[0].Index, 0, this.FIn); this.shaderupdated = false; } if (this.FInEnabled[0] && this.FIn.PluginIO.IsConnected) { //Clear shader stages (important here) shaderdata.ResetShaderStages(ctx); if (this.FIn.IsChanged || this.FInTechnique.IsChanged || shaderdata.LayoutValid.Count == 0) { shaderdata.Update(this.FInTechnique[0].Index, 0, this.FIn); } if (shaderdata.IsLayoutValid(0) && this.varmanager.SetGlobalSettings(shaderdata.ShaderInstance, this.settings)) { this.OnBeginQuery(context); this.settings = new DX11RenderSettings(); this.settings.RenderWidth = 1; this.settings.RenderHeight = 1; this.settings.View = this.FInView[0]; this.settings.Projection = this.FInProjection[0]; this.settings.ViewProjection = this.settings.View * this.settings.Projection; this.settings.RenderDepth = 1; this.settings.BackBuffer = null; if (this.FInSemantics.PluginIO.IsConnected) { this.settings.CustomSemantics.AddRange(this.FInSemantics.ToArray()); } if (this.FInResSemantics.PluginIO.IsConnected) { this.settings.ResourceSemantics.AddRange(this.FInResSemantics.ToArray()); } this.varmanager.ApplyGlobal(shaderdata.ShaderInstance); if (this.clone == null || this.FIn.IsChanged || this.FInAsAuto.IsChanged || this.FInMaxElements.IsChanged || this.FInLayout.IsChanged || this.FInAutoLayout.IsChanged) { if (this.buffer != null) { this.buffer.Dispose(); } bool customlayout = this.FInLayout.PluginIO.IsConnected || this.FInAutoLayout[0]; InputElement[] elems = null; int size = 0; if (this.FInAutoLayout[0]) { elems = this.FShader.DefaultEffect.GetTechniqueByIndex(tid).GetPassByIndex(0).GetStreamOutputLayout(out size); } else { if (customlayout) { elems = this.BindInputLayout(out size); } } #region Vertex Geom if (this.FIn[0][context] is DX11VertexGeometry) { if (!this.FInAsAuto[0]) { DX11VertexGeometry vg = (DX11VertexGeometry)this.FIn[0][context].ShallowCopy(); int vsize = customlayout ? size : vg.VertexSize; Buffer vbo = BufferHelper.CreateStreamOutBuffer(context, vsize, vg.VerticesCount); if (customlayout) { vg.VertexSize = vsize; } vg.VertexBuffer = vbo; this.clone = vg; this.buffer = vbo; } else { DX11VertexGeometry vg = (DX11VertexGeometry)this.FIn[0][context].ShallowCopy(); int maxv = vg.VerticesCount; if (this.FInMaxElements[0] > 0) { maxv = this.FInMaxElements[0]; } int vsize = customlayout ? size : vg.VertexSize; Buffer vbo = BufferHelper.CreateStreamOutBuffer(context, vsize, maxv); vg.VertexBuffer = vbo; vg.AssignDrawer(new DX11VertexAutoDrawer()); if (customlayout) { vg.VertexSize = vsize; } this.clone = vg; this.buffer = vbo; } } #endregion #region Inxexed geom if (this.FIn[0][context] is DX11IndexedGeometry) { if (!this.FInAsAuto[0]) { DX11IndexedGeometry ig = (DX11IndexedGeometry)this.FIn[0][context].ShallowCopy(); int vsize = customlayout ? size : ig.VertexSize; Buffer vbo = BufferHelper.CreateStreamOutBuffer(context, vsize, ig.VerticesCount); ig.VertexBuffer = vbo; if (customlayout) { ig.VertexSize = vsize; } this.clone = ig; this.buffer = vbo; } else { //Need to rebind indexed geom as vertex DX11IndexedGeometry ig = (DX11IndexedGeometry)this.FIn[0][context]; int maxv = ig.VerticesCount; if (this.FInMaxElements[0] > 0) { maxv = this.FInMaxElements[0]; } int vsize = customlayout ? size : ig.VertexSize; Buffer vbo = BufferHelper.CreateStreamOutBuffer(context, vsize, maxv); //Copy a new Vertex buffer with stream out DX11VertexGeometry vg = new DX11VertexGeometry(context); vg.AssignDrawer(new DX11VertexAutoDrawer()); vg.BoundingBox = ig.BoundingBox; vg.HasBoundingBox = ig.HasBoundingBox; vg.InputLayout = ig.InputLayout; vg.Topology = ig.Topology; vg.VertexBuffer = vbo; vg.VertexSize = ig.VertexSize; vg.VerticesCount = ig.VerticesCount; if (customlayout) { vg.VertexSize = vsize; } this.clone = vg; this.buffer = vbo; } } #endregion #region Null geom if (this.FIn[0][context] is DX11NullGeometry) { DX11NullGeometry ng = (DX11NullGeometry)this.FIn[0][context]; Buffer vbo = BufferHelper.CreateStreamOutBuffer(context, size, this.FInMaxElements[0]); //Copy a new Vertex buffer with stream out DX11VertexGeometry vg = new DX11VertexGeometry(context); vg.AssignDrawer(new DX11VertexAutoDrawer()); vg.BoundingBox = ng.BoundingBox; vg.HasBoundingBox = ng.HasBoundingBox; vg.InputLayout = ng.InputLayout; vg.Topology = ng.Topology; vg.VertexBuffer = vbo; vg.VertexSize = size; vg.VerticesCount = this.FInMaxElements[0]; this.clone = vg; this.buffer = vbo; } #endregion #region Index Only geom if (this.FIn[0][context] is DX11IndexOnlyGeometry) { DX11IndexOnlyGeometry ng = (DX11IndexOnlyGeometry)this.FIn[0][context]; Buffer vbo = BufferHelper.CreateStreamOutBuffer(context, size, this.FInMaxElements[0]); //Copy a new Vertex buffer with stream out DX11VertexGeometry vg = new DX11VertexGeometry(context); vg.AssignDrawer(new DX11VertexAutoDrawer()); vg.BoundingBox = ng.BoundingBox; vg.HasBoundingBox = ng.HasBoundingBox; vg.InputLayout = ng.InputLayout; vg.Topology = ng.Topology; vg.VertexBuffer = vbo; vg.VertexSize = size; vg.VerticesCount = this.FInMaxElements[0]; this.clone = vg; this.buffer = vbo; } #endregion if (customlayout) { this.clone.InputLayout = elems; } if (this.FOutBuffer[0][context] != null) { this.FOutBuffer[0][context].SRV.Dispose(); } if (context.ComputeShaderSupport) { this.FOutBuffer[0][context] = new DX11RawBuffer(context, this.buffer); } else { this.FOutBuffer[0][context] = null; } } ctx.StreamOutput.SetTargets(new StreamOutputBufferBinding(this.buffer, 0)); shaderdata.SetInputAssembler(ctx, this.FIn[0][context], 0); DX11ObjectRenderSettings ors = new DX11ObjectRenderSettings(); ors.DrawCallIndex = 0; ors.Geometry = this.FIn[0][context]; ors.WorldTransform = Matrix.Identity; this.varmanager.ApplyPerObject(context, shaderdata.ShaderInstance, ors, 0); shaderdata.ApplyPass(ctx); this.FIn[0][context].Draw(); ctx.StreamOutput.SetTargets(null); this.FOut[0][context] = this.clone; this.OnEndQuery(context); } else { this.FOut[0][context] = this.FIn[0][context]; } } else { this.FOut[0][context] = this.FIn[0][context]; } }
public void Update(IPluginIO pin, DX11RenderContext context) { if (this.FInvalidate) { if (this.FOutput[0].Contains(context)) { this.FOutput[0].Dispose(context); } DX11IndexedGeometry geom = new DX11IndexedGeometry(context); geom.InputLayout = this.inputlayout; geom.VertexSize = this.vertexsize; var vertices = new SlimDX.Direct3D11.Buffer(context.Device, this.FVertexStream, new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = (int)this.FVertexStream.Length, Usage = ResourceUsage.Default }); geom.HasBoundingBox = false; geom.IndexBuffer = new DX11IndexBuffer(context, this.FIndexStream, false, false); geom.InputLayout = this.inputlayout; var topo = this.FInTopology[0]; if (topo == PrimitiveTopology.Undefined) { topo = PrimitiveTopology.TriangleList; this.FHost.Log(TLogType.Warning, "Undefined topology is not valid for indexed geometry join, defaulting to TriangleList"); } geom.Topology = topo; geom.VertexBuffer = vertices; geom.VertexSize = this.vertexsize; geom.VerticesCount = this.FInVerticesCount[0]; this.FOutput[0][context] = geom; this.FInvalidate = false; } }
public void Update(IPluginIO pin, DX11RenderContext context) { if (this.FInvalidate || !this.FOutGeom[0].Contains(context)) { int vertexoffset = 0; List<Pos3Norm3Tex2InstanceVertex> vertices = new List<Pos3Norm3Tex2InstanceVertex>(); List<int> indices = new List<int>(); List<Vector2> uvs = new List<Vector2>(); int cnt = this.FinUseName[0] ? idsort.Count : this.FInScene[0].MeshCount; for (int i = 0; i < cnt; i++) { AssimpMesh assimpmesh = this.FinUseName[0] == false ? this.FInScene[0].Meshes[i] : this.FInScene[0].Meshes[idsort[i]]; List<int> inds = assimpmesh.Indices; if (inds.Count > 0 && assimpmesh.VerticesCount > 0) { var texcd = assimpmesh.GetInputElements().Where( ie => ie.SemanticName == "TEXCOORD").FirstOrDefault(); bool zuv = false; if (texcd != null) { zuv = texcd.Format == SlimDX.DXGI.Format.R32G32B32_Float; } for (int j = 0; j < inds.Count; j++) { indices.Add(inds[j] + vertexoffset); } DataStream posbuffer = new DataStream(assimpmesh.PositionPointer, assimpmesh.VerticesCount * 12, true, true); DataStream normbuffer = new DataStream(assimpmesh.NormalsPointer, assimpmesh.VerticesCount * 12, true, true); DataStream uvbuffer = null; List<DataStream> uvbuffers = new List<DataStream>(); List<int> uvcounters = new List<int>(); for (int uvc = 0; uvc < assimpmesh.UvChannelCount;uvc++ ) { uvbuffers.Add(new DataStream(assimpmesh.GetUvPointer(uvc), assimpmesh.VerticesCount * 12, true, true)); uvcounters.Add(this.GetUVChannelCount(assimpmesh, uvc)); } if (assimpmesh.UvChannelCount > 0) { uvbuffer = new DataStream(assimpmesh.GetUvPointer(0), assimpmesh.VerticesCount * 12, true, true); } Vector3* pos = (Vector3*)posbuffer.DataPointer.ToPointer(); Vector3 accum = Vector3.Zero; for (int j = 0; j < assimpmesh.VerticesCount; j++) { accum += pos[j]; } Vector3 center = accum / assimpmesh.VerticesCount; for (int j = 0; j < assimpmesh.VerticesCount; j++) { Pos3Norm3Tex2InstanceVertex vert = new Pos3Norm3Tex2InstanceVertex() { InstanceID = i, Normals = normbuffer.Read<Vector3>(), Position = posbuffer.Read<Vector3>(), Center = center, TexCoords = uvbuffer != null ? uvbuffer.Read<Vector2>() : Vector2.Zero }; vertices.Add(vert); for (int k = 0; k < assimpmesh.UvChannelCount; k++ ) { var b = uvbuffers[k]; uvs.Add(b.Read<Vector2>()); if (uvcounters[k] == 3) { b.Read<float>(); } } if (uvbuffer != null && zuv) { uvbuffer.Read<float>(); } } vertexoffset += assimpmesh.VerticesCount; } } DataStream vS = new DataStream(vertices.ToArray(), true, true); vS.Position = 0; DataStream iS = new DataStream(indices.ToArray(), true, true); iS.Position = 0; var vbuffer = new SlimDX.Direct3D11.Buffer(context.Device, vS, new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = (int)vS.Length, Usage = ResourceUsage.Default }); DX11IndexedGeometry geom = new DX11IndexedGeometry(context); geom.VertexBuffer = vbuffer; geom.IndexBuffer = new DX11IndexBuffer(context, iS, true, false); geom.InputLayout = Pos3Norm3Tex2InstanceVertex.Layout; geom.Topology = PrimitiveTopology.TriangleList; geom.VerticesCount = vertices.Count; geom.VertexSize = Pos3Norm3Tex2InstanceVertex.VertexSize; geom.HasBoundingBox = false; vS.Position = 0; DataStream uvS = new DataStream(uvs.ToArray(), true, true); uvS.Position = 0; this.FOutGeom[0][context] = geom; this.FOutBuffer[0][context] = new DX11ImmutableStructuredBuffer(context.Device, geom.VerticesCount, geom.VertexSize, vS); this.FOutIndices[0][context] = new DX11RawBuffer(context, geom.IndexBuffer.Buffer); this.FOutUVBuffer[0][context] = new DX11ImmutableStructuredBuffer(context.Device,uvs.Count,8,uvS); this.FInvalidate = false; } }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); RenderForm form = new RenderForm("Kinect Camera Joint sample"); RenderDevice device = new RenderDevice(SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport | DeviceCreationFlags.Debug); RenderContext context = new RenderContext(device); DX11SwapChain swapChain = DX11SwapChain.FromHandle(device, form.Handle); DX11DepthStencil depthStencil = new DX11DepthStencil(device, swapChain.Width, swapChain.Height, eDepthFormat.d24s8); //VertexShader vertexShader = ShaderCompiler.CompileFromFile<VertexShader>(device, "ColorJointView.fx", "VS"); SharpDX.D3DCompiler.ShaderSignature signature; VertexShader vertexShader = ShaderCompiler.CompileFromFile(device, "CameraJointView.fx", "VS_Color", out signature); PixelShader pixelShader = ShaderCompiler.CompileFromFile <PixelShader>(device, "CameraJointView.fx", "PS_Color"); VertexShader vertexShaderLine = ShaderCompiler.CompileFromFile <VertexShader>(device, "CameraJointView.fx", "VS"); PixelShader pixelShaderLine = ShaderCompiler.CompileFromFile <PixelShader>(device, "CameraJointView.fx", "PS_White"); JointTableIndexBuffer indexBuffer = new JointTableIndexBuffer(device, 6); DX11IndexedGeometry cube = device.Primitives.Box(new Box() { Size = new Vector3(0.05f) }); DX11InstancedIndexedDrawer drawer = new DX11InstancedIndexedDrawer(); cube.AssignDrawer(drawer); InputLayout layout; var bc = new ShaderBytecode(signature); cube.ValidateLayout(bc, out layout); KinectSensor sensor = KinectSensor.GetDefault(); sensor.Open(); Color4[] statusColor = new Color4[] { Color.Red, Color.Yellow, Color.Green }; cbCamera camera = new cbCamera(); camera.Projection = Matrix.PerspectiveFovLH(1.57f, 1.3f, 0.1f, 100.0f); camera.View = Matrix.Translation(0.0f, 0.0f, 2.0f); camera.Projection.Transpose(); camera.View.Transpose(); ConstantBuffer <cbCamera> cameraBuffer = new ConstantBuffer <cbCamera>(device); cameraBuffer.Update(context, ref camera); DX11StructuredBuffer colorTableBuffer = DX11StructuredBuffer.CreateImmutable <Color4>(device, statusColor); bool doQuit = false; bool doUpload = false; int bodyCount = 0; KinectBody[] bodyFrame = null; BodyCameraPositionBuffer positionBuffer = new BodyCameraPositionBuffer(device); BodyJointStatusBuffer statusBuffer = new BodyJointStatusBuffer(device); KinectSensorBodyFrameProvider provider = new KinectSensorBodyFrameProvider(sensor); provider.FrameReceived += (sender, args) => { bodyFrame = args.FrameData; doUpload = true; }; form.KeyDown += (sender, args) => { if (args.KeyCode == Keys.Escape) { doQuit = true; } }; context.Context.OutputMerger.DepthStencilState = device.DepthStencilStates.LessReadWrite; context.Context.Rasterizer.State = device.RasterizerStates.BackCullSolid; RenderLoop.Run(form, () => { if (doQuit) { form.Dispose(); return; } if (doUpload) { var tracked = bodyFrame.TrackedOnly(); bodyCount = tracked.Count(); positionBuffer.Copy(context, tracked); statusBuffer.Copy(context, tracked); drawer.InstanceCount = tracked.Count() * Microsoft.Kinect.Body.JointCount; } context.RenderTargetStack.Push(depthStencil, false, swapChain); context.Context.ClearRenderTargetView(swapChain.RenderView, SharpDX.Color.Black); depthStencil.Clear(context); /*Position buffer and cbuffers are the same data and in same slot, * so we bind them only once*/ context.Context.VertexShader.SetShaderResource(0, positionBuffer.ShaderView); context.Context.VertexShader.SetConstantBuffer(0, cameraBuffer.Buffer); //Draw lines context.Context.PixelShader.Set(pixelShaderLine); context.Context.VertexShader.Set(vertexShaderLine); //Attach index buffer, null topology since we fetch indexBuffer.AttachWithLayout(context); indexBuffer.Draw(context, bodyCount); //Draw cubes cube.Bind(context, layout); context.Context.VertexShader.Set(vertexShader); context.Context.PixelShader.Set(pixelShader); context.Context.VertexShader.SetShaderResource(1, statusBuffer.ShaderView); context.Context.VertexShader.SetShaderResource(2, colorTableBuffer.ShaderView); cube.Draw(context); context.RenderTargetStack.Pop(); swapChain.Present(0, SharpDX.DXGI.PresentFlags.None); }); swapChain.Dispose(); depthStencil.Dispose(); context.Dispose(); device.Dispose(); positionBuffer.Dispose(); statusBuffer.Dispose(); colorTableBuffer.Dispose(); cameraBuffer.Dispose(); provider.Dispose(); cube.Dispose(); layout.Dispose(); pixelShader.Dispose(); vertexShader.Dispose(); pixelShaderLine.Dispose(); vertexShaderLine.Dispose(); indexBuffer.Dispose(); sensor.Close(); }
public void Update(IPluginIO pin, DX11RenderContext context) { for (int i = 0; i < this.FOutput.SliceCount; i++) { bool update = this.FInvalidate; DX11IndexedGeometry geom; if (!this.FOutput[i].Contains(context)) { geom = new DX11IndexedGeometry(context); geom.InputLayout = Pos3Norm3Tex2Vertex.Layout; geom.VertexSize = Pos3Norm3Tex2Vertex.VertexSize; geom.HasBoundingBox = false; geom.Topology = PrimitiveTopology.TriangleList; var indexstream = new DataStream(KinectRuntime.FACE_INDICES.Length * 4, true, true); indexstream.WriteRange(KinectRuntime.FACE_INDICES); indexstream.Position = 0; geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true); geom.VerticesCount = this.FInFrame[i].GetProjected3DShape().Count; var vbuffer = new SlimDX.Direct3D11.Buffer(context.Device, new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.Write, OptionFlags = ResourceOptionFlags.None, SizeInBytes = geom.VerticesCount * geom.VertexSize, Usage = ResourceUsage.Dynamic }); geom.VertexBuffer = vbuffer; this.FOutput[i][context] = geom; update = true; } else { geom = this.FOutput[i][context]; } if (update) { DataStream ds = geom.LockVertexBuffer(); ds.Position = 0; EnumIndexableCollection<FeaturePoint, PointF> pp = this.FInFrame[i].GetProjected3DShape(); EnumIndexableCollection<FeaturePoint, Vector3DF> p = this.FInFrame[i].Get3DShape(); Vector3[] norms = new Vector3[p.Count]; int[] inds = KinectRuntime.FACE_INDICES; int tricount = inds.Length / 3; //Compute smoothed normals for (int j = 0; j < tricount; j++) { int i1 = inds[j * 3]; int i2 = inds[j * 3 + 1]; int i3 = inds[j * 3 + 2]; Vector3 v1 = p[i1].SlimVector(); Vector3 v2 = p[i2].SlimVector(); Vector3 v3 = p[i3].SlimVector(); Vector3 faceEdgeA = v2 - v1; Vector3 faceEdgeB = v1 - v3; Vector3 norm = Vector3.Cross(faceEdgeB, faceEdgeA); norms[i1] += norm; norms[i2] += norm; norms[i3] += norm; } for (int j = 0; j < geom.VerticesCount; j++) { Pos3Norm3Tex2Vertex vertex = new Pos3Norm3Tex2Vertex(); Vector3DF v = p[j]; vertex.Position = new Vector3(v.X, v.Y, v.Z); vertex.Normals = Vector3.Normalize(norms[j]); vertex.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(vertex); } geom.UnlockVertexBuffer(); } } }
public DX11IndexedGeometry IcoGrid(IcoGrid grid) { Vector2 size = grid.Size; int resX = grid.ResolutionX; int resY = grid.ResolutionY; float fdispx = -0.5f; float fdispy = (float)Math.Sqrt(0.75); List<Pos4Norm3Tex2Vertex> verts = new List<Pos4Norm3Tex2Vertex>(); Pos4Norm3Tex2Vertex v = new Pos4Norm3Tex2Vertex(); v.Normals = new Vector3(0, 0, -1); v.TexCoords = new Vector2(0, 0); float maxx = float.MinValue; float maxy = float.MinValue; bool bdisp = true; float y = 0.0f; for (int i = 0; i < resX; i++) { bdisp = !bdisp; int cnt = resY; for (int j = 0; j < cnt; j++) { if (bdisp) { v.Position = new Vector4((float)j - 0.5f, y, 0.0f, 1.0f); if (v.Position.X > maxx) { maxx = v.Position.X; } if (v.Position.Y > maxy) { maxy = v.Position.Y; } } else { v.Position = new Vector4((float)j, y, 0.0f, 1.0f); if (v.Position.X > maxx) { maxx = v.Position.X; } if (v.Position.Y > maxy) { maxy = v.Position.Y; } } verts.Add(v); } y += fdispy; } float invmx = 1.0f / maxx; float invmy = 1.0f / maxy; for (int i = 0; i < verts.Count; i++) { Pos4Norm3Tex2Vertex v2 = verts[i]; v2.Position.X *= invmx; v2.Position.X -= 0.5f; v2.Position.Y *= invmy; v2.Position.Y -= 0.5f; verts[i] = v2; } List<int> inds = new List<int>(); bool bflip = true; int nextrow = resY; int a = 1; for (int i = 0; i < resX - 1; i++) { bflip = !bflip; for (int j = 0; j < resY - 1; j++) { int linestart = i * resY; int lineup = (i + 1) * resY; if (!bflip) { inds.Add(lineup + j); inds.Add(linestart + j); inds.Add(lineup + j + 1); inds.Add(linestart + j); inds.Add(linestart + j + 1); inds.Add(lineup + j + 1); } else { inds.Add(linestart + j); inds.Add(linestart + j + 1); inds.Add(lineup + j); inds.Add(lineup + j); inds.Add(linestart + j + 1); inds.Add(lineup + j + 1); } } a += nextrow; } DX11IndexedGeometry geom = new DX11IndexedGeometry(context); geom.Tag = grid; geom.PrimitiveType = grid.PrimitiveType; DataStream vertexstream = new DataStream(verts.Count * Pos4Norm3Tex2Vertex.VertexSize, true, true); vertexstream.Position = 0; vertexstream.WriteRange(verts.ToArray()); vertexstream.Position = 0; var vertices = BufferHelper.CreateDynamicVertexBuffer(context, vertexstream, true); var indexstream = new DataStream(inds.Count * 4, true, true); indexstream.WriteRange(inds.ToArray()); indexstream.Position = 0; geom.VertexBuffer = vertices; geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true); geom.InputLayout = Pos4Norm3Tex2Vertex.Layout; geom.Topology = PrimitiveTopology.TriangleList; geom.VerticesCount = verts.Count; geom.VertexSize = Pos4Norm3Tex2Vertex.VertexSize; geom.HasBoundingBox = false; return geom; }
public DX11IndexedGeometry Grid(Vector2 size, int resX, int resY) { DX11IndexedGeometry geom = new DX11IndexedGeometry(context); DataStream ds = new DataStream(resX * resY * Pos4Norm3Tex2Vertex.VertexSize, true, true); ds.Position = 0; float sx = 0.5f * size.X; float sy = 0.5f * size.Y; float ix = (sx / Convert.ToSingle(resX - 1)) * 2.0f; float iy = (sy / Convert.ToSingle(resY - 1)) * 2.0f; float y = -sy; Pos4Norm3Tex2Vertex v = new Pos4Norm3Tex2Vertex(); v.Normals = new Vector3(0, 0, -1.0f); for (int i = 0; i < resY; i++) { float x = -sx; for (int j = 0; j < resX; j++) { v.Position = new Vector4(x, y, 0.0f, 1.0f); v.TexCoords.X = Convert.ToSingle(Map((float)j, 0.0f, resX - 1, 0.0f, 1.0f)); v.TexCoords.Y = Convert.ToSingle(Map((float)i, 0.0f, resY - 1, 1.0f, 0.0f)); x += ix; ds.Write<Pos4Norm3Tex2Vertex>(v); } y += iy; } ds.Position = 0; var vertices = new SlimDX.Direct3D11.Buffer(context.Device, ds, new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = (int)ds.Length, Usage = ResourceUsage.Default }); ds.Dispose(); List<int> indlist = new List<int>(); for (int j = 0; j < resY - 1; j++) { int rowlow = (j * resX); int rowup = ((j + 1) * resX); for (int i = 0; i < resX - 1; i++) { int col = i * (resX - 1); indlist.Add(0 + rowlow + i); indlist.Add(0 + rowup + i); indlist.Add(1 + rowlow + i); indlist.Add(1 + rowlow + i); indlist.Add(0 + rowup + i); indlist.Add(1 + rowup + i); } } var indexstream = new DataStream(indlist.Count * 4, true, true); indexstream.WriteRange(indlist.ToArray()); indexstream.Position = 0; geom.VertexBuffer = vertices; geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true); geom.InputLayout = Pos4Norm3Tex2Vertex.Layout; geom.Topology = PrimitiveTopology.TriangleList; geom.VerticesCount = resX * resY; geom.VertexSize = Pos4Norm3Tex2Vertex.VertexSize; geom.HasBoundingBox = true; geom.BoundingBox = new BoundingBox(new Vector3(-sx, -sy, 0.0f), new Vector3(sx, sy, 0.0f)); return geom; }
public void Update(IPluginIO pin, DX11RenderContext context) { if (!this.FTextureOutput[0].Contains(context)) { this.FTextureOutput[0][context] = new DX11DynamicTexture2D(context, this.width, this.height, SlimDX.DXGI.Format.R8G8B8A8_UNorm); this.FPCOut[0][context] = new DX11DynamicStructuredBuffer<float>(context, 640 * 480 * 6); } if (this.FInvalidate) { fixed (int* f = &this.pic[0]) { IntPtr ptr = new IntPtr(f); this.FTextureOutput[0][context].WriteData(ptr, this.width * this.height * 4); } /*fixed (float* f = &this.piccloud[0]) {* IntPtr ptr = new IntPtr(f);*/ DX11DynamicStructuredBuffer<float> db = (DX11DynamicStructuredBuffer<float>)this.FPCOut[0][context]; db.WriteData(this.piccloud); //} this.FInvalidate = false; } if (this.FInVoxels[0]) { if (this.FOutVoxels[0].Contains(context)) { this.FOutVoxels[0].Dispose(context); } short[] data = new short[this.VoxelResolutionX * this.VoxelResolutionY * this.VoxelResolutionZ]; this.colorVolume.ExportVolumeBlock(0, 0, 0, this.VoxelResolutionX, this.VoxelResolutionY, this.VoxelResolutionZ, 1, data); DX11DynamicStructuredBuffer<int> b = new DX11DynamicStructuredBuffer<int>(context, this.VoxelResolutionX * this.VoxelResolutionY * this.VoxelResolutionZ); int[] idata = new int[this.VoxelResolutionX * this.VoxelResolutionY * this.VoxelResolutionZ]; for (int i = 0; i < this.VoxelResolutionX * this.VoxelResolutionY * this.VoxelResolutionZ; i++) { idata[i] = data[i]; } b.WriteData(idata); this.FOutVoxels[0][context] = b; } if (this.FInExport[0]) { if (this.FGeomOut[0].Contains(context)) { this.FGeomOut[0].Dispose(context); } if (this.colorVolume != null) { ColorMesh m = this.colorVolume.CalculateMesh(this.FInGeomVoxelStep[0]); DX11IndexedGeometry geom = new DX11IndexedGeometry(context); ReadOnlyCollection<int> inds = m.GetTriangleIndexes(); DataStream ds = new DataStream(inds.Count*4,true,true); ds.WriteRange<int>(inds.ToArray()); ds.Position = 0; DX11IndexBuffer ibo = new DX11IndexBuffer(context, ds, false, true); ReadOnlyCollection<Microsoft.Kinect.Toolkit.Fusion.Vector3> pos = m.GetVertices(); ReadOnlyCollection<Microsoft.Kinect.Toolkit.Fusion.Vector3> norm = m.GetNormals(); ReadOnlyCollection<int> col = m.GetColors(); DataStream dsv = new DataStream(Pos3Norm3Vertex.VertexSize * pos.Count,true,true); SlimDX.Vector3 bmin = new SlimDX.Vector3(float.MaxValue, float.MaxValue, float.MaxValue); SlimDX.Vector3 bmax = new SlimDX.Vector3(float.MinValue, float.MinValue, float.MinValue); for (int i = 0; i < pos.Count; i++) { Microsoft.Kinect.Toolkit.Fusion.Vector3 p = pos[i]; Microsoft.Kinect.Toolkit.Fusion.Vector3 n = norm[i]; dsv.Write<Microsoft.Kinect.Toolkit.Fusion.Vector3>(p); dsv.Write<Microsoft.Kinect.Toolkit.Fusion.Vector3>(n); dsv.Write<int>(col[i]); if (p.X < bmin.X) { bmin.X = p.X; } if (p.Y < bmin.Y) { bmin.Y = p.Y; } if (p.Z < bmin.Z) { bmin.Z = p.Z; } if (p.X > bmax.X) { bmax.X = p.X; } if (p.Y > bmax.Y) { bmax.Y = p.Y; } if (p.Z > bmax.Z) { bmax.Z = p.Z; } } geom.IndexBuffer = ibo; geom.HasBoundingBox = true; geom.InputLayout = FusionColoredVertex.Layout; geom.Topology = SlimDX.Direct3D11.PrimitiveTopology.TriangleList; geom.VertexSize = FusionColoredVertex.VertexSize; geom.VertexBuffer = BufferHelper.CreateVertexBuffer(context, dsv, false, true); geom.VerticesCount = pos.Count; geom.BoundingBox = new BoundingBox(bmin, bmax); this.FGeomOut[0][context] = geom; m.Dispose(); } } }
public void Update(IPluginIO pin, DX11RenderContext context) { if (this.FInvalidate || !this.FOutGeom[0].Contains(context)) { int vertexoffset = 0; List <Pos3Norm3Tex2InstanceVertex> vertices = new List <Pos3Norm3Tex2InstanceVertex>(); List <int> indices = new List <int>(); List <Vector2> uvs = new List <Vector2>(); int cnt = this.FinUseName[0] ? idsort.Count : this.FInScene[0].MeshCount; for (int i = 0; i < cnt; i++) { AssimpMesh assimpmesh = this.FinUseName[0] == false ? this.FInScene[0].Meshes[i] : this.FInScene[0].Meshes[idsort[i]]; List <int> inds = assimpmesh.Indices; if (inds.Count > 0 && assimpmesh.VerticesCount > 0) { var texcd = assimpmesh.GetInputElements().Where(ie => ie.SemanticName == "TEXCOORD").FirstOrDefault(); bool zuv = false; if (texcd != null) { zuv = texcd.Format == SlimDX.DXGI.Format.R32G32B32_Float; } for (int j = 0; j < inds.Count; j++) { indices.Add(inds[j] + vertexoffset); } DataStream posbuffer = new DataStream(assimpmesh.PositionPointer, assimpmesh.VerticesCount * 12, true, true); DataStream normbuffer = new DataStream(assimpmesh.NormalsPointer, assimpmesh.VerticesCount * 12, true, true); DataStream uvbuffer = null; List <DataStream> uvbuffers = new List <DataStream>(); List <int> uvcounters = new List <int>(); for (int uvc = 0; uvc < assimpmesh.UvChannelCount; uvc++) { uvbuffers.Add(new DataStream(assimpmesh.GetUvPointer(uvc), assimpmesh.VerticesCount * 12, true, true)); uvcounters.Add(this.GetUVChannelCount(assimpmesh, uvc)); } if (assimpmesh.UvChannelCount > 0) { uvbuffer = new DataStream(assimpmesh.GetUvPointer(0), assimpmesh.VerticesCount * 12, true, true); } Vector3 *pos = (Vector3 *)posbuffer.DataPointer.ToPointer(); Vector3 accum = Vector3.Zero; for (int j = 0; j < assimpmesh.VerticesCount; j++) { accum += pos[j]; } Vector3 center = accum / assimpmesh.VerticesCount; for (int j = 0; j < assimpmesh.VerticesCount; j++) { Pos3Norm3Tex2InstanceVertex vert = new Pos3Norm3Tex2InstanceVertex() { InstanceID = i, Normals = normbuffer.Read <Vector3>(), Position = posbuffer.Read <Vector3>(), Center = center, TexCoords = uvbuffer != null?uvbuffer.Read <Vector2>() : Vector2.Zero }; vertices.Add(vert); for (int k = 0; k < assimpmesh.UvChannelCount; k++) { var b = uvbuffers[k]; uvs.Add(b.Read <Vector2>()); if (uvcounters[k] == 3) { b.Read <float>(); } } if (uvbuffer != null && zuv) { uvbuffer.Read <float>(); } } vertexoffset += assimpmesh.VerticesCount; } } DataStream vS = new DataStream(vertices.ToArray(), true, true); vS.Position = 0; DataStream iS = new DataStream(indices.ToArray(), true, true); iS.Position = 0; var vbuffer = new SlimDX.Direct3D11.Buffer(context.Device, vS, new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = (int)vS.Length, Usage = ResourceUsage.Default }); DX11IndexedGeometry geom = new DX11IndexedGeometry(context); geom.VertexBuffer = vbuffer; geom.IndexBuffer = new DX11IndexBuffer(context, iS, true, false); geom.InputLayout = Pos3Norm3Tex2InstanceVertex.Layout; geom.Topology = PrimitiveTopology.TriangleList; geom.VerticesCount = vertices.Count; geom.VertexSize = Pos3Norm3Tex2InstanceVertex.VertexSize; geom.HasBoundingBox = false; vS.Position = 0; DataStream uvS = new DataStream(uvs.ToArray(), true, true); uvS.Position = 0; this.FOutGeom[0][context] = geom; this.FOutBuffer[0][context] = new DX11ImmutableStructuredBuffer(context.Device, geom.VerticesCount, geom.VertexSize, vS); this.FOutIndices[0][context] = new DX11RawBuffer(context, geom.IndexBuffer.Buffer); this.FOutUVBuffer[0][context] = new DX11ImmutableStructuredBuffer(context.Device, uvs.Count, 8, uvS); this.FInvalidate = false; } }
public DX11IndexedGeometry Segment(Segment settings) { float phase = settings.Phase; float cycles = settings.Cycles; float inner = settings.InnerRadius; int res = settings.Resolution; bool flat = settings.Flat; DX11IndexedGeometry geom = new DX11IndexedGeometry(context); geom.Tag = settings; geom.PrimitiveType = settings.PrimitiveType; int vcount = res * 2; int icount = (res - 1) * 6; DataStream ds = new DataStream(vcount * Pos4Norm3Tex2Vertex.VertexSize, true, true); ds.Position = 0; float inc = Convert.ToSingle((Math.PI * 2.0 * cycles) / (res - 1.0)); float phi = Convert.ToSingle(phase * (Math.PI * 2.0)); Pos4Norm3Tex2Vertex innerv = new Pos4Norm3Tex2Vertex(); innerv.Normals = new Vector3(0.0f, 0.0f, 1.0f); Pos4Norm3Tex2Vertex outerv = new Pos4Norm3Tex2Vertex(); outerv.Normals = new Vector3(0.0f, 0.0f, 1.0f); Pos4Norm3Tex2Vertex[] vertices = new Pos4Norm3Tex2Vertex[res * 2]; for (int i = 0; i < res; i++) { float x = Convert.ToSingle(0.5 * inner * Math.Cos(phi)); float y = Convert.ToSingle(0.5 * inner * Math.Sin(phi)); innerv.Position = new Vector4(x, y, 0.0f, 1.0f); if (flat) { innerv.TexCoords = new Vector2(0.5f - x, 0.5f - y); } else { innerv.TexCoords = new Vector2((1.0f * (float)i) / ((float)res - 1.0f), 0.0f); } x = Convert.ToSingle(0.5 * Math.Cos(phi)); y = Convert.ToSingle(0.5 * Math.Sin(phi)); outerv.Position = new Vector4(x, y, 0.0f, 1.0f); if (flat) { outerv.TexCoords = new Vector2(0.5f - x, 0.5f - y); } else { outerv.TexCoords = new Vector2((1.0f * (float)i) / ((float)res - 1.0f), 1.0f); } vertices[i] = innerv; vertices[i + res] = outerv; phi += inc; } float minx = float.MaxValue, miny = float.MaxValue, minz = float.MaxValue; float maxx = float.MinValue, maxy = float.MinValue, maxz = float.MinValue; foreach (Pos4Norm3Tex2Vertex v in vertices) { minx = v.Position.X < minx ? v.Position.X : minx; miny = v.Position.Y < miny ? v.Position.Y : miny; minz = v.Position.Z < minz ? v.Position.Z : minz; maxx = v.Position.X > maxx ? v.Position.X : maxx; maxy = v.Position.Y > maxy ? v.Position.Y : maxy; maxz = v.Position.Z > maxz ? v.Position.Z : maxz; } ds.WriteRange(vertices); ds.Position = 0; var vbuffer = new SlimDX.Direct3D11.Buffer(context.Device, ds, new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = (int)ds.Length, Usage = ResourceUsage.Default }); ds.Dispose(); int indstep = 0; int[] indices = new int[icount]; for (int i = 0; i < res - 1; i++) { //Triangle from low to high indices[indstep] = i; indices[indstep + 2] = res + i; indices[indstep + 1] = i + 1; //Triangle from high to low indices[indstep + 3] = i + 1; indices[indstep + 5] = res + i; indices[indstep + 4] = res + i + 1; indstep += 6; } var indexstream = new DataStream(icount * 4, true, true); indexstream.WriteRange(indices); indexstream.Position = 0; geom.VertexBuffer = vbuffer; geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true); geom.InputLayout = Pos4Norm3Tex2Vertex.Layout; geom.Topology = PrimitiveTopology.TriangleList; geom.VerticesCount = vcount; geom.VertexSize = Pos4Norm3Tex2Vertex.VertexSize; geom.BoundingBox = new BoundingBox(new Vector3(minx, miny, minz), new Vector3(maxx, maxy, maxz)); geom.HasBoundingBox = true; return geom; }
public QuadShaderDeviceData(DX11RenderContext context) { string basepath = "VVVV.DX11.Nodes.effects.quad.fx"; DX11Effect effect = DX11Effect.FromResource(Assembly.GetExecutingAssembly(), basepath); quadshader = new DX11ShaderInstance(context, effect); texturevariable = quadshader.Effect.GetVariableBySemantic("INPUTTEXTURE").AsResource(); samplervariable = quadshader.Effect.GetVariableBySemantic("SAMPLERSTATE").AsSampler(); Quad quad = new Quad(); quad.Size = new Vector2(1.0f); quadgeometry = context.Primitives.QuadNormals(quad); quadlayouts = new List<InputLayout>(); for (int i = 0; i < 4; i++) { InputLayout layout; quadshader.SelectTechnique(i); bool res = quadgeometry.ValidateLayout(quadshader.GetPass(0), out layout); quadlayouts.Add(layout); } }
public DX11IndexedGeometry SegmentZ(SegmentZ settings) { int res = settings.Resolution; float cycles = settings.Cycles; float phase = settings.Phase; float inner = settings.InnerRadius; float z = settings.Z; DX11IndexedGeometry geom = new DX11IndexedGeometry(context); geom.Tag = settings; geom.PrimitiveType = settings.PrimitiveType; int vcount = res * 2; int icount = (res - 1) * 6; float inc = Convert.ToSingle((Math.PI * 2.0 * cycles) / (res - 1.0)); float phi = Convert.ToSingle(phase * (Math.PI * 2.0)); List<Pos4Norm3Tex2Vertex> vlist = new List<Pos4Norm3Tex2Vertex>(); List<int> ilist = new List<int>(); Pos4Norm3Tex2Vertex innerv = new Pos4Norm3Tex2Vertex(); innerv.Normals = new Vector3(0.0f, 0.0f, 1.0f); Pos4Norm3Tex2Vertex outerv = new Pos4Norm3Tex2Vertex(); outerv.Normals = new Vector3(0.0f, 0.0f, 1.0f); Pos4Norm3Tex2Vertex[] vertices = new Pos4Norm3Tex2Vertex[res * 2]; #region Append front face for (int i = 0; i < res; i++) { float x = Convert.ToSingle(0.5 * inner * Math.Cos(phi)); float y = Convert.ToSingle(0.5 * inner * Math.Sin(phi)); innerv.Position = new Vector4(x, y, z, 1.0f); x = Convert.ToSingle(0.5 * Math.Cos(phi)); y = Convert.ToSingle(0.5 * Math.Sin(phi)); outerv.Position = new Vector4(x, y, z, 1.0f); vertices[i] = innerv; vertices[i + res] = outerv; phi += inc; } int indstep = 0; int[] indices = new int[icount]; for (int i = 0; i < res - 1; i++) { //Triangle from low to high indices[indstep] = i; indices[indstep + 1] = res + i; indices[indstep + 2] = i + 1; //Triangle from high to low indices[indstep + 3] = i + 1; indices[indstep + 4] = res + i; indices[indstep + 5] = res + i + 1; indstep += 6; } vlist.AddRange(vertices); ilist.AddRange(indices); #endregion #region Append Back Face //Second layer just has Z inverted for (int i = 0; i < res * 2; i++) { vertices[i].Position.Z = -vertices[i].Position.Z; vertices[i].Normals.Z = -vertices[i].Normals.Z; phi += inc; } //Here we also flip triangles for cull indstep = 0; int offset = res * 2; for (int i = offset; i < offset + res - 1; i++) { //Triangle from low to high indices[indstep] = i; indices[indstep + 2] = res + i; indices[indstep + 1] = i + 1; //Triangle from high to low indices[indstep + 3] = i + 1; indices[indstep + 5] = res + i; indices[indstep + 4] = res + i + 1; indstep += 6; } vlist.AddRange(vertices); ilist.AddRange(indices); #endregion //We need to append new set of indices, as we want nice normals #region Append Outer phi = Convert.ToSingle(phase * (Math.PI * 2.0)); for (int i = 0; i < res; i++) { float x = Convert.ToSingle(0.5 * Math.Cos(phi)); float y = Convert.ToSingle(0.5 * Math.Sin(phi)); innerv.Position = new Vector4(x, y, z, 1.0f); outerv.Position = new Vector4(x, y, -z, 1.0f); innerv.Normals = Vector3.Normalize(new Vector3(innerv.Position.X, innerv.Position.Y, 0.0f)); outerv.Normals = Vector3.Normalize(new Vector3(innerv.Position.X, innerv.Position.Y, 0.0f)); vertices[i] = innerv; vertices[i + res] = outerv; phi += inc; } indstep = 0; offset += (res * 2); for (int i = offset; i < offset + res - 1; i++) { //Triangle from low to high indices[indstep] = i; indices[indstep + 1] = res + i; indices[indstep + 2] = i + 1; //Triangle from high to low indices[indstep + 3] = i + 1; indices[indstep + 4] = res + i; indices[indstep + 5] = res + i + 1; indstep += 6; } vlist.AddRange(vertices); ilist.AddRange(indices); #endregion #region Append Inner phi = Convert.ToSingle(phase * (Math.PI * 2.0)); for (int i = 0; i < res; i++) { float x = Convert.ToSingle(0.5 * inner * Math.Cos(phi)); float y = Convert.ToSingle(0.5 * inner * Math.Sin(phi)); innerv.Position = new Vector4(x, y, z, 1.0f); outerv.Position = new Vector4(x, y, -z, 1.0f); innerv.Normals = -Vector3.Normalize(new Vector3(innerv.Position.X, innerv.Position.Y, 0.0f)); outerv.Normals = -Vector3.Normalize(new Vector3(innerv.Position.X, innerv.Position.Y, 0.0f)); vertices[i] = innerv; vertices[i + res] = outerv; phi += inc; } indstep = 0; offset += (res * 2); for (int i = offset; i < offset + res - 1; i++) { //Triangle from low to high indices[indstep] = i; indices[indstep + 2] = res + i; indices[indstep + 1] = i + 1; //Triangle from high to low indices[indstep + 3] = i + 1; indices[indstep + 5] = res + i; indices[indstep + 4] = res + i + 1; indstep += 6; } vlist.AddRange(vertices); ilist.AddRange(indices); #endregion #region Append Border //Append border low (quad) phi = Convert.ToSingle(phase * (Math.PI * 2.0)); float x2 = Convert.ToSingle(0.5 * inner * Math.Cos(phi)); float y2 = Convert.ToSingle(0.5 * inner * Math.Sin(phi)); float x3 = Convert.ToSingle(0.5 * Math.Cos(phi)); float y3 = Convert.ToSingle(0.5 * Math.Sin(phi)); Pos4Norm3Tex2Vertex q1 = new Pos4Norm3Tex2Vertex(); Pos4Norm3Tex2Vertex q2 = new Pos4Norm3Tex2Vertex(); Pos4Norm3Tex2Vertex q3 = new Pos4Norm3Tex2Vertex(); Pos4Norm3Tex2Vertex q4 = new Pos4Norm3Tex2Vertex(); q1.Position = new Vector4(x2, y2, z, 1.0f); q2.Position = new Vector4(x2, y2, -z, 1.0f); q3.Position = new Vector4(x3, y3, z, 1.0f); q4.Position = new Vector4(x3, y3, -z, 1.0f); Vector3 e1 = new Vector3(q2.Position.X - q1.Position.X, q2.Position.Y - q1.Position.Y, q2.Position.Z - q1.Position.Z); Vector3 e2 = new Vector3(q3.Position.X - q2.Position.X, q3.Position.Y - q2.Position.Y, q3.Position.Z - q2.Position.Z); Vector3 n = Vector3.Cross(e1, e2); q1.Normals = n; q2.Normals = n; q3.Normals = n; q4.Normals = n; vlist.Add(q1); vlist.Add(q2); vlist.Add(q3); vlist.Add(q4); offset += (res * 2); ilist.Add(offset); ilist.Add(offset + 1); ilist.Add(offset + 2); ilist.Add(offset + 2); ilist.Add(offset + 1); ilist.Add(offset + 3); offset += 4; //Totally crapply unoptimized, but phi can be negative phi = Convert.ToSingle(phase * (Math.PI * 2.0)); for (int i = 0; i < res - 1; i++) { phi += inc; } x2 = Convert.ToSingle(0.5 * inner * Math.Cos(phi)); y2 = Convert.ToSingle(0.5 * inner * Math.Sin(phi)); x3 = Convert.ToSingle(0.5 * Math.Cos(phi)); y3 = Convert.ToSingle(0.5 * Math.Sin(phi)); q1.Position = new Vector4(x2, y2, z, 1.0f); q2.Position = new Vector4(x2, y2, -z, 1.0f); q3.Position = new Vector4(x3, y3, z, 1.0f); q4.Position = new Vector4(x3, y3, -z, 1.0f); e1 = new Vector3(q2.Position.X - q1.Position.X, q2.Position.Y - q1.Position.Y, q2.Position.Z - q1.Position.Z); e2 = new Vector3(q3.Position.X - q2.Position.X, q3.Position.Y - q2.Position.Y, q3.Position.Z - q2.Position.Z); n = Vector3.Cross(e2, e1); q1.Normals = n; q2.Normals = n; q3.Normals = n; q4.Normals = n; vlist.Add(q1); vlist.Add(q2); vlist.Add(q3); vlist.Add(q4); ilist.Add(offset); ilist.Add(offset + 2); ilist.Add(offset + 1); ilist.Add(offset + 2); ilist.Add(offset + 3); ilist.Add(offset + 1); #endregion float minx = float.MaxValue, miny = float.MaxValue, minz = float.MaxValue; float maxx = float.MinValue, maxy = float.MinValue, maxz = float.MinValue; foreach (Pos4Norm3Tex2Vertex v in vlist) { minx = v.Position.X < minx ? v.Position.X : minx; miny = v.Position.Y < miny ? v.Position.Y : miny; minz = v.Position.Z < minz ? v.Position.Z : minz; maxx = v.Position.X > maxx ? v.Position.X : maxx; maxy = v.Position.Y > maxy ? v.Position.Y : maxy; maxz = v.Position.Z > maxz ? v.Position.Z : maxz; } DataStream ds = new DataStream(vlist.Count * Pos4Norm3Tex2Vertex.VertexSize, true, true); ds.Position = 0; ds.WriteRange(vlist.ToArray()); ds.Position = 0; var vbuffer = new SlimDX.Direct3D11.Buffer(context.Device, ds, new BufferDescription() { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SizeInBytes = (int)ds.Length, Usage = ResourceUsage.Default }); ds.Dispose(); var indexstream = new DataStream(ilist.Count * 4, true, true); indexstream.WriteRange(ilist.ToArray()); indexstream.Position = 0; geom.VertexBuffer = vbuffer; geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true); geom.InputLayout = Pos4Norm3Tex2Vertex.Layout; geom.Topology = PrimitiveTopology.TriangleList; geom.VerticesCount = vlist.Count; geom.VertexSize = Pos4Norm3Tex2Vertex.VertexSize; geom.HasBoundingBox = true; geom.BoundingBox = new BoundingBox(new Vector3(minx, miny, minz), new Vector3(maxx, maxy, maxz)); return geom; }