Sampling a render target?

Started by
1 comment, last by AmzBee 12 years, 1 month ago
Does anyone know if it's possible to sample a render target within a pixel shader in XNA 4. Bit of an odd-ball question
I know, but I'm playing round with a few ideas at the moment, and knowing the answer to this would help me quite a lot.

Aimee.

Edit: also, i thought i'd be smart by passing the target texture as a parameter earlier today to my shader, but realized
quite quickly (with a big exception being thrown) that it's not possible that way.

We are now on Tumblr, so please come and check out our site!

http://xpod-games.com

Advertisement
Hello Aimee,

In XNA 4.0 the RenderTarget2D inherits from Texture2D, so you can just pass it to an effect like this:
myEffect.Parameters[“myTexture”].SetValue(myRenderTarget);

In the shader code you need a sampler to read from it (a sampler defines how the texture is filtered).
texture myTexture;
sampler2D PointSampler = sampler_state {
Texture = < myTexture >;
MinFilter = Point;
MagFilter = Point;
MipFilter = Linear;
AddressU = CLAMP;
AddressV = CLAMP;
};


And that’s how you fetch from it in the pixel shader.
float4 color = tex2D(PointSampler, texCoord);

Cheers!
Thanks, after your comment I realized I wasn't even passing the right target also lol, still learning!

We are now on Tumblr, so please come and check out our site!

http://xpod-games.com

This topic is closed to new replies.

Advertisement