Say I have these two variables in my shader:
HLSL
texture ModelTexture;
sampler2D TextureSampler
And this is how I would set the texture:
C#
myEffect.Parameters["ModelTexture"].SetValue(woodTexture);
What do about the sampler? There's no EffectParameter.SetValue(SamplerState)
overload but I want to change filters in runtime. How do I go about it?
I'm pretty sure the rest of the code is OK, because if I initialize TextureSampler
directly in HLSL it properly draws textured objects.
Edit:
I've tried setting a SamplerState object in the GraphicsDevice.
C#
GraphicsDevice.SamplerStates[0] = new SamplerState { Filter = TextureFilter.Linear };
HLSL
sampler2D TextureSampler : register(s0);
Now texture assignment (see the 2nd snippet) throws NullReferenceException
.
I've also tried setting the texture like above instead of via EffectParameter
:
C#
GraphicsDevice.Textures[0] = woodTexture;
HLSL
texture ModelTexture : register(t0);
The program compiles and runs but the texture is not loaded (rendered object is black).