예제 #1
0
        public DX11VertexGeometry BoxLine(Box settings)
        {
            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);

            DX11VertexGeometry geom = new DX11VertexGeometry(device);

            geom.Tag            = settings;
            geom.PrimitiveType  = settings.PrimitiveType;
            geom.Topology       = PrimitiveTopology.LineList;
            geom.VerticesCount  = 24;
            geom.VertexSize     = Pos4Vertex.VertexSize;
            geom.InputLayout    = Pos4Vertex.Layout;
            geom.HasBoundingBox = true;
            geom.BoundingBox    = new BoundingBox(-s3, s3);

            DataStream vertexstream = new DataStream(24 * Pos4Vertex.VertexSize, true, true);

            vertexstream.Position = 0;

            //Front Face
            vertexstream.Write <Vector4>(BoxData.BottomLeftFront.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.BottomRightFront.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.BottomRightFront.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.TopRightFront.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.TopRightFront.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.TopLeftFront.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.TopLeftFront.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.BottomLeftFront.MulComp(size));

            //Back face
            vertexstream.Write <Vector4>(BoxData.BottomLeftBack.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.BottomRightBack.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.BottomRightBack.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.TopRightBack.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.TopRightBack.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.TopLeftBack.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.TopLeftBack.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.BottomLeftBack.MulComp(size));

            //Connections
            vertexstream.Write <Vector4>(BoxData.BottomLeftFront.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.BottomLeftBack.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.TopLeftFront.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.TopLeftBack.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.TopRightFront.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.TopRightBack.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.BottomRightFront.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.BottomRightBack.MulComp(size));

            var vbo = DX11VertexBuffer.CreateImmutable <Vector4>(device, vertexstream);

            geom.VertexBuffer = vbo.Buffer;
            vertexstream.Dispose();
            return(geom);
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="context">Render context</param>
        /// <param name="vertexSize">Vertex size</param>
        /// <param name="vertexCount">Vertex Count</param>
        /// <param name="inputElements">Input elements</param>
        public StreamOutputBufferWithRawSupport(DX11RenderContext context, int vertexSize, int vertexCount, OutputDrawMode outputDrawMode, bool allowIndexBuffer, InputElement[] inputElements)
        {
            this.innerBuffer = BufferHelper.CreateStreamOutBuffer(context, vertexSize, vertexCount, true, allowIndexBuffer);

            //Copy a new Vertex buffer with stream out
            this.vertexGeometry           = new DX11VertexGeometry(context);
            vertexGeometry.HasBoundingBox = false;
            vertexGeometry.InputLayout    = inputElements;
            vertexGeometry.Topology       = PrimitiveTopology.TriangleList;
            vertexGeometry.VertexBuffer   = innerBuffer;
            vertexGeometry.VertexSize     = vertexSize;
            vertexGeometry.VerticesCount  = vertexCount;

            if (outputDrawMode == OutputDrawMode.Auto)
            {
                vertexGeometry.AssignDrawer(new DX11VertexAutoDrawer());
            }

            if (context.ComputeShaderSupport)
            {
                this.rawBuffer = new DX11RawBuffer(context, innerBuffer);
            }

            if (allowIndexBuffer)
            {
                this.indexBuffer = DX11IndexBuffer.FromReference(context, this.innerBuffer, vertexCount);
            }
        }
