Parameter storage in fragment shader
I want to do edge-detection and get the max or min x position of those edges in fragment shader. There seems no problem on edge detection, but Iím blocked on how to storage parameter calculated by the previous fragment and then used by the next fragment. Does anyone have an idea about parameter storage calculated by the previous fragment and used by the next one in fragment shader, thx a lot in advance!
If you mean in the same render pass you basically can't because they are calculated in parallel. If you mean in sucessive render passes you can by feeding the output from the last render pass as a texture to the new render pass.
It seems not clear enough for me. Let's take an example:
Originally Posted by tonyo_au
task: a texture contains a circle, we need to get the max and min x coordination of the circle;
1. first rendering: detect the edge of the circle, feed the output with the position of the edges;
2. second rendering: the input texture is feed by the position of the edges. But I can't still figure out how to get the min and max x coordinate of the circle. Could you give me a hint? thx!
I don't know an algorithm for your second step. I thought you had one but didn't know how to access the fragments. It doesn't sound like a job for OpenGL. You could fetch the texture from the first step into a cpu memory buffer and scan from left to right looking for a set pixel. Then you can feed the min/max values to a fragment shader as uniforms. Of course this same scan logic can be done on a fragment shader with texel fetches but that sounds like a very bad idea.
Because of the limitation of bus bandwidth in my application, I’m not allowed to map the texture to CPU to do such a job.
Fragment shader is processed in parallel. If there is no way to share data dynamically, it seems impossible to do the job the second step mentioned above.
If I’m wrong, please correct me.