Jump to content
Site Stability Read more... ×
  • Advertisement
Sign in to follow this  

Sampling a render target?

This topic is 2786 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.


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.

Share this post

Link to post
Share on other sites
Hello Aimee,

In XNA 4.0 the RenderTarget2D inherits from Texture2D, so you can just pass it to an effect like this:

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);


Share this post

Link to post
Share on other sites
Thanks, after your comment I realized I wasn't even passing the right target also lol, still learning!

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!