예제 #3
0
        public void Update(IPluginIO pin, DX11RenderContext context)
        {
            if (this.updateddevices.Contains(context))
            {
                return;
            }
            if (reset || !this.FOutGeom[0].Contains(context))
            {
                this.DisposeBuffers(context);

                // int vsize = customlayout ? size : ig.VertexSize;
                SlimDX.Direct3D11.Buffer vbo = BufferHelper.CreateStreamOutBuffer(context, vsize, this.cnt);

                //Copy a new Vertex buffer with stream out
                DX11VertexGeometry vg = new DX11VertexGeometry(context);
                vg.AssignDrawer(new DX11VertexAutoDrawer());
                vg.HasBoundingBox = false;
                vg.InputLayout    = this.FInLayout.ToArray();
                vg.Topology       = PrimitiveTopology.TriangleList;
                vg.VertexBuffer   = vbo;
                vg.VertexSize     = vsize;
                vg.VerticesCount  = this.cnt;

                this.buffer = vbo;

                this.FOutGeom[0][context] = vg;
            }

            this.updateddevices.Add(context);
        }
        public void Update(IPluginIO pin, DX11RenderContext context)
        {
            for (int i = 0; i < this.FOutGeom.SliceCount; i++)
            {
                DX11VertexGeometry geom = (DX11VertexGeometry)this.FInGeom[i][context].ShallowCopy();

                if (this.FInEnabled[i])
                {
                    if (this.FInGeom.IsChanged || this.FInCnt.IsChanged)
                    {
                        DX11VertexIndirectDrawer ind = new DX11VertexIndirectDrawer();
                        geom.AssignDrawer(ind);

                        ind.Update(context, this.FInCnt[i]);
                    }

                    DX11VertexIndirectDrawer drawer = (DX11VertexIndirectDrawer)geom.Drawer;

                    if (this.FInI.PluginIO.IsConnected)
                    {
                        drawer.IndirectArgs.CopyInstanceCount(context.CurrentDeviceContext, this.FInI[i][context].UAV);
                    }

                    if (this.FInV.PluginIO.IsConnected)
                    {
                        drawer.IndirectArgs.CopyVertexCount(context.CurrentDeviceContext, this.FInV[i][context].UAV);
                    }

                    this.FOutGeom[i][context] = geom;
                }
            }
        }
예제 #5
0
        public DX11VertexGeometry QuadLine(Quad settings)
        {
            Vector2 size = settings.Size;

            float sx = 0.5f * size.X;
            float sy = 0.5f * size.Y;

            DX11VertexGeometry geom = new DX11VertexGeometry(device);

            geom.Tag            = settings;
            geom.PrimitiveType  = settings.PrimitiveType;
            geom.Topology       = PrimitiveTopology.LineStrip;
            geom.InputLayout    = Pos4Vertex.Layout;
            geom.VerticesCount  = 5;
            geom.VertexSize     = Pos4Vertex.VertexSize;
            geom.HasBoundingBox = true;
            geom.BoundingBox    = new BoundingBox(new Vector3(-sx, -sy, 0.0f), new Vector3(sx, sy, 0.0f));

            Vector4[] verts = new Vector4[]
            {
                new Vector4(-sx, -sy, 0.0f, 1.0f),
                new Vector4(sx, -sy, 0.0f, 1.0f),
                new Vector4(sx, sy, 0.0f, 1.0f),
                new Vector4(-sx, sy, 0.0f, 1.0f),
                new Vector4(-sx, -sy, 0.0f, 1.0f)
            };
            geom.VertexBuffer = DX11VertexBuffer.CreateImmutable <Vector4>(device, verts).Buffer;
            return(geom);
        }
예제 #6
0
        public static DX11VertexGeometry LineStrip3d(DX11RenderContext context, List <Vector3> points, List <Vector3> directions, bool loop)
        {
            //Use direction verctor as normal, useful when we have analytical derivatives for direction
            DX11VertexGeometry geom = new DX11VertexGeometry(context);

            int ptcnt = Math.Max(points.Count, directions.Count);

            int vcount = loop ? ptcnt + 1 : ptcnt;

            FeralTic.DX11.Geometry.Pos3Norm3Tex2Vertex[] verts = new FeralTic.DX11.Geometry.Pos3Norm3Tex2Vertex[vcount];

            float inc = loop ? 1.0f / (float)vcount : 1.0f / ((float)vcount + 1.0f);

            float curr = 0.0f;


            for (int i = 0; i < ptcnt; i++)
            {
                verts[i].Position    = points[i % points.Count];
                verts[i].Normals     = directions[i % directions.Count];
                verts[i].TexCoords.X = curr;
                curr += inc;
            }

            if (loop)
            {
                verts[ptcnt].Position    = points[0];
                verts[ptcnt].Normals     = directions[0];
                verts[ptcnt].TexCoords.X = 1.0f;
            }


            DataStream ds = new DataStream(vcount * FeralTic.DX11.Geometry.Pos3Norm3Tex2Vertex.VertexSize, true, true);

            ds.Position = 0;
            ds.WriteRange(verts);
            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();

            geom.VertexBuffer  = vbuffer;
            geom.InputLayout   = FeralTic.DX11.Geometry.Pos3Norm3Tex2Vertex.Layout;
            geom.Topology      = PrimitiveTopology.LineStrip;
            geom.VerticesCount = vcount;
            geom.VertexSize    = FeralTic.DX11.Geometry.Pos3Norm3Tex2Vertex.VertexSize;

            geom.HasBoundingBox = false;

            return(geom);
        }
