Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Parameter storage in fragment shader

  1. #1
    Junior Member Newbie
    Join Date
    May 2012
    Posts
    10

    Parameter storage in fragment shader

    Hi all,

    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!

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    723
    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.

  3. #3
    Junior Member Newbie
    Join Date
    May 2012
    Posts
    10
    Quote Originally Posted by tonyo_au View Post
    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:
    task: a texture contains a circle, we need to get the max and min x coordination of the circle;

    method: multi-rendering
    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!

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    723
    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.

  5. #5
    Junior Member Newbie
    Join Date
    May 2012
    Posts
    10
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •