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 4 of 4

Thread: Screen space ambient occlusion

  1. #1
    Intern Contributor
    Join Date
    Jun 2011
    Posts
    82

    Unhappy Screen space ambient occlusion

    I am reading someone's code about SSAO, but there are some places I cannot understand.

    Their code for SSAO is extremely simple:

    Code :
    uniform vec4 fk3f[32];
    uniform vec4 fres;
    uniform sampler2D tex0; // the depth map
    uniform sampler2D tex1; // a small random normal map
     
     
    void main(void)
    {
        vec4 zbu = texture2D( tex0, gl_Color.xy ); //gl_Color the 2d pixel coordinates
     
     
        vec3 ep = zbu.x*gl_TexCoord[0].xyz/gl_TexCoord[0].z;//gl_TexCoord[0] contains the eye view vector
     
     
        vec4 pl = texture2D( tex1, gl_Color.xy*fres.xy );
        pl = pl*2.0 - vec4(1.0);
     
     
        float bl = 0.0;
        for( int i=0; i<32; i++ )
        {
            vec3 se = ep + rad*reflect(fk3f[i].xyz,pl.xyz);
     
     
            vec2 ss = (se.xy/se.z)*vec2(.75,1.0);
            vec2 sn = ss*.5 + vec2(.5);
            vec4 sz = texture2D(tex0,sn);
     
     
            float zd = 50.0*max( se.z-sz.x, 0.0 );
            bl += 1.0/(1.0+zd*zd);
       }
       gl_FragColor = vec4(bl/32.0);
    }

    The author says the following code is for transforming points from eye space to clip space:
    Code :
    vec2 ss = (se.xy/se.z)*vec2(.75,1.0);
    What's the mathematic behind this? The coefficient 0.75 looks strange to me.

    In addition, the author uses a per pixel random plane to do a reflection on the sampling point around the shading point. But how does the random plane work? the sampling points are already random, is it really necessary to reflect them to be more random?

    The original article containing the code can be found at
    http://www.iquilezles.org/www/articles/ssao/ssao.htm

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,655
    I guess the 0.75 on x is to adapt a power of two texture to a 16/10 screen ratio. Mmh no scratch that, it would be 0.625 instead, so I have no clue.

    The random plane is needed, as the sampling points are absolutely not random but aligned with the screen pixels.

  3. #3
    Junior Member Newbie
    Join Date
    May 2010
    Posts
    28
    Quote Originally Posted by ZbuffeR View Post
    I guess the 0.75 on x is to adapt a power of two texture to a 16/10 screen ratio..
    But maybe a 4/3 ratio...

  4. #4
    Intern Contributor
    Join Date
    Jun 2011
    Posts
    82
    Do you know what does the uniform fres do in this line:
    Code :
    vec4 pl = texture2D( tex1, gl_Color.xy*fres.xy );

Posting Permissions

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