예제 #1
0
        private void CreateShaders()
        {
            var vertexLayout = new VertexLayoutDescription
                               (
                16,
                0,
                new VertexElementDescription[]
            {
                new VertexElementDescription("Position", VertexElementFormat.Float2, VertexElementSemantic.Position),
                new VertexElementDescription("VTex", VertexElementFormat.Float2, VertexElementSemantic.TextureCoordinate)
            }
                               );

            var uniformDescriptions = new ResourceLayoutElementDescription[2][];

            uniformDescriptions[0] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("Factors", ResourceKind.UniformBuffer, ShaderStages.Fragment)
            };

            uniformDescriptions[1] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("Sampler", ResourceKind.TextureReadOnly, ShaderStages.Fragment),
                new ResourceLayoutElementDescription("Texture", ResourceKind.Sampler, ShaderStages.Fragment)
            };

            _shaderPackage = _shaderLoader.CreateShaderPackage("Vertex2D", AssetSourceEnum.Embedded, "ColourFragment", AssetSourceEnum.Embedded, vertexLayout, uniformDescriptions);
        }
예제 #2
0
        private void CreateShaders()
        {
            var vertexLayout = new VertexLayoutDescription
                               (
                16,
                0,
                new VertexElementDescription[]
            {
                new VertexElementDescription("Position", VertexElementFormat.Float2, VertexElementSemantic.Position),
                new VertexElementDescription("VTex", VertexElementFormat.Float2, VertexElementSemantic.TextureCoordinate)
            }
                               );

            var uniformDescriptions = new ResourceLayoutElementDescription[8][];

            uniformDescriptions[0] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("Sampler_Source", ResourceKind.TextureReadOnly, ShaderStages.Fragment),
                new ResourceLayoutElementDescription("Texture_Source", ResourceKind.Sampler, ShaderStages.Fragment)
            };

            uniformDescriptions[1] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("Sampler_Noise", ResourceKind.TextureReadOnly, ShaderStages.Fragment),
                new ResourceLayoutElementDescription("Texture_Noise", ResourceKind.Sampler, ShaderStages.Fragment)
            };

            uniformDescriptions[2] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("Sampler_ScanlineMask", ResourceKind.TextureReadOnly, ShaderStages.Fragment),
                new ResourceLayoutElementDescription("Texture_ScanlineMask", ResourceKind.Sampler, ShaderStages.Fragment)
            };

            uniformDescriptions[3] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("PixellateFactors", ResourceKind.UniformBuffer, ShaderStages.Fragment)
            };

            uniformDescriptions[4] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("EdgeDetectionFactors", ResourceKind.UniformBuffer, ShaderStages.Fragment)
            };

            uniformDescriptions[5] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("StaticFactors", ResourceKind.UniformBuffer, ShaderStages.Fragment)
            };

            uniformDescriptions[6] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("OldMovieFactors", ResourceKind.UniformBuffer, ShaderStages.Fragment)
            };

            uniformDescriptions[7] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("CrtEffectFactors", ResourceKind.UniformBuffer, ShaderStages.Fragment)
            };

            _shaderPackage = _shaderLoader.CreateShaderPackage("Vertex2D", AssetSourceEnum.Embedded, "StyleFragment", AssetSourceEnum.Embedded, vertexLayout, uniformDescriptions);
        }
예제 #3
0
        private void CreateShadersAndFactorsUniform()
        {
            var vertexLayout = new VertexLayoutDescription
                               (
                16,
                0,
                new VertexElementDescription[]
            {
                new VertexElementDescription("Position", VertexElementFormat.Float2, VertexElementSemantic.Position),
                new VertexElementDescription("VTex", VertexElementFormat.Float2, VertexElementSemantic.TextureCoordinate)
            }
                               );

            var uniformDescriptions = new ResourceLayoutElementDescription[3][];

            uniformDescriptions[0] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("UniformBlock", ResourceKind.UniformBuffer, ShaderStages.Fragment)
            };

            uniformDescriptions[1] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("Sampler_Source", ResourceKind.TextureReadOnly, ShaderStages.Fragment),
                new ResourceLayoutElementDescription("Texture_Source", ResourceKind.Sampler, ShaderStages.Fragment)
            };

            uniformDescriptions[2] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("Sampler_Processed", ResourceKind.TextureReadOnly, ShaderStages.Fragment),
                new ResourceLayoutElementDescription("Texture_Processed", ResourceKind.Sampler, ShaderStages.Fragment)
            };

            _shaderPackage = _shaderLoader.CreateShaderPackage("Vertex2D", AssetSourceEnum.Embedded, "BloomMixFragment", AssetSourceEnum.Embedded, vertexLayout, uniformDescriptions);

            var uniformBlockResourceLayoutDescription = uniformDescriptions[0][0];

            _uniformBlockBuffer = _systemComponents.Factory.CreateBuffer(new BufferDescription(MixingShaderFactors.SizeInBytes, BufferUsage.UniformBuffer | BufferUsage.Dynamic));

            var uniformBlockResourceLayout = _systemComponents.Factory.CreateResourceLayout(
                new ResourceLayoutDescription(
                    uniformBlockResourceLayoutDescription
                    )
                );

            _uniformBlockResourceSet = _systemComponents.Factory.CreateResourceSet(
                new ResourceSetDescription(uniformBlockResourceLayout, _uniformBlockBuffer)
                );
        }
