Example #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)
            };
        }
Example #2
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);
        }
Example #3
0
        public static DescriptorItem CombinedImageSampler(ShaderType shaderType, Texture2D texture, SamplerFilter minFilter, SamplerFilter magFilter, SamplerFilter mipmapFilter = SamplerFilter.Nearest)
        {
            var item = new DescriptorItem();

            item.Type    = DescriptorType.CombinedImageSampler;
            item.Shader  = shaderType;
            item.Texture = texture;
            item.Sampler = VKHelper.CreateSampler(
                texture.Context,
                minFilter == SamplerFilter.Nearest ? Filter.Nearest :
                minFilter == SamplerFilter.Cubic ? Filter.CubicImg :
                Filter.Linear,
                magFilter == SamplerFilter.Nearest ? Filter.Nearest :
                magFilter == SamplerFilter.Cubic ? Filter.CubicImg :
                Filter.Linear,
                mipmapFilter == SamplerFilter.Linear ? SamplerMipmapMode.Linear :
                SamplerMipmapMode.Nearest
                );
            return(item);
        }