1
votes

I want to do some rendering with webGL shader but I need to read an array of data which was generated by the shader from previous frame. I'm doing this with using the shader to write to a texture and read that texture with the same shader. However, this doesn't work. The shader can read the texture from the last frame and write to the frame buffer perfectly but it just can't write to the texture again. I also tried to copy the texture to other image unit but it doesn't work either. I'm wondering if there's any restriction on the texture of webGL that you can't do read/write in the same shader? or I did something wrong?

Thanks in advance, Yi

1

1 Answers

6
votes

From Common mistakes in http://www.opengl.org/wiki/GLSL_:_common_mistakes : "Normally, you should not sample a texture and render to that same texture at the same time. This would give you undefined behavior. It might work on some GPUs and with some driver version but not others."

Use instead two textures using the ping-pong approach (The following tutorial is OpenGL, but using the technique in WebGL should be straight forward):

http://www.mathematik.tu-dortmund.de/~goeddeke/gpgpu/oldstuff/HelloPingPong.pdf