예제 #4
0
        private void CreateShadersAndFactorsUniform()
        {
            var vertexLayout = new VertexLayoutDescription
                               (
                16,
                0,
                new VertexElementDescription[] {
                new VertexElementDescription("Position", VertexElementFormat.Float2, VertexElementSemantic.Position),
                new VertexElementDescription("VTex", VertexElementFormat.Float2, VertexElementSemantic.TextureCoordinate)
            }
                               );

            var uniformDescriptions = new ResourceLayoutElementDescription[3][];

            uniformDescriptions[0] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("DistortionFactor", ResourceKind.UniformBuffer, ShaderStages.Fragment)
            };

            uniformDescriptions[1] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("SamplerGradientMap", ResourceKind.TextureReadOnly, ShaderStages.Fragment),
                new ResourceLayoutElementDescription("TextureGradientMap", ResourceKind.Sampler, ShaderStages.Fragment)
            };

            uniformDescriptions[2] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("SamplerImage", ResourceKind.TextureReadOnly, ShaderStages.Fragment),
                new ResourceLayoutElementDescription("TextureImage", ResourceKind.Sampler, ShaderStages.Fragment)
            };

            _shaderPackage = _shaderLoader.CreateShaderPackage("Vertex2D", AssetSourceEnum.Embedded, "DistortionFragment", AssetSourceEnum.Embedded, vertexLayout, uniformDescriptions);

            _distortionFactorBuffer = _systemComponents.Factory.CreateBuffer(new BufferDescription(DistortionFactorUniform.SizeInBytes, BufferUsage.UniformBuffer | BufferUsage.Dynamic));

            var distortionFactorBufferResourceLayout = _systemComponents.Factory.CreateResourceLayout(
                new ResourceLayoutDescription(
                    uniformDescriptions[0]
                    )
                );

            _distortionFactorUniformResourceSet = _systemComponents.Factory.CreateResourceSet(
                new ResourceSetDescription(distortionFactorBufferResourceLayout, _distortionFactorBuffer)
                );
        }
예제 #5
0
        private void CreateShaders()
        {
            var vertexLayout = new VertexLayoutDescription
                               (
                32,
                0,
                new VertexElementDescription[] {
                new VertexElementDescription("VertPosition", VertexElementFormat.Float3, VertexElementSemantic.Position),
                new VertexElementDescription("VertNormal", VertexElementFormat.Float3, VertexElementSemantic.Normal),
                new VertexElementDescription("VertTexCoord", VertexElementFormat.Float2, VertexElementSemantic.TextureCoordinate)
            }
                               );

            var uniformDescriptions = new ResourceLayoutElementDescription[5][];

            uniformDescriptions[0] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("VertexUniforms", ResourceKind.UniformBuffer, ShaderStages.Vertex)
            };

            uniformDescriptions[1] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("FragUniforms", ResourceKind.UniformBuffer, ShaderStages.Fragment)
            };

            uniformDescriptions[2] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("Texture", ResourceKind.TextureReadOnly, ShaderStages.Fragment),
                new ResourceLayoutElementDescription("Sampler", ResourceKind.Sampler, ShaderStages.Fragment)
            };

            uniformDescriptions[3] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("LightProperties", ResourceKind.UniformBuffer, ShaderStages.Fragment)
            };

            uniformDescriptions[4] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("LightsUniformBlock", ResourceKind.UniformBuffer, ShaderStages.Fragment)
            };

            _shaderPackage = _shaderLoader.CreateShaderPackage("Vertex3D", AssetSourceEnum.Embedded, "MeshFragment", AssetSourceEnum.Embedded, vertexLayout, uniformDescriptions);
        }
