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.
Sampling a render target?
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).
And that’s how you fetch from it in the pixel shader.
Cheers!
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!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement