Пример #1
0
        Pipeline BuildPipeline(GraphicsDevice gd, SceneContext sc, SpriteShaderKey key)
        {
            var shaderCache           = Resolve <IShaderCache>();
            var vertexShaderName      = "SpriteSV.vert";
            var fragmentShaderName    = "SpriteSF.frag";
            var vertexShaderContent   = shaderCache.GetGlsl(vertexShaderName);
            var fragmentShaderContent = shaderCache.GetGlsl(fragmentShaderName);

            if (key.UseArrayTexture)
            {
                fragmentShaderName   += ".array";
                fragmentShaderContent =
                    @"#define USE_ARRAY_TEXTURE
" + fragmentShaderContent;
            }

            var shaders = shaderCache.GetShaderPair(
                gd.ResourceFactory,
                vertexShaderName, fragmentShaderName,
                vertexShaderContent, fragmentShaderContent);

            _shaders.AddRange(shaders);
            var shaderSet = new ShaderSetDescription(new[] { VertexLayout, InstanceLayout }, shaders);

            Console.WriteLine($"-- Build SpriteRenderer-- IsDepth0..1: {gd.IsDepthRangeZeroToOne} YInvert: {gd.IsClipSpaceYInverted} UV TopLeft: {gd.IsUvOriginTopLeft}");
            var depthStencilMode =
                key.PerformDepthTest
                ?  gd.IsDepthRangeZeroToOne
                    ? DepthStencilStateDescription.DepthOnlyLessEqual
                    : DepthStencilStateDescription.DepthOnlyGreaterEqual
                : DepthStencilStateDescription.Disabled;

            var rasterizerMode = new RasterizerStateDescription(
                FaceCullMode.None,
                PolygonFillMode.Solid,
                FrontFace.Clockwise,
                key.PerformDepthTest, // depth test
                true);                // scissor test

            var pipelineDescription = new GraphicsPipelineDescription(
                BlendStateDescription.SingleAlphaBlend,
                depthStencilMode,
                rasterizerMode,
                PrimitiveTopology.TriangleList,
                new ShaderSetDescription(new[] { VertexLayout, InstanceLayout },
                                         shaderSet.Shaders,
                                         ShaderHelper.GetSpecializations(gd)),
                new[] { _perSpriteResourceLayout, sc.CommonResourceLayout },
                sc.MainSceneFramebuffer.OutputDescription);

            var pipeline = gd.ResourceFactory.CreateGraphicsPipeline(ref pipelineDescription);

            pipeline.Name = $"P_Sprite_{key}";
            return(pipeline);
        }
Пример #2
0
        public void Render(GraphicsDevice gd, CommandList cl, SceneContext sc, RenderPasses renderPass, IRenderable renderable)
        {
            ITextureManager textureManager = Resolve <ITextureManager>();
            // float depth = gd.IsDepthRangeZeroToOne ? 0 : 1;
            var sprite    = (MultiSprite)renderable;
            var shaderKey = new SpriteShaderKey(
                sprite.Key.Texture.ArrayLayers > 1,
                !sprite.Flags.HasFlag(SpriteFlags.NoDepthTest));

            //if (!shaderKey.UseArrayTexture)
            //    return;

            cl.PushDebugGroup($"Sprite:{sprite.Key.Texture.Name}:{sprite.Key.RenderOrder}");
            TextureView textureView = textureManager?.GetTexture(sprite.Key.Texture);

            if (sc.PaletteView == null)
            {
                return;
            }

            var resourceSet = gd.ResourceFactory.CreateResourceSet(new ResourceSetDescription(
                                                                       _perSpriteResourceLayout,
                                                                       sc.ProjectionMatrixBuffer,
                                                                       sc.ModelViewMatrixBuffer,
                                                                       gd.PointSampler,
                                                                       textureView,
                                                                       sc.PaletteView
                                                                       ));

            resourceSet.Name = $"RS_Sprite:{sprite.Key.Texture.Name}";
            _resourceSets.Add(resourceSet);

            cl.SetPipeline(_pipelines[shaderKey]);
            cl.SetGraphicsResourceSet(0, resourceSet);
            cl.SetGraphicsResourceSet(1, sc.CommonResourceSet);
            cl.SetVertexBuffer(0, _vertexBuffer);
            cl.SetIndexBuffer(_indexBuffer, IndexFormat.UInt16);
            cl.SetVertexBuffer(1, _instanceBuffers[sprite.BufferId]);

            //cl.SetViewport(0, new Viewport(0, 0, sc.MainSceneColorTexture.Width, sc.MainSceneColorTexture.Height, depth, depth));
            cl.DrawIndexed((uint)Indices.Length, (uint)sprite.Instances.Length, 0, 0, 0);
            //cl.SetViewport(0, new Viewport(0, 0, sc.MainSceneColorTexture.Width, sc.MainSceneColorTexture.Height, 0, 1));
            cl.PopDebugGroup();
        }
Пример #3
0
        public void Render(GraphicsDevice gd, CommandList cl, SceneContext sc, RenderPasses renderPass, IRenderable renderable)
        {
            ITextureManager      textureManager = Resolve <ITextureManager>();
            IDeviceObjectManager dom            = Resolve <IDeviceObjectManager>();
            // float depth = gd.IsDepthRangeZeroToOne ? 0 : 1;
            var sprite    = (MultiSprite)renderable;
            var shaderKey = new SpriteShaderKey(sprite);

            sprite.PipelineId = shaderKey.GetHashCode();

            //if (!shaderKey.UseArrayTexture)
            //    return;

            cl.PushDebugGroup($"Sprite:{sprite.Key.Texture.Name}:{sprite.Key.RenderOrder}");

            var uniformInfo = new SpriteUniformInfo {
                Flags = sprite.Key.Flags
            };

            cl.UpdateBuffer(_uniformBuffer, 0, uniformInfo);

            if (sc.PaletteView == null)
            {
                return;
            }

            TextureView textureView    = textureManager?.GetTexture(sprite.Key.Texture);
            var         resourceSet    = dom.Get <ResourceSet>((sprite, textureView));
            var         instanceBuffer = dom.Get <DeviceBuffer>((sprite, sprite));

            cl.SetPipeline(_pipelines[shaderKey]);
            cl.SetGraphicsResourceSet(0, resourceSet);
            cl.SetGraphicsResourceSet(1, sc.CommonResourceSet);
            cl.SetVertexBuffer(0, _vertexBuffer);
            cl.SetIndexBuffer(_indexBuffer, IndexFormat.UInt16);
            cl.SetVertexBuffer(1, instanceBuffer);

            //cl.SetViewport(0, new Viewport(0, 0, sc.MainSceneColorTexture.Width, sc.MainSceneColorTexture.Height, depth, depth));
            cl.DrawIndexed((uint)Indices.Length, (uint)sprite.ActiveInstances, 0, 0, 0);
            //cl.SetViewport(0, new Viewport(0, 0, sc.MainSceneColorTexture.Width, sc.MainSceneColorTexture.Height, 0, 1));
            cl.PopDebugGroup();
        }