예제 #6
0
        private void CreateShaders()
        {
            var vertexLayout = new VertexLayoutDescription
                               (
                56,
                0,
                new VertexElementDescription[] {
                new VertexElementDescription("isWorld", VertexElementFormat.UInt1, VertexElementSemantic.TextureCoordinate),
                new VertexElementDescription("TexuringType", VertexElementFormat.UInt1, VertexElementSemantic.TextureCoordinate),
                new VertexElementDescription("Position", VertexElementFormat.Float3, VertexElementSemantic.Position),
                new VertexElementDescription("Color", VertexElementFormat.Float4, VertexElementSemantic.Color),
                new VertexElementDescription("TexCoord0", VertexElementFormat.Float2, VertexElementSemantic.TextureCoordinate),
                new VertexElementDescription("TexCoord1", VertexElementFormat.Float2, VertexElementSemantic.TextureCoordinate),
                new VertexElementDescription("TexWeight0", VertexElementFormat.Float1, VertexElementSemantic.TextureCoordinate)
            }
                               );

            var uniformDescriptions = new ResourceLayoutElementDescription[3][];

            //Thes resource layouts will match those that are used to create the resouce sets for the camera matrices and textures.
            //It may be useful to feed a fixed version to both higher up. Also, I am assuming the string label means nothing as
            //For textures they can be either 0 or 1.. anyway, i'm sure i get headaches later when using different graphics api backends

            uniformDescriptions[0] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("WorldViewProjection", ResourceKind.UniformBuffer, ShaderStages.Vertex)
            };

            uniformDescriptions[1] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("texSampler0", ResourceKind.TextureReadOnly, ShaderStages.Fragment),
                new ResourceLayoutElementDescription("tex0", ResourceKind.Sampler, ShaderStages.Fragment)
            };

            uniformDescriptions[2] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("texSampler1", ResourceKind.TextureReadOnly, ShaderStages.Fragment),
                new ResourceLayoutElementDescription("tex1", ResourceKind.Sampler, ShaderStages.Fragment)
            };

            _shaderPackage = _shaderLoader.CreateShaderPackage("DrawingVertex", AssetSourceEnum.Embedded, "DrawingFragment", AssetSourceEnum.Embedded, vertexLayout, uniformDescriptions);
        }
예제 #7
0
        private void CreateShaders()
        {
            var vertexLayout = new VertexLayoutDescription
                               (
                56,
                0,
                new VertexElementDescription[] {
                new VertexElementDescription("isWorld", VertexElementFormat.UInt1, VertexElementSemantic.TextureCoordinate),
                new VertexElementDescription("TexuringType", VertexElementFormat.UInt1, VertexElementSemantic.TextureCoordinate),
                new VertexElementDescription("Position", VertexElementFormat.Float3, VertexElementSemantic.Position),
                new VertexElementDescription("Color", VertexElementFormat.Float4, VertexElementSemantic.Color),
                new VertexElementDescription("TexCoord0", VertexElementFormat.Float2, VertexElementSemantic.TextureCoordinate),
                new VertexElementDescription("TexCoord1", VertexElementFormat.Float2, VertexElementSemantic.TextureCoordinate),
                new VertexElementDescription("TexWeight0", VertexElementFormat.Float1, VertexElementSemantic.TextureCoordinate)
            }
                               );

            var uniformDescriptions = new ResourceLayoutElementDescription[3][];

            uniformDescriptions[0] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("WorldViewProjection", ResourceKind.UniformBuffer, ShaderStages.Vertex)
            };

            uniformDescriptions[1] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("texSampler0", ResourceKind.TextureReadOnly, ShaderStages.Fragment),
                new ResourceLayoutElementDescription("tex0", ResourceKind.Sampler, ShaderStages.Fragment)
            };

            uniformDescriptions[2] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("texSampler1", ResourceKind.TextureReadOnly, ShaderStages.Fragment),
                new ResourceLayoutElementDescription("tex1", ResourceKind.Sampler, ShaderStages.Fragment)
            };

            _shaderPackage = _shaderLoader.CreateShaderPackage("DrawingVertex", AssetSourceEnum.Embedded, "DistortionHeightFragment", AssetSourceEnum.Embedded, vertexLayout, uniformDescriptions);
        }
