How to use texture in custom shader ? Please help


#1

I spended several hours in attempts to set texture to custom shader on XLSL… Looks like Xenko completely lack the possibility to transfer texture into custom shader… Somebody explain me why and how to make it correctly ? The code below compiles correctly but fail execution at runtime…

shader TextureColor<Texture2D myTexture> : ComputeColor, Texturing
{
    override float4 Compute()
    {
        return myTexture.Sample(LinearSampler, streams.TexCoord);
    }
};  

neither

shader TextureColor<Texture2D myTexture> : ComputeColorTexture<myTexture, TEXCOORD0>
{
    override float4 Compute()
    {
        return base.Compute();
    }
};

#2

Ok, looks like im not alone with this problem - I created a new issue on Github - https://github.com/SiliconStudio/xenko/issues/631


#3

Well that seems to work ^
However, it requires an extra script, which isn’t optimal.

If you wish to create a shader where you can set a texture in the game studio, the following code should work:

shader TextureShader: ComputeColor
    {
        //Not necessarily a texture, it can also be a different shader, a color, etc.
        compose ComputeColor MatrixTexture; 

        override float4 Compute()
        {
            return MatrixTexture.Compute();
        }
    };