polyadvent

A game engine from scratch in C
git clone git://jb55.com/polyadvent
Log | Files | Refs | README

fog.glsl (974B)


      1 
      2 
      3 vec3 apply_fog(in vec3 rgb, in vec3 vert_pos, in float distance,
      4                in vec3 ray_orig, in vec3 ray_dir)
      5 {
      6     const float b = 0.00032;
      7 
      8     float draw_dist = 0.5;
      9     float fog_amount = 1.0-exp(-pow(distance * (1.0/draw_dist) * b, 3.0));
     10     float sun_amount = max( dot( ray_dir, -light_dir ), 0.0 ) * b;
     11     // sun_amount = pow(sun_amount, 0.0);
     12 
     13     // vec3 I = normalize(vert_pos - camera_position);
     14     // vec3 R = refract(I, vertex.normal, 1.0/2.0);
     15     // vec3 fog_color = sun_color * sky_intensity;
     16     // vec3 fog_color = sun_color;
     17 
     18     vec3  fog_color  = mix(vec3(0.5,0.6,0.7),
     19                            vec3(1.0,0.9,0.8),
     20                     smoothstep(0.1, 1.0, 0.5)
     21                            ) * light_intensity;
     22 
     23     // vec3 final_color = rgb*(1.0-exp(-distance*b)) + fog_color*exp(-distance*b);
     24     vec3 final_color = mix( rgb, fog_color, fog_amount);
     25 
     26     return final_color;
     27 }
     28 
     29 
     30 vec3 depth_fog(vec3 rgb, vec4 depth) {
     31     return depth.xyz;
     32 }