예제 #8
0
        private void CreateShadersAndBuffer()
        {
            var vertexLayout = new VertexLayoutDescription
                               (
                16,
                0,
                new VertexElementDescription[]
            {
                new VertexElementDescription("Position", VertexElementFormat.Float2, VertexElementSemantic.Position),
                new VertexElementDescription("VTex", VertexElementFormat.Float2, VertexElementSemantic.TextureCoordinate)
            }
                               );

            var uniformDescriptions = new ResourceLayoutElementDescription[6][];

            uniformDescriptions[0] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("MixFactors", ResourceKind.UniformBuffer, ShaderStages.Fragment)
            };

            uniformDescriptions[1] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("SamplerMix", ResourceKind.TextureReadOnly, ShaderStages.Fragment),
                new ResourceLayoutElementDescription("TextureMix", ResourceKind.Sampler, ShaderStages.Fragment)
            };

            uniformDescriptions[2] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("Sampler0", ResourceKind.TextureReadOnly, ShaderStages.Fragment),
                new ResourceLayoutElementDescription("Texture0", ResourceKind.Sampler, ShaderStages.Fragment)
            };

            uniformDescriptions[3] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("Sampler1", ResourceKind.TextureReadOnly, ShaderStages.Fragment),
                new ResourceLayoutElementDescription("Texture1", ResourceKind.Sampler, ShaderStages.Fragment)
            };

            uniformDescriptions[4] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("Sampler2", ResourceKind.TextureReadOnly, ShaderStages.Fragment),
                new ResourceLayoutElementDescription("Texture2", ResourceKind.Sampler, ShaderStages.Fragment)
            };

            uniformDescriptions[5] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("Sampler3", ResourceKind.TextureReadOnly, ShaderStages.Fragment),
                new ResourceLayoutElementDescription("Texture3", ResourceKind.Sampler, ShaderStages.Fragment)
            };

            _shaderPackage = _shaderLoader.CreateShaderPackage("Vertex2D", AssetSourceEnum.Embedded, "MixFragment", AssetSourceEnum.Embedded, vertexLayout, uniformDescriptions);

            _mixFactorsBuffer = _systemComponents.Factory.CreateBuffer(new BufferDescription(MixStageFactors.SizeInBytes, BufferUsage.UniformBuffer | BufferUsage.Dynamic));

            var resourceLayout = _systemComponents.Factory.CreateResourceLayout(
                new ResourceLayoutDescription(
                    uniformDescriptions[0]
                    )
                );

            _mixFactorsResource = _systemComponents.Factory.CreateResourceSet(
                new ResourceSetDescription(resourceLayout, _mixFactorsBuffer)
                );
        }
        private void CreateShadersAndFactorsUniform()
        {
            var vertexLayout = new VertexLayoutDescription
                               (
                16,
                0,
                new VertexElementDescription[]
            {
                new VertexElementDescription("Position", VertexElementFormat.Float2, VertexElementSemantic.Position),
                new VertexElementDescription("VTex", VertexElementFormat.Float2, VertexElementSemantic.TextureCoordinate)
            }
                               );

            var uniformDescriptions = new ResourceLayoutElementDescription[3][];

            uniformDescriptions[0] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("Sampler", ResourceKind.TextureReadOnly, ShaderStages.Fragment),
                new ResourceLayoutElementDescription("Texture", ResourceKind.Sampler, ShaderStages.Fragment)
            };

            uniformDescriptions[1] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("LinearSampledGaussianUniforms", ResourceKind.UniformBuffer, ShaderStages.Fragment)
            };

            uniformDescriptions[2] = new ResourceLayoutElementDescription[]
            {
                new ResourceLayoutElementDescription("WeightsAndOffsets", ResourceKind.UniformBuffer, ShaderStages.Fragment)
            };

            _shaderPackage = _shaderLoader.CreateShaderPackage("Vertex2D", AssetSourceEnum.Embedded, "LinearFilterGaussianBlur1DFragment", AssetSourceEnum.Embedded, vertexLayout, uniformDescriptions);

            var gaussianUniformBlockResourceLayoutDescription = uniformDescriptions[1][0];

            _gaussianFactorsUniformBlockBuffer = _systemComponents.Factory.CreateBuffer(new BufferDescription(GaussianBlurFactors.SizeInBytes, BufferUsage.UniformBuffer | BufferUsage.Dynamic));

            var gaussianFactorsResourceLayout = _systemComponents.Factory.CreateResourceLayout(
                new ResourceLayoutDescription(
                    gaussianUniformBlockResourceLayoutDescription
                    )
                );

            _gaussianFactorsUniformBlockResourceSet = _systemComponents.Factory.CreateResourceSet(
                new ResourceSetDescription(gaussianFactorsResourceLayout, _gaussianFactorsUniformBlockBuffer)
                );

            var weightsAndOffsetsResourceLayoutDescription = uniformDescriptions[2][0];

            _weightsAndOffsetsDeviceBuffer = _systemComponents.Factory.CreateBuffer(new BufferDescription((uint)_gaussianWeightsAndOffsetsCache.WeightsAndOffsetsArraySize * GaussianBlurArrayComponent.SizeInBytes, BufferUsage.UniformBuffer | BufferUsage.Dynamic));

            var weightsAndOffsetsResourceLayoutFactors = _systemComponents.Factory.CreateResourceLayout(
                new ResourceLayoutDescription(
                    weightsAndOffsetsResourceLayoutDescription
                    )
                );

            _weightsAndOffsetsResourceSet = _systemComponents.Factory.CreateResourceSet(
                new ResourceSetDescription(weightsAndOffsetsResourceLayoutFactors, _weightsAndOffsetsDeviceBuffer)
                );
        }