예제 #7
0
        private IDxGeometry PrepareGeometry(IDxGeometry geometry)
        {
            if (geometry is DX11VertexGeometry)
            {
                DX11VertexGeometry vd = (DX11VertexGeometry)geometry.ShallowCopy();
                vd.VertexBuffer  = this.rawbuffer.Buffer;
                vd.VertexSize    = this.outputvertexsize;
                vd.VerticesCount = this.outputvertexcount;
                vd.InputLayout   = this.outputlayout;
                vd.Topology      = geometry.Topology;
                if (this.AsAuto)
                {
                    DX11VertexAutoDrawer auto = new DX11VertexAutoDrawer();
                    vd.AssignDrawer(auto);
                }
                return(vd);
            }
            if (geometry is DX11IndexedGeometry)
            {
                if (this.AsAuto)
                {
                    DX11VertexGeometry vd = new DX11VertexGeometry(this.Device);
                    vd.VertexBuffer  = this.rawbuffer.Buffer;
                    vd.VertexSize    = this.outputvertexsize;
                    vd.VerticesCount = this.outputvertexcount;
                    vd.InputLayout   = this.outputlayout;
                    vd.Topology      = geometry.Topology;
                    DX11VertexAutoDrawer auto = new DX11VertexAutoDrawer();
                    vd.AssignDrawer(auto);
                    return(vd);
                }
                else
                {
                    //Replace the vertexbuffer
                    DX11IndexedGeometry id = (DX11IndexedGeometry)geometry.ShallowCopy();
                    id.InputLayout  = this.outputlayout;
                    id.VertexBuffer = DX11VertexBuffer.CreateFromRawBuffer(this.Device, this.outputvertexcount, this.outputvertexsize, this.rawbuffer);
                    return(id);
                }
            }
            if (geometry is DX11NullGeometry)
            {
                DX11VertexGeometry vd = new DX11VertexGeometry(this.Device);
                vd.VertexBuffer  = this.rawbuffer.Buffer;
                vd.VertexSize    = this.outputvertexsize;
                vd.VerticesCount = this.outputvertexcount;
                vd.InputLayout   = this.outputlayout;
                vd.Topology      = geometry.Topology;
                if (this.AsAuto)
                {
                    DX11VertexAutoDrawer auto = new DX11VertexAutoDrawer();
                    vd.AssignDrawer(auto);
                }
                return(vd);
            }

            throw new NotSupportedException("Can't prepare geometry from provided geometry");
        }
