it's not blurred or anything yet just trying to get the ssao looking correct.
thanks.
see in action here: video
and a pic...
Posted 07 July 2012 - 01:21 AM
Posted 07 July 2012 - 03:09 AM
Posted 07 July 2012 - 06:29 AM
Posted 07 July 2012 - 06:37 PM
Posted 07 July 2012 - 08:21 PM
Posted 08 July 2012 - 01:20 AM
Posted 08 July 2012 - 06:37 AM
Posted 08 July 2012 - 07:13 AM
Posted 08 July 2012 - 10:31 AM
/////////////////
/** Constants **/
/* Scaling constants (can also be uniforms!) */
const float sample_scale = 5.0;
const vec2 random_scale = vec2(10.0, 5.25);
const int sample_count = 10;
const float depth_scale = 0.001;
const float jitter_scale = 0.1;
///////////////////////////////////
/** Some needed texture samples **/
/* Sample from random texture - noisy RGB normal map */
vec3 random = texture(tex_random, tex_coord * vec2(random_scale.x, random_scale.y)).xyz * 2.0 - 1.0;
/* Position map & Normal map */
vec3 position_map = texture(tex_position, tex_coord).xyz; //< !!! Reconstruct from depth, I was too lazy to add it to old software
vec3 normal_map = texture(tex_normal, tex_coord).xyz * 2.0 - 1.0;
//////////////////////
/** SSAO variables **/
float occlusion = 0.0; //< value where everything will accumulate
float depth = texture(tex_depth, tex_coord); //< depth value at pixel we're currently shading
float incx = sample_scale * 1.0 / win_width; //< step size in x-direction
float incy = sample_scale * 1.0 / win_height; //< step size in y-direction
/* Just variables for computing sample point */
float dx0 = incx;
float dy0 = incy;
float ang = 0.0; //< Angle
////////////////////
/** Compute SSAO **/
/* We're circularly sampling around the point with some random noise, calculating the occlusion, note that it's absolutely
* necessary to use enough samples - 8 is fine, 16 is very good, 128 is damn too smooth (and damn too slow).
*
* Also it's good to mention that ambient occlusion is not affecting resulting image that much - e.g. a noise is hardly noticeable
* unless too strong. The strength of noise can be tuned through 'jitter_scale' variable, or in random-texture. (Can be optimized
* by just modifying texture and not multiplying here later - saves 2 MULs per loop cycle per pixel) */
for(int a = 0; a < sample_count; a++)
{
/* Compute coordinates (note they're jittered!) */
float dzx = (dx0 + jitter_scale * random.x) / depth;
float dzy = (dy0 + jitter_scale * random.y) / depth;
float angle = ang * 3.14 / 180.0;
/* TODO: Do this faster + more precision might be needed (although it runs nice so far) */
float dx = cos(angle) * dzx - sin(angle) * dzy;
float dy = sin(angle) * dzx + cos(angle) * dzy;
/* Sample position and normal texture */
vec3 pos = texture(tex_position, tex_coord + vec2(dx, dy)).xyz - position_map;
vec3 norm = texture(tex_data, tex_coord + vec2(dx, dy)).xyz;
/* Normalize and scale */
vec3 v = normalize(pos);
float d = length(pos) * depth_scale;
/* Heavy wizardy and deep magic */
/* This code is actually computing amount of occlusion between two points - note that it's absolutely necessary to fine tune the
* constant numbers here to get the best result! */
occlusion += (1.0 - clamp(max(dot(norm, -v), 0.0) - 0.05, 0.0, 1.0)) * clamp(max(dot(normal_map, v), 0.0) - 0.05, 0.0, 1.0) * (1.0 - 1.0 / sqrt(0.2 / (d * d * 23.0) + 1.0));
/* Continue sampling in a "sphere" around the point */
dx0 += incx;
dy0 += incy;
ang += 360.0 / ((float)sample_count);
}
occlusion /= ((float)sample_count); // The actual occlusion is average over samples
///////////////////
/** SSAO Result **/
/* We've got occlusion, where 1.0 means the point is fully occluded from environment and 0.0 that it's fully visible to environment
* but we need 1.0 when fully visible and 0.0 when fully occluded, also a bit of darkening through power function can be done (not
* necessary of course - fine-tune this to get the best result */
float ssao = pow(1.0 - clamp(occlusion, 0.0, 1.0), 2.0); // The result (e.g. SSAO result)

Posted 08 July 2012 - 08:56 PM
Posted 08 July 2012 - 11:28 PM
0 members, 1 guests, 0 anonymous users