PDA

View Full Version : Sample MRT Texture and Write to its attachment?



Swoop
12-16-2008, 12:23 AM
Im thinking this cant be done, but before I go write a bunch of stuff that wont work I wanna see if this idea is completely off the wall.
I have three textures generated using a FBO,
gl_FragData[0] = position,
gl_FragData[1] = normal,
gl_FragData[2] = diffuse,
Is it possible to sample the diffuse texture in a shader, and write back to the color attachment (gl_FragData[2]) that sampled texture is on? Which would seem like a read/write kinda loop, write to it in an initial fill, sample it (read) in a shader (change it), and then put the color back in the same target.

babis
12-16-2008, 01:42 AM
Better forget it,because most of the time the result is undefined. Just keep 2 copies of each RT you want to R/W, & ping-pong between them.

zeoverlord
12-16-2008, 03:04 AM
You can't have a texture bound for sampling at the same time as it's bound as a color buffer, so the answer would be no.
You could use two textures and alternate between them, or find a way to do it in one pass.

Swoop
12-16-2008, 11:51 AM
Yeah, seemed like a stretch, thx.