Hello,
I have experience with graphics programming, but for the love of god I can’t manage to perform a simple texture sample in a custom shader.
Has anyone already managed to perform a texture sample (with a most recent version of Xenko) ?
There seem to be a few posts about it already on this forum but between now and 2015 it seems that Xenko had major rendering changes…
Below is my code, I would like to precise that I managed to get it working passing a simple color value from CPU instead of sampling a texture.
Also, I have check the texture dimensions in the shader for debug and I always get 0…
**** Please only answer if you managed yourself to sample a texture in a recent version of Xenko****
Thanks in advance.
//***** Material creation *****//
var material = Material.New(m_graphicsDevice, new MaterialDescriptor
{
Attributes =
{
Emissive = new MaterialEmissiveMapFeature(new SiliconStudio.Xenko.Rendering.Materials.ComputeColors.ComputeShaderClassColor() { MixinReference = "SimpleTexture" }),
}
});
...
material.Parameters.Set(SimpleTextureKeys.MyTexture, myTexture);
modelComponent.Model.Materials.Add(material);
//***** Shader code *****//
shader SimpleTexture: ComputeColor
{
stage stream float2 TexCoord : TEXCOORD0;
SamplerState MySampler
{
Filter = ANISOTROPIC;
AddressU = Wrap;
AddressV = Wrap;
MaxAnisotropy = 16;
};
// Tried with and without cbuffer
//Texture2D MyTexture;
cbuffer PerMaterial
{
Texture2D MyTexture;
}
override float4 Compute()
{
// Tried reading the tex dimensions for debug... always return null
//float w;
//float h;
//MyTexture.GetDimensions(w, h);
//if(w == 0) discard;
return MyTexture.Sample(MySampler, streams.TexCoord);
}
};