Loop through an ID3D11Texture2D object

Started by
1 comment, last by iedoc 12 years, 1 month ago
I would like to know how to iterate through the texels of an ID3D11Texture2D object, so i can do an operation that replaces certain texels with that of another ID3D11Texture2D object.

What i'm really looking for is how to set every other pixel on the screen to one texture, and all the other pixels to the other texture. I thought the pixel shader would be a great place to do this, by setting every other pixel's alpha value to 0 from the first render target, and in the second render target set the other pixels alpha's to 0. but as far as i know you can't find the current pixel the pixel shader is working on, and you can't share data between iterations. I'm not looking for blending though, because i don't want the pixels to "bleed" onto the surrounding pixels.
Advertisement
I'm a little confused on what your intended result should be...so have texture A and texture B, and you want to fill texture A with an interleaved mix of texture A and texture B pixels? If that's the case that should be really easy...just bind texture A as the render target, use SV_Position to get the pixel position being shaded, and based on that position you can conditionally call discard to not write to that pixel (or you can use an alpha value of 0, and enable alpha blending). Then if you don't discard, you can just sample the corresponding texel from texture B and output that value. Or if you wanted the result in texture C, you could just just sample both and pick which sample you want to use based on the pixel position.
That's exactly what i was looking for, thanks mjp. I had looked for a really long time but couldn't find how to get the pixel position (I didn't know SV_Position could be used in the pixel shader, I just thought that was only used to send the vertex position from the vs to the rs, but now that i'm thinking about it, I have come across using SV_Position in the pixel shader! just needed a refresher i suppose, haha). I know the operation i want to do is real simple, i just didn't know how to actually find the pixel position (i'm really not good with hlsl). thanks again

This topic is closed to new replies.

Advertisement