예제 #8
0
        public DX11VertexGeometry LineStrip3d(List <Vector3> points, bool loop)
        {
            DX11VertexGeometry geom = new DX11VertexGeometry(context);

            int vcount = loop ? points.Count + 1 : points.Count;

            Pos3Tex2Vertex[] verts = new Pos3Tex2Vertex[vcount];

            float inc = loop ? 1.0f / (float)vcount : 1.0f / ((float)vcount + 1.0f);

            float curr = 0.0f;


            for (int i = 0; i < points.Count; i++)
            {
                verts[i].Position    = points[i];
                verts[i].TexCoords.X = curr;
                curr += inc;
            }

            if (loop)
            {
                verts[points.Count].Position    = points[0];
                verts[points.Count].TexCoords.X = 1.0f;
            }


            DataStream ds = new DataStream(vcount * Pos3Tex2Vertex.VertexSize, true, true);

            ds.Position = 0;
            ds.WriteRange(verts);
            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();

            geom.VertexBuffer  = vbuffer;
            geom.InputLayout   = Pos3Tex2Vertex.Layout;
            geom.Topology      = PrimitiveTopology.LineStrip;
            geom.VerticesCount = vcount;
            geom.VertexSize    = Pos3Tex2Vertex.VertexSize;

            geom.HasBoundingBox = false;

            return(geom);
        }
 public void Update(IPluginIO pin, DX11RenderContext context)
 {
     if (this.FInvalidate || !this.FOutput[0].Data.ContainsKey(context))
     {
         for (int i = 0; i < oldSpreadMax; i++)
         {
             DX11VertexGeometry geom = this.GetGeom(context, i);
             this.FOutput[i][context] = geom;
         }
     }
 }
 public void Update(DX11RenderContext context)
 {
     if ((this.FInvalidate && this.FOutput.SliceCount > 0) || !this.FOutput[0].Contains(context))
     {
         for (int i = 0; i < oldSpreadMax; i++)
         {
             DX11VertexGeometry geom = this.GetGeom(context, i);
             this.FOutput[i][context] = geom;
         }
     }
 }
예제 #11
0
        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 void Update(IPluginIO pin, DX11RenderContext context)
        {
            for (int i = 0; i < this.FOutGeom.SliceCount; i++)
            {
                DX11VertexGeometry geom = (DX11VertexGeometry)this.FInGeom[i][context].ShallowCopy();
                if (this.FInEnabled[i])
                {
                    DX11InstancedVertexDrawer d = new DX11InstancedVertexDrawer();
                    d.InstanceCount = this.FInCnt[i];

                    geom.AssignDrawer(d);
                }

                this.FOutGeom[i][context] = geom;
            }
        }
예제 #13
0
        public static IDX11Geometry CreateVertexGeometry(DX11RenderContext context, List <Vector3> points, List <Vector3> normals, List <Vector2> tex, MeshTopology topology)
        {
            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(count * FeralTic.DX11.Geometry.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();

            DX11VertexGeometry geom = new DX11VertexGeometry(context);

            geom.VertexBuffer  = vbuffer;
            geom.InputLayout   = FeralTic.DX11.Geometry.Pos3Norm3Tex2Vertex.Layout;
            geom.Topology      = (PrimitiveTopology)topology;
            geom.VerticesCount = count;
            geom.VertexSize    = FeralTic.DX11.Geometry.Pos3Norm3Tex2Vertex.VertexSize;

            geom.HasBoundingBox = false;

            return(geom);
        }
예제 #14
0
        public void Update(DX11RenderContext context)
        {
            if (this.FInvalidate)
            {
                if (this.FOutput[0].Contains(context))
                {
                    this.FOutput[0].Dispose(context);
                }

                DX11VertexGeometry geom = new DX11VertexGeometry(context);
                geom.InputLayout = this.inputlayout;
                geom.VertexSize  = this.vertexsize;

                try
                {
                    this.FStream.Position = 0;
                    var vertices = new SlimDX.Direct3D11.Buffer(context.Device, this.FStream, new BufferDescription()
                    {
                        BindFlags      = BindFlags.VertexBuffer,
                        CpuAccessFlags = CpuAccessFlags.None,
                        OptionFlags    = ResourceOptionFlags.None,
                        SizeInBytes    = (int)this.FStream.Length,
                        Usage          = ResourceUsage.Default
                    });

                    geom.VerticesCount  = this.FInVerticesCount[0];
                    geom.VertexBuffer   = vertices;
                    geom.Topology       = this.FInTopology[0];
                    geom.HasBoundingBox = false;

                    /*if (geom.Topology == PrimitiveTopology.LineListWithAdjacency)
                     * {
                     *  geom.VerticesCount /= 2;
                     * }*/

                    this.FOutput[0][context] = geom;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
예제 #15
0
        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;
                }
            }
        }
예제 #16
0
 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)
        {
            for (int i = 0; i < this.FOutGeom.SliceCount; i++)
            {
                DX11VertexGeometry geom = (DX11VertexGeometry)this.FInGeom[i][context].ShallowCopy();

                if (this.FInEnabled[i])
                {
                    if (this.FInGeom.IsChanged || this.FInCnt.IsChanged)
                    {
                        DX11VertexIndirectDrawer ind = new DX11VertexIndirectDrawer();
                        geom.AssignDrawer(ind);

                        ind.Update(context, this.FInCnt[i]);
                    }

                    DX11VertexIndirectDrawer drawer = (DX11VertexIndirectDrawer)geom.Drawer;
                    var argBuffer = drawer.IndirectArgs.Buffer;

                    if (this.FInI.PluginIO.IsConnected)
                    {
                        int            instOffset = this.FInInstOffset[i];
                        ResourceRegion region     = new ResourceRegion(instOffset, 0, 0, instOffset + 4, 1, 1);
                        context.CurrentDeviceContext.CopySubresourceRegion(this.FInI[i][context].Buffer, 0, region, argBuffer, 0, 4, 0, 0);
                    }

                    if (this.FInV.PluginIO.IsConnected)
                    {
                        int            vOffset = this.FInVtxOffset[i];
                        ResourceRegion region  = new ResourceRegion(vOffset, 0, 0, vOffset + 4, 1, 1);
                        context.CurrentDeviceContext.CopySubresourceRegion(this.FInV[i][context].Buffer, 0, region, argBuffer, 0, 0, 0, 0);
                    }

                    this.FOutGeom[i][context] = geom;
                }
            }
        }
