예제 #1
0
        public MeshRenderer(Graphics g, Texture2D tex, string vertexShader, string fragmentShader, int maxInstances = 1024, int maxUniqueMeshes = 8)
        {
            MaxInstances    = maxInstances;
            MaxUniqueMeshes = maxUniqueMeshes;
            Graphics        = g;
            Texture         = tex;
            Instances       = new VKBuffer[maxUniqueMeshes];
            Count           = new int[maxUniqueMeshes];
            Meshes          = new Mesh[maxUniqueMeshes];
            for (var i = 0; i < maxUniqueMeshes; i++)
            {
                Instances[i] = VKBuffer.InstanceInfo <MeshRenderInfo>(g, maxInstances);
            }
            TempInstances      = new MeshInfo[maxInstances];
            InstanceCopyBuffer = new MeshRenderInfo[maxInstances];
            UProjection        = VKBuffer.UniformBuffer <ViewProjection>(g, 1);
            UTime = VKBuffer.UniformBuffer <float>(g, 1);

            Pipeline = new PipelineController(Graphics);
            Pipeline.ClearDepthOnBeginPass = true;
            Pipeline.DepthTest             = false;
            Pipeline.DepthWrite            = false;
            Pipeline.BlendMode             = BlendMode.AlphaPremultiplied;
            Pipeline.Instancing            = true;
            Pipeline.InstanceInfoType      = typeof(MeshRenderInfo);
            Pipeline.Shaders         = new[] { vertexShader, fragmentShader };
            Pipeline.DescriptorItems = new[] {
                DescriptorItem.UniformBuffer(DescriptorItem.ShaderType.Vertex, UProjection),
                DescriptorItem.UniformBuffer(DescriptorItem.ShaderType.Vertex, UTime),
                DescriptorItem.CombinedImageSampler(DescriptorItem.ShaderType.Fragment, tex, DescriptorItem.SamplerFilter.Nearest, DescriptorItem.SamplerFilter.Nearest)
            };
        }
예제 #2
0
파일: Mesh.cs 프로젝트: meriaizen86/Vulpine
 public Mesh(Graphics g, Vertex[] vertices, int[] indices, Vector3 boxMin, Vector3 boxMax)
 {
     ID       = NextID++;
     Vertices = ToDispose(VKBuffer.Vertex(g.Context, vertices));
     Indices  = ToDispose(VKBuffer.Index(g.Context, indices));
     BoxMin   = boxMin;
     BoxMax   = boxMax;
 }
예제 #3
0
파일: Mesh.cs 프로젝트: meriaizen86/Vulpine
 internal Mesh(Context ctx, Vertex[] vertices, int[] indices, Vector3 boxMin, Vector3 boxMax)
 {
     ID       = NextID++;
     Vertices = ToDispose(VKBuffer.Vertex(ctx, vertices));
     Indices  = ToDispose(VKBuffer.Index(ctx, indices));
     BoxMin   = boxMin;
     BoxMax   = boxMax;
 }
예제 #4
0
        public static DescriptorItem UniformBuffer(ShaderType shaderType, VKBuffer buffer)
        {
            var item = new DescriptorItem();

            item.Type   = DescriptorType.UniformBuffer;
            item.Shader = shaderType;
            item.Buffer = buffer;
            return(item);
        }
예제 #5
0
파일: Mesh.cs 프로젝트: meriaizen86/Vulpine
        public Mesh(Graphics g, Vertex[] vertices, int[] indices)
        {
            ID = NextID++;
            var minX = 0f;
            var minY = 0f;
            var minZ = 0f;
            var maxX = 0f;
            var maxY = 0f;
            var maxZ = 0f;

            foreach (var vert in vertices)
            {
                if (vert.Position.X < minX)
                {
                    minX = vert.Position.X;
                }
                else if (vert.Position.X > maxX)
                {
                    maxX = vert.Position.X;
                }
                if (vert.Position.Y < minY)
                {
                    minY = vert.Position.Y;
                }
                else if (vert.Position.Y > maxY)
                {
                    maxY = vert.Position.Y;
                }
                if (vert.Position.Z < minZ)
                {
                    minZ = vert.Position.Z;
                }
                else if (vert.Position.Z > maxZ)
                {
                    maxZ = vert.Position.Z;
                }
            }

            Vertices = ToDispose(VKBuffer.Vertex(g.Context, vertices));
            Indices  = ToDispose(VKBuffer.Index(g.Context, indices));
            BoxMin   = new Vector3(minX, minY, minZ);
            BoxMax   = new Vector3(maxX, maxY, maxZ);
        }
 public void Draw(Mesh mesh, VKBuffer instanceInfo, int instances, int firstIndex = 0, int firstVertex = 0, int firstInstance = 0)
 {
     CommandBuffer.CmdBindVertexBuffers(0, 2, new[] { mesh.Vertices.Buffer, instanceInfo.Buffer }, new[] { 0L, 0L });
     CommandBuffer.CmdBindIndexBuffer(mesh.Indices);
     CommandBuffer.CmdDrawIndexed(mesh.Indices.Count, instances, firstIndex, firstVertex, firstInstance);
 }