Ejemplo n.º 1
0
        public EnvironmentCube(string cubemapPath, DescriptorSet dsSkybox, PipelineLayout plLayout, Queue staggingQ, RenderPass renderPass, PipelineCache cache = null)
            : base(renderPass, cache, "EnvCube pipeline")
        {
            using (CommandPool cmdPool = new CommandPool(staggingQ.Dev, staggingQ.index)) {
                vboSkybox = new GPUBuffer <float> (staggingQ, cmdPool, VkBufferUsageFlags.VertexBuffer, box_vertices);

                cubemap = KTX.KTX.Load(staggingQ, cmdPool, cubemapPath,
                                       VkImageUsageFlags.Sampled, VkMemoryPropertyFlags.DeviceLocal, true);
                cubemap.CreateView(VkImageViewType.Cube, VkImageAspectFlags.Color, 6, 0, cubemap.CreateInfo.mipLevels);
                cubemap.CreateSampler(VkSamplerAddressMode.ClampToEdge);
                cubemap.SetName("skybox Texture");
                cubemap.Descriptor.imageLayout = VkImageLayout.ShaderReadOnlyOptimal;

                GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault(VkPrimitiveTopology.TriangleList, renderPass.Samples, false);
                cfg.RenderPass = renderPass;
                cfg.Layout     = plLayout;
                cfg.AddVertexBinding(0, 3 * sizeof(float));
                cfg.AddVertexAttributes(0, VkFormat.R32g32b32Sfloat);
                cfg.AddShader(VkShaderStageFlags.Vertex, "shaders/skybox.vert.spv");
                cfg.AddShader(VkShaderStageFlags.Fragment, "shaders/skybox.frag.spv");
                cfg.multisampleState.rasterizationSamples = Samples;

                layout = cfg.Layout;

                init(cfg);

                generateBRDFLUT(staggingQ, cmdPool);
                generateCubemaps(staggingQ, cmdPool);
            }
        }
Ejemplo n.º 2
0
        public PbrModelSeparatedTextures(Queue transferQ, string path, DescriptorSetLayout layout, params AttachmentType[] attachments)
        {
            dev = transferQ.Dev;
            using (CommandPool cmdPool = new CommandPool(dev, transferQ.index)) {
                using (glTFLoader ctx = new glTFLoader(path, transferQ, cmdPool)) {
                    ulong vertexCount, indexCount;

                    ctx.GetVertexCount(out vertexCount, out indexCount, out IndexBufferType);
                    ulong vertSize = vertexCount * (ulong)Marshal.SizeOf <Vertex> ();
                    ulong idxSize  = indexCount * (IndexBufferType == VkIndexType.Uint16 ? 2ul : 4ul);
                    ulong size     = vertSize + idxSize;

                    vbo = new GPUBuffer(dev, VkBufferUsageFlags.VertexBuffer | VkBufferUsageFlags.TransferDst, vertSize);
                    ibo = new GPUBuffer(dev, VkBufferUsageFlags.IndexBuffer | VkBufferUsageFlags.TransferDst, idxSize);

                    vbo.SetName("vbo gltf");
                    ibo.SetName("ibo gltf");

                    Meshes = new List <Mesh> (ctx.LoadMeshes <Vertex> (IndexBufferType, vbo, 0, ibo, 0));

                    textures = ctx.LoadImages();

                    loadMaterials(ctx, layout, attachments);

                    materialUBO = new HostBuffer <Material> (dev, VkBufferUsageFlags.UniformBuffer, materials);

                    Scenes = new List <Scene> (ctx.LoadScenes(out defaultSceneIndex));
                }
            }
        }
Ejemplo n.º 3
0
        public PbrModelTexArray(Queue transferQ, string path)
        {
            dev = transferQ.Dev;
            using (CommandPool cmdPool = new CommandPool(dev, transferQ.index)) {
                using (glTFLoader ctx = new glTFLoader(path, transferQ, cmdPool)) {
                    ulong vertexCount, indexCount;

                    ctx.GetVertexCount(out vertexCount, out indexCount, out IndexBufferType);
                    ulong vertSize = vertexCount * (ulong)Marshal.SizeOf <Vertex> ();
                    ulong idxSize  = indexCount * (IndexBufferType == VkIndexType.Uint16 ? 2ul : 4ul);
                    ulong size     = vertSize + idxSize;

                    vbo = new GPUBuffer(dev, VkBufferUsageFlags.VertexBuffer | VkBufferUsageFlags.TransferDst, vertSize);
                    ibo = new GPUBuffer(dev, VkBufferUsageFlags.IndexBuffer | VkBufferUsageFlags.TransferDst, idxSize);

                    vbo.SetName("vbo gltf");
                    ibo.SetName("ibo gltf");

                    Meshes = new List <Mesh> (ctx.LoadMeshes <Vertex> (IndexBufferType, vbo, 0, ibo, 0));

                    if (ctx.ImageCount > 0)
                    {
                        texArray = new Image(dev, Image.DefaultTextureFormat, VkImageUsageFlags.Sampled | VkImageUsageFlags.TransferDst | VkImageUsageFlags.TransferSrc,
                                             VkMemoryPropertyFlags.DeviceLocal, TEXTURE_DIM, TEXTURE_DIM, VkImageType.Image2D,
                                             VkSampleCountFlags.SampleCount1, VkImageTiling.Optimal, Image.ComputeMipLevels(TEXTURE_DIM), ctx.ImageCount);

                        ctx.BuildTexArray(ref texArray, 0);

                        texArray.CreateView(VkImageViewType.ImageView2DArray, VkImageAspectFlags.Color, texArray.CreateInfo.arrayLayers);
                        texArray.CreateSampler();
                        texArray.Descriptor.imageLayout = VkImageLayout.ShaderReadOnlyOptimal;
                        texArray.SetName("model texArray");
                    }

                    loadMaterials(ctx);

                    materialUBO = new HostBuffer <Material> (dev, VkBufferUsageFlags.UniformBuffer, materials);

                    Scenes = new List <Scene> (ctx.LoadScenes(out defaultSceneIndex));
                }
            }
        }
Ejemplo n.º 4
0
        public PbrModel(Queue transferQ, string path)
        {
            dev = transferQ.Dev;
            using (CommandPool cmdPool = new CommandPool(dev, transferQ.index)) {
                using (glTFLoader ctx = new glTFLoader(path, transferQ, cmdPool)) {
                    ulong vertexCount, indexCount;

                    ctx.GetVertexCount(out vertexCount, out indexCount, out IndexBufferType);

                    ulong vertSize = vertexCount * (ulong)Marshal.SizeOf <Vertex> ();
                    ulong idxSize  = indexCount * (IndexBufferType == VkIndexType.Uint16 ? 2ul : 4ul);
                    ulong size     = vertSize + idxSize;

                    vbo = new GPUBuffer(dev, VkBufferUsageFlags.VertexBuffer | VkBufferUsageFlags.TransferDst, vertSize);
                    ibo = new GPUBuffer(dev, VkBufferUsageFlags.IndexBuffer | VkBufferUsageFlags.TransferDst, idxSize);

                    vbo.SetName("vbo gltf");
                    ibo.SetName("ibo gltf");

                    Meshes = new List <Mesh> (ctx.LoadMeshes <Vertex> (IndexBufferType, vbo, 0, ibo, 0));
                    Scenes = new List <Scene> (ctx.LoadScenes(out defaultSceneIndex));
                }
            }
        }