예제 #18
0
        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 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);
        }
예제 #20
0
        public DX11VertexGeometry LineStrip3d(List <Vector3> points, bool loop, bool buildAdjacency = false)
        {
            if (points.Count == 0)
            {
                //Build zero line
                points = new List <Vector3>(2);
                points.Add(Vector3.Zero);
                points.Add(Vector3.Zero);
            }
            else if (points.Count == 1)
            {
                var oldPoints = points;
                //Build zero line using current vertex
                points = new List <Vector3>(2);
                points.Add(oldPoints[0]);
                points.Add(oldPoints[0]);
            }

            DX11VertexGeometry geom = new DX11VertexGeometry(context);

            //Line has N vertex count, we add 1 in case of loop to close, and we add 2 more in case of adjacency
            int lineVertexCount  = loop ? points.Count + 1 : points.Count;
            int totalVertexCount = buildAdjacency ? lineVertexCount + 2 : lineVertexCount;
            int startWriteIndex  = buildAdjacency ? 1 : 0;

            Pos3Tex2Vertex[] verts = new Pos3Tex2Vertex[totalVertexCount];

            float uvStep    = loop ? 1.0f / (float)totalVertexCount : 1.0f / ((float)totalVertexCount + 1.0f);
            float currentUv = 0.0f;

            for (int i = 0; i < points.Count; i++)
            {
                verts[startWriteIndex + i].Position    = points[i];
                verts[startWriteIndex + i].TexCoords.X = currentUv;
                currentUv += uvStep;
            }

            //Add first point to close the loop
            if (loop)
            {
                verts[startWriteIndex + points.Count].Position    = points[0];
                verts[startWriteIndex + points.Count].TexCoords.X = 1.0f;
            }

            if (buildAdjacency)
            {
                if (loop)
                {
                    //Add last point from the line as first vertex
                    verts[0] = verts[lineVertexCount - 1];

                    //Add second point as loop = last point
                    verts[0] = verts[1];
                }
                else
                {
                    //In that case, we just extend the lines from beginning and end, first point we reverse that dir
                    Vector3 originDir = points[1] - points[0];
                    verts[0].Position  = points[0] - originDir;
                    verts[0].TexCoords = new Vector2(0.0f, 0.0f);

                    //Last point to previous
                    Vector3 destDir = points[points.Count - 1] - points[points.Count - 2];
                    verts[verts.Length - 1].Position  = points[points.Count - 1] + destDir;
                    verts[verts.Length - 1].TexCoords = new Vector2(1.0f, 0.0f);
                }
            }


            DataStream ds = new DataStream(totalVertexCount * Pos3Tex2Vertex.VertexSize, true, true);

            ds.Position = 0;
            ds.WriteRange(verts);
            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();

            geom.VertexBuffer   = vbuffer;
            geom.InputLayout    = Pos3Tex2Vertex.Layout;
            geom.Topology       = buildAdjacency ? PrimitiveTopology.LineStripWithAdjacency : PrimitiveTopology.LineStrip;
            geom.VerticesCount  = totalVertexCount;
            geom.VertexSize     = Pos3Tex2Vertex.VertexSize;
            geom.HasBoundingBox = false;

            return(geom);
        }
