7uniform 
float max_radius;
 
   10uniform 
float step_mul;
 
   12uniform sampler2D depth_texture;
 
   13uniform sampler2D random_texture;
 
   15const float PI = 3.14159265;
 
   17uniform 
mat4  mat_proj_inv;
 
   18uniform 
float shadows_gamma;
 
   19uniform 
float shadows_intensity;
 
   20uniform 
float depth_cueing;
 
   21uniform 
float nb_directions;
 
   25uniform 
vec2 depth_tex_size;
 
   26uniform 
vec2 random_tex_size;
 
   28#define width float(depth_tex_size.x) 
   29#define height float(depth_tex_size.y) 
   31#define r_width float(random_tex_size.x) 
   32#define r_height float(random_tex_size.y) 
   37float width  = float(textureSize(depth_texture,0).x);
 
   38float height = float(textureSize(depth_texture,0).y);
 
   41float r_width  = float(textureSize(random_texture,0).x);
 
   42float r_height = float(textureSize(random_texture,0).y);
 
   50vec3 get_obj_coords(in vec2 where, in sampler2D texture) {
 
   51    vec4 p = 
vec4(where, glup_texture(texture, where).x, 1.);
 
   53    p.xyz = p.xyz * 2. - 1.;
 
   65float get_obj_z(in vec2 where, in sampler2D texture) {
 
   66    float depth = glup_texture(texture, where).x;
 
   72    depth = depth * 2. - 1.;
 
   73    float z = (depth * mat_proj_inv[2][2] + mat_proj_inv[3][2]) /
 
   74        (depth * mat_proj_inv[2][3] + mat_proj_inv[3][3]);
 
   82bool outside(in vec2 point) {
 
   84        point.x > 1. || point.x < 0.||
 
   85        point.y > 1. || point.y < 0.
 
   93vec2 horizon_point(in vec2 from, in vec2 dir) {
 
   95    float horizon_delta = -100000.0;
 
   96    float from_z = get_obj_z(from, depth_texture);
 
   97    float step = (1.0 / width);
 
   99    vec2 cur_point = from + r * dir;
 
  102    for(
int i=0; i<100; ++i) {
 
  103        if(!outside(cur_point)) {
 
  105            while (!outside(cur_point)) {
 
  108                z = get_obj_z(cur_point, depth_texture);
 
  110                float delta_z = (z - from_z) / r;
 
  111                if( delta_z > horizon_delta) {
 
  112                    horizon_delta = delta_z;
 
  120                cur_point = from + r * dir;
 
  136    float horizon_angle(in vec2 from, in vec3 from3D, in vec2 dir, in vec3 normal) {
 
  138            get_obj_coords(horizon_point(from, dir), depth_texture) - from3D;
 
  139        return acos ( 
dot(normal, horizon) / 
length(horizon) );
 
  147        float x = tex_coord.x * width  / r_width;
 
  148        float y = tex_coord.y * height / r_height;
 
  149        return glup_texture(random_texture, 
vec2(x,y)).x;
 
  152    float ambient_occlusion(in vec2 from) {
 
  153        float angle_step = 2.0 * PI / (nb_directions);
 
  154        float cur_angle = my_noise() * 2. * PI ;
 
  155        float occlusion_factor = 0.0;
 
  156        vec3 from3D = get_obj_coords(from, depth_texture);
 
  158        for (
int i=0; i < 7; i++) {
 
  160            for (
int i=0; i < nb_directions; i++) {
 
  162                vec2 dir = 
vec2(cos(cur_angle), sin(cur_angle));
 
  163                float h_angle = horizon_angle(from, from3D, dir, 
vec3(0., 0., 1.));
 
  164                cur_angle += angle_step;
 
  165                occlusion_factor += h_angle;
 
  167            return occlusion_factor / (float(nb_directions) * (PI / 2.0));
 
  170        float compute_depth_cueing(vec2 uv) {
 
  171            if(depth_cueing == 0.0) {
 
  174            float depth = glup_texture(depth_texture,tex_coord).x;
 
  175            return depth < 1.0 ? depth_cueing * depth : 0.0;
 
  180            if(glup_texture(depth_texture, tex_coord).x < 1.0) {
 
  181                g = ambient_occlusion(tex_coord);
 
  182                g = shadows_intensity *
 
  183                    pow(g, shadows_gamma) - compute_depth_cueing(tex_coord);
 
  185            glup_FragColor.rgb = 
vec3(0.0,0.0,0.0);
 
  186            glup_FragColor.a   = 1.0 - g;
 
double length(vec3 v)
Computes the length of a vector.
Matrix< 4, Numeric::float64 > mat4
Represents a 4x4 matrix.
T dot(const vecng< 3, T > &v1, const vecng< 3, T > &v2)
Computes the dot product of 2 vectors.   vecng
vecng< 3, Numeric::float64 > vec3
Represents points and vectors in 3d.
vecng< 4, Numeric::float64 > vec4
Represents points and vectors in 4d.
vecng< 2, Numeric::float64 > vec2
Represents points and vectors in 2d.