Results 1 to 4 of 4

Thread: Shader "return value"

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2008
    Location
    france
    Posts
    26

    Shader "return value"

    Hi,

    I'm looking for a way to check, on the CPU, whether a fragment has met a certain condition or not.

    In other words, I would like a boolean which is true if and only if one or more fragment shader executions have done a special action.

    At the first glance I thought I could simply use a 1x1 texture, but I can't write to a texture which is not a RT ( can I ? )

    Another idea I've had is to use the histogram functionnality : since I don't really care about the real colors ( I'm doing some weird kind of GPGPU ) I could just have the fragment color to be red if the condition is met, and blue otherwise. But how fast is that ? Aren't they faster/simpler solution(s) ?

    Thanks !

  2. #2
    V-man
    Guest

    Re: Shader "return value"

    You can render your color to the framebuffer or a render_to_texture. You can make your window or render_to_texture 1x1 if you want.
    I've never used histogram so I can't say if it is fast or not.

  3. #3
    Senior Member OpenGL Pro Zengar's Avatar
    Join Date
    Sep 2001
    Location
    Germany
    Posts
    1,931

    Re: Shader "return value"

    Histrograms are not accelerated. Hovewer, you can write a shader that discards or accepts fragments based on the condition and then use the occlusion query.

  4. #4
    Junior Member Newbie
    Join Date
    Sep 2008
    Location
    france
    Posts
    26

    Re: Shader "return value"

    I had already thought about occlusion query but it is not an option since I'm already using it for other needs. ( I eventually couly render the scene twice and make 2 different queries ... )

    V-man : Will it really work ?
    I want a 512*512 buffer to tell me that one or more fragments have met the condition. If I render to a 1*1 texture, the fragment shader will be executed only once, won't it ?
    Moreover, shaders are supposed to write to gl_FragColor or they won't compile. But if a shader execution "outputs" 1, and then another one ouputs 0, the value will be cleared ...

    Another solution I've been thinking about it to render the condition value in another framebuffer ( 512*512 ) and then pass it to another shader that could shrink it to a 256*256, 128*128, ... 1*1 tex in several passes, each time taking the max of the four texel values.

    So, my three options seem to be :
    - use the histogram and parse it on the CPU
    - render my 2 __complex__ and often __huge__ VBOs twice, because I need 2 separate occlusion queries
    - Add another "boolean" render target, shrink it on the GPU, download it to the CPU.

    Do you have any idea would be the fastest ?

Similar Threads

  1. Switching between "arcball" and "fps-style" camera rotation
    By bsabiston in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 10-31-2017, 12:37 PM
  2. egl gles2 "function is no-op" "Mesa: User error"
    By unixmania in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-17-2013, 05:30 AM
  3. Replies: 1
    Last Post: 10-26-2012, 02:19 AM
  4. my "glMapBuffer" does not return pointer?
    By akashiraffee in forum OpenGL: Basic Coding
    Replies: 9
    Last Post: 12-20-2009, 07:26 AM
  5. JOGL: all gl method calls return "GL_INVALID_ENUM"
    By garydeng in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 06-12-2009, 02:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean