The scenario is: I have a texture A. There are 3 loops. Each loop writes a channel into the texture A. After the 3 loops, all 3 channels in A are updated.
The shader is like:
vec3 tmpVec3 = texture(inputTexture0, vUV).rgb; // inputTexture0 is texture A tmpVec3[channelIndex_P] = texture(inputTexture1, vUV).r; // write one channel from inputTexture1
color = vec4(tmpVec3, 1.0);
It render to texture A, that is inputTexture0. In this way by rendering and sampling the same texture, I can save memory by one texture.
However, the result is not desired.
I read the article "Sampling and Rendering to the Same Texture". It says:
"Meaning it may do what you want, the sampler may get old data, the sampler may get half old and half new data, or it may get garbage data. Any of these are possible outcomes."
But since the writing data of the specific pixel always happens after getting data of the specific pixel, why is it not possible?
Another article "Sampling from and rendering to the same texture and parallel sorting / hashing" It says:
"But if the result in every framebuffer pixel would be the value of one of the fragments which wrote to that pixel and not a combination of values from multiple fragments, this functionality would still be useful for parallel sorting / hashing algorithms implemented in glsl."
I do not understand the above words. Does it say under some situations "sampling and rendering to the same texture" can be used and have defined result. Then how to do it? How to solve my current situation, since I want to save one texture variable.