예제 #10
0
        private void CreateShaders()
        {
            //Vertex layout is the same for all custom shaders
            var vertexLayout = new VertexLayoutDescription
                               (
                16,
                0,
                new VertexElementDescription[]
            {
                new VertexElementDescription("Position", VertexElementFormat.Float2, VertexElementSemantic.Position),
                new VertexElementDescription("VTex", VertexElementFormat.Float2, VertexElementSemantic.TextureCoordinate)
            }
                               );

            //Build up the uniform descriptions & create buffers where required
            var uniformDescriptions = new List <ResourceLayoutElementDescription[]>();

            var numUniforms = _userUniformDescriptions.Length;

            var textureCount = 0;

            for (var n = 0; n < numUniforms; n++)
            {
                var desc = _userUniformDescriptions[n];

                switch (desc.UniformType)
                {
                case ShaderUniformType.Texture:
                    if (textureCount >= 4)
                    {
                        _frameworkMessenger.Report("Customer Shader has more than 4 textures, not currently allowed, skipping uniform");
                        continue;
                    }
                    textureCount++;

                    uniformDescriptions.Add(
                        new ResourceLayoutElementDescription[]
                    {
                        new ResourceLayoutElementDescription(string.Concat("Sampler_", desc.Name), ResourceKind.TextureReadOnly, ShaderStages.Fragment),
                        new ResourceLayoutElementDescription(string.Concat("Texture_", desc.Name), ResourceKind.Sampler, ShaderStages.Fragment)
                    }
                        );
                    break;

                case ShaderUniformType.Data:
                    var description = new ResourceLayoutElementDescription[]
                    {
                        new ResourceLayoutElementDescription(desc.Name, ResourceKind.UniformBuffer, ShaderStages.Fragment)
                    };
                    uniformDescriptions.Add(description);
                    var buffer = CreateUniformBuffer(description, desc);
                    _uniformBuffers[n] = buffer;
                    _uniformBufferNameLookup.Add(desc.Name, n);
                    break;
                }
            }

            var vertexShaderFileName = "Vertex2D";

            if (_useSpirvCompile)
            {
                //Different Vertex Shaders account for differences in backend (incl. Texcoord origin)
                switch (_systemComponents.Device.BackendType)
                {
                case GraphicsApi.Direct3D11:
                case GraphicsApi.Metal:
                    vertexShaderFileName = "Vertex2D-TcTopLeft";
                    break;

                case GraphicsApi.Vulkan:
                case GraphicsApi.OpenGL:
                    vertexShaderFileName = "Vertex2D-TcBottomLeft";
                    break;

                case GraphicsApi.OpenGLES:
                case GraphicsApi.SystemDefault:
                    throw new Yak2DException("Type is either unsupported or erroneously stored as system default");
                }
            }

            _shaderPackage = _shaderLoader.CreateShaderPackage(vertexShaderFileName,
                                                               AssetSourceEnum.Embedded,
                                                               _fragmentShaderFilename,
                                                               _shaderFileAssetType,
                                                               vertexLayout,
                                                               uniformDescriptions.ToArray(),
                                                               _useSpirvCompile,
                                                               _useSpirvCompile);
        }