예제 #21
0
        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];
            }
        }
예제 #22
0
        protected override DX11VertexGeometry GetGeom(DX11RenderContext device, int slice)
        {
            if (d2dFactory == null)
            {
                d2dFactory = new D2DFactory();
                dwFactory  = new DWriteFactory(SharpDX.DirectWrite.FactoryType.Shared);
            }

            TextFormat fmt = new TextFormat(dwFactory, this.FFontInput[slice].Name, FFontSize[slice]);
            TextLayout tl  = new TextLayout(dwFactory, FText[slice], fmt, 0.0f, 32.0f);

            tl.WordWrapping       = WordWrapping.NoWrap;
            tl.TextAlignment      = FHAlignment[slice];
            tl.ParagraphAlignment = FVAlignment[slice];

            OutlineRenderer renderer = new OutlineRenderer(d2dFactory);
            Extruder        ex       = new Extruder(d2dFactory);


            tl.Draw(renderer, 0.0f, 0.0f);

            var outlinedGeometry = renderer.GetGeometry();

            ex.GetVertices(outlinedGeometry, vertexList, this.FExtrude[slice]);
            outlinedGeometry.Dispose();

            Vector3 min = new Vector3(float.MaxValue);
            Vector3 max = new Vector3(float.MinValue);

            for (int i = 0; i < vertexList.Count; i++)
            {
                Pos3Norm3VertexSDX pn = vertexList[i];

                min.X = pn.Position.X < min.X ? pn.Position.X : min.X;
                min.Y = pn.Position.Y < min.Y ? pn.Position.Y : min.Y;
                min.Z = pn.Position.Z < min.Z ? pn.Position.Z : min.Z;

                max.X = pn.Position.X > max.X ? pn.Position.X : max.X;
                max.Y = pn.Position.Y > max.Y ? pn.Position.Y : max.Y;
                max.Z = pn.Position.Z > max.Z ? pn.Position.Z : max.Z;
            }

            SlimDX.DataStream ds = new SlimDX.DataStream(vertexList.Count * Pos3Norm3VertexSDX.VertexSize, true, true);
            ds.Position = 0;

            for (int i = 0; i < vertexList.Count; i++)
            {
                ds.Write(vertexList[i]);
            }

            ds.Position = 0;

            var vbuffer = new SlimDX.Direct3D11.Buffer(device.Device, ds, new SlimDX.Direct3D11.BufferDescription()
            {
                BindFlags      = SlimDX.Direct3D11.BindFlags.VertexBuffer,
                CpuAccessFlags = SlimDX.Direct3D11.CpuAccessFlags.None,
                OptionFlags    = SlimDX.Direct3D11.ResourceOptionFlags.None,
                SizeInBytes    = (int)ds.Length,
                Usage          = SlimDX.Direct3D11.ResourceUsage.Default
            });

            ds.Dispose();

            DX11VertexGeometry vg = new DX11VertexGeometry(device);

            vg.InputLayout    = Pos3Norm3VertexSDX.Layout;
            vg.Topology       = SlimDX.Direct3D11.PrimitiveTopology.TriangleList;
            vg.VertexBuffer   = vbuffer;
            vg.VertexSize     = Pos3Norm3VertexSDX.VertexSize;
            vg.VerticesCount  = vertexList.Count;
            vg.HasBoundingBox = true;
            vg.BoundingBox    = new SlimDX.BoundingBox(new SlimDX.Vector3(min.X, min.Y, min.Z), new SlimDX.Vector3(max.X, max.Y, max.Z));

            renderer.Dispose();
            fmt.Dispose();
            tl.Dispose();

            return(vg);
        }
