spritebatch draw texture with effect?

how to draw spritebatch texture with custom effect?

Take a look at my post processing framework here.

But simply:-

spriteBatch.Begin(SortMode, Blend, Sampler, DepthStencilState.None, RasterizerState.CullCounterClockwise);
spriteBatch.Draw(BackBuffer, new Rectangle(0, 0, Game.GraphicsDevice.Viewport.Width, Game.GraphicsDevice.Viewport.Height), Color.White);

You can also pass the effect in Begin:
spriteBatch.Begin(DeferredMode, Blend, LinearWrap, DepthNone, RasterState, tree_fx);
Regular texture is passed by draw call and additional textures would be added by passing as a parameter.
Custom Shader Texture declaration may depend on Shader Model being used.

Texture2D<float4> Texture : register(t0);  // <-- t1 for texture 2,   t2 for tex 3, t3, etc...
sampler TextureSampler : register(s0)     // <--s1 for sampler 2, s2, s3, etc...
	Texture = <Texture>;  // <Texture> passed as parameter for second texture if using
	AddressU = clamp;
	AddressV = clamp;
	MinFilter = linear;
	MagFilter = linear;	

It’ll keep the regular SpriteEffect.fx vertex shader if you only replace the pixel shader. Likewise you could give it only the vertex shader or could switch out both in the fx.

1 Like

I usually just have this actually (without the other stuff):

sampler TexSampler : register(s0)
	Texture = <Texture>;
	AddressU = clamp;// wrap;
	AddressV = clamp;// wrap;

	Filter = linear;

and then use col = tex2D(TexSampler, tex_coord);