0
votes

So I am working on openGL ES2.0 and GLSL and I have a question about fragment shader. Through my vertex and fragment shader, I compute and get blended image. I however want to output differently. So for example, on my fragment shader, I have

vec4 image1 = texture2DProj(tex1,projCoord);
vec4 image2 = vec4(1.0,0.0,0.0,1.0); //red

I want to show my output (gl_FragColor) as image2, red color. But I want to find a way to also pass image1 to my openGL ES2.0 code. Is there anyway to do this?

I know that in regular openGL, (Not ES), you can do something like gl_FragData[n] and do frame buffer attachment and etc. In openGL ES2.0, I can only do gl_FragData[0], [1] will be out of index. Normally, in my case, gl_FragColor will be store whatever I have to frame buffer. So in this case, if I do

gl_FragColor = image2;

red color image will be store in frame buffer. I just want to show image2 but I want to access image1's frame buffer only. Is there anyway to do it?

1

1 Answers

1
votes

But I want to find a way to also pass image1 to my openGL ES2.0 code.

Your question is very confusing. You don't need to "pass" image1 anywhere; it's in your shader; that's where you computed it.

If you mean that you want to store it from one shader execution and then read it back in another, then you need to either have multiple render targets, or you need to split your shader and render to your separate render targets from different shaders. And since you're in OpenGL ES world, you generally don't have much freedom for MRTs.

So you need to take your data generation shader and split it so that one of them generates image1 and the other generates image2. You use the first shader to render to one render target and use another shader to render to the second.