Stride Forums Archive

How to use texture in custom shader ? Please help

3 posts, 1949 views, 2017-09-29 to 2018-02-24

Taurus 2017-09-29 #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();
    }
};
Taurus 2017-09-29 #2

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

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();
        }
    };