December 13, 2011

SSAO shader update v1.2

changes since 1.0:
• v1.2 - added fog calculation to mask AO. Some minor fixes.
• v1.1 - replaced rings sampling with new spiral sampling method. Taken from HERE

fragment shader HERE
blend HERE


  1. hey man looks awesome, keep up the good work!! the only problem I have is it also put ao on my skybox...

  2. Hi, may I ask you some questions about your algorithm? What does it mean on

    1. #define DL 2.399963229728653", // PI * ( 3.0 - sqrt( 5.0 ) )
    I have no idea why you use parameter 3, 5.

    2. cameraCoef / ( cameraFarPlusNear - unpackDepth( texture2D( tDepth, coord ) ) * cameraFarMinusNear );
    I understand unpackDepth( texture2D( tDepth, coord ) ) * cameraFarMinusNear would compute the world-view depth value, because clip space depth value is from 0.0 to 1.0 by starting from near plane to far plane. but I have no idea you need to use cameraCoef and cameraFarPlusNear.


    1. Hey,
      1. that part nicely calculates spiral alignment of samples. Made by far wiser people than myself. Got it from here (look in Spirals section):

      2. I am linearizing an exponential depth value there. I guess that is what unpackDepth thingy does.

    2. Thanks for your sharing, Martins.
      I understand it totally. You are so great, you really do a nice job.