uniform float screenWidth; uniform float screenHeight; uniform sampler2D depthMap; uniform sampler2D rotateMap; uniform float zFar; uniform float zNear; uniform float radius; uniform float attBias; uniform float attScale; void main(void){ // With SSAO float att = 0.0; vec4 rndTable[8]; rndTable[0] = vec4 ( -0.5, -0.5, -0.5, 0.0 ); rndTable[1] = vec4 ( 0.5, -0.5, -0.5, 0.0 ); rndTable[2] = vec4 ( -0.5, 0.5, -0.5, 0.0 ); rndTable[3] = vec4 ( 0.5, 0.5, -0.5, 0.0 ); rndTable[4] = vec4 ( -0.5, -0.5, 0.5, 0.0 ); rndTable[5] = vec4 ( 0.5, -0.5, 0.5, 0.0 ); rndTable[6] = vec4 ( -0.5, 0.5, 0.5, 0.0 ); rndTable[7] = vec4 ( 0.5, 0.5, 0.5, 0.0 ); float zb = texture2D ( depthMap, vec2(gl_FragCoord.x/screenWidth, gl_FragCoord.y/screenHeight)).x; float z = zFar*zNear/(zb * (zFar - zNear) - zFar); vec3 plane = 2.0 * texture2D ( rotateMap, vec2(gl_FragCoord.x/4.0,gl_FragCoord.y/4.0)).xyz - vec3 ( 1.0 ); float mult = radius/z; vec2 texCoord = vec2(gl_FragCoord.x/screenWidth, gl_FragCoord.y/screenHeight); for ( int isample = 0; isample < 8; isample++ ) { //vec3 sample = reflect ( rndTable [isample].xyz, plane ); vec3 sample = rndTable [isample].xyz - 2.0 * dot(plane,rndTable [isample].xyz) * plane; float zSample = texture2D ( depthMap, texCoord + mult*sample.xy).x; zSample = zFar * zNear / (zSample * (zFar - zNear) - zFar ); //if ( zSample - z > 0.1 ) //continue; float dz = max ( zSample - z, 0.0 ) * 30.0; att += 1.0 / ( 1.0 + dz*dz ); } att = clamp ( (att / 8.0 + attBias) * attScale, 0.0, 1.0 ); gl_FragColor = vec4(att,att,att,1.0); }