예제 #23
0
        public static DX11VertexGeometry Text3d(DX11RenderContext device, string text, string fontName, float fontSize, float extrude, TextAlignment textAlignment, ParagraphAlignment paragraphAlignment)
        {
            //Dictionary<DX11RenderContext, DX11VertexGeometry> deviceDict = null;
            //if (TextGeometryCache.TryGetValue(text, out deviceDict))
            //{
            //    DX11VertexGeometry geom;
            //    if(deviceDict.TryGetValue(device, out geom))
            //    {
            //        return geom;
            //    }
            //}

            if (d2dFactory == null)
            {
                d2dFactory = new D2DFactory();
                dwFactory  = new DWriteFactory(SharpDX.DirectWrite.FactoryType.Shared);
            }

            TextFormat fmt = new TextFormat(dwFactory, fontName, fontSize);

            TextLayout tl = new TextLayout(dwFactory, text, fmt, 0.0f, .0f);

            tl.WordWrapping       = WordWrapping.NoWrap;
            tl.TextAlignment      = (SharpDX.DirectWrite.TextAlignment)textAlignment;
            tl.ParagraphAlignment = (SharpDX.DirectWrite.ParagraphAlignment)paragraphAlignment;

            OutlineRenderer renderer = new OutlineRenderer(d2dFactory);
            Extruder        ex       = new Extruder(d2dFactory);

            tl.Draw(renderer, 0.0f, 0.0f);

            var geo    = renderer.GetGeometry();
            var result = ex.GetVertices(geo, extrude).ToArray();

            renderer.Dispose();
            geo.Dispose();
            fmt.Dispose();
            tl.Dispose();

            Vector3 min = new Vector3(float.MaxValue);
            Vector3 max = new Vector3(float.MinValue);

            foreach (var pn in result)
            {
                min.X = pn.Position.X < min.X ? pn.Position.X : min.X;
                min.Y = pn.Position.Y < min.Y ? pn.Position.Y : min.Y;
                min.Z = pn.Position.Z < min.Z ? pn.Position.Z : min.Z;

                max.X = pn.Position.X > max.X ? pn.Position.X : max.X;
                max.Y = pn.Position.Y > max.Y ? pn.Position.Y : max.Y;
                max.Z = pn.Position.Z > max.Z ? pn.Position.Z : max.Z;
            }

            SlimDX.DataStream ds = new SlimDX.DataStream(result.Length * Pos3Norm3VertexSDX.VertexSize, true, true);
            ds.Position = 0;

            ds.WriteRange(result);

            ds.Position = 0;

            var vbuffer = new SlimDX.Direct3D11.Buffer(device.Device, ds, new SlimDX.Direct3D11.BufferDescription()
            {
                BindFlags      = SlimDX.Direct3D11.BindFlags.VertexBuffer,
                CpuAccessFlags = SlimDX.Direct3D11.CpuAccessFlags.None,
                OptionFlags    = SlimDX.Direct3D11.ResourceOptionFlags.None,
                SizeInBytes    = (int)ds.Length,
                Usage          = SlimDX.Direct3D11.ResourceUsage.Default,
            });

            ds.Dispose();

            DX11VertexGeometry vg = new DX11VertexGeometry(device);

            vg.InputLayout    = Pos3Norm3VertexSDX.Layout;
            vg.Topology       = SlimDX.Direct3D11.PrimitiveTopology.TriangleList;
            vg.VertexBuffer   = vbuffer;
            vg.VertexSize     = Pos3Norm3VertexSDX.VertexSize;
            vg.VerticesCount  = result.Length;
            vg.HasBoundingBox = true;
            vg.BoundingBox    = new SlimDX.BoundingBox(new SlimDX.Vector3(min.X, min.Y, min.Z), new SlimDX.Vector3(max.X, max.Y, max.Z));


            //if(deviceDict != null)
            //{
            //    deviceDict[device] = vg;
            //}
            //else
            //{
            //    deviceDict = new Dictionary<DX11RenderContext, DX11VertexGeometry>();
            //    deviceDict[device] = vg;
            //    TextGeometryCache[text] = deviceDict;
            //}

            return(vg);
        }