If I have a custom effect that define a texture sampler like this:
sampler2D MainTextureSampler = sampler_state {
Texture = (MainTexture);
MinFilter = Linear;
MagFilter = Linear;
AddressU = Clamp;
AddressV = Clamp;
};
How can I change the MinFilter / MagFilter / AddressU / AddressV params from C# code? I looked at all the options of SetValue() of shader parameters and didn’t find anything that match sampler state.
Thanks!
Sizaar
August 12, 2017, 7:16pm
2
Try using graphicsDevice.SamplerStates[n] = mySamplerState
, where n is the index of the sampler state in your shader.
1 Like
This only works for default effects… Not what I posted above.
Edit: never-mind I just realized I can create the sampler state without params, eg like this:
sampler2D MainTextureSampler = sampler_state { Texture = (MainTexture); }
And in this case it works. Thanks!
Sizaar
August 12, 2017, 7:24pm
4
This works for all shaders, just use the SamplerState like this:
SamplerState mySamplerState = new SamplerState()
{
AddressU = TextureAddressMode.Wrap,
AddressV = TextureAddressMode.Wrap,
Filter = TextureFilter.LinearMipPoint
}
You can use e.g. SamplerComparisonState defined this way for your shadow maps etc.