Hi,
if I have a filled texture and want to read and write this texture within the same shader, could that cause problems with some graphic cards?
Best,
Andreas
You can't read from a texture in the same shader that writes to it. There are no guarantees what executes first, so the result is undefined. I suggest you write to another texture instead and then execute the shader on that texture how many times are needed in order to get the desired effect.
Thank you! Can you tell me why? Which mechanism of the graphic card would cause this undefined result?
Best,
Andreas
I won't go into specifics but consider that the video card is a SIMD machine (e.g parallel processor). It takes your shader and runs it on all pixels simultaneously, you can't know if the pixel you're reading has been written to or not. In addition to that I believe you will get a hardware error if you try to do that as the video card might reserve the render target texture as write-only memory or something during the rasterization stage (where the pixel shader runs).
Writing to a texture using TextureRenderer while having this texture in the TextureState of the rendered quad, I got no error. At my ati card, the image was displayed correctly. But, nvidia users told me about problems. Also there were no exceptions. Thx, again and I took your advice.