medfall

A super great game engine
Log | Files | Refs

clipmap_skirt.glsl (1004B)


      1 layout( std140 ) uniform view {
      2 	mat4 V;
      3 	mat4 P;
      4 	vec3 camera_pos;
      5 };
      6 
      7 layout( std140 ) uniform sun {
      8 	vec3 sun_dir;
      9 	float sun_angle;
     10 };
     11 
     12 layout( std140 ) uniform clipmap_skirt {
     13 	float scale;
     14 };
     15 
     16 struct VSOut {
     17 	vec4 view_position;
     18 };
     19 
     20 uniform sampler2D blue_noise;
     21 
     22 #ifdef VERTEX_SHADER
     23 
     24 in vec3 position;
     25 out VSOut v2f;
     26 
     27 void main() {
     28 	vec2 xy = position.xy + camera_pos.xy;
     29 	vec2 snapped_xy = floor( xy / scale ) * scale;
     30 	v2f.view_position = V * vec4( snapped_xy, 0.0, 1.0 );
     31 	gl_Position = P * v2f.view_position;
     32 }
     33 
     34 #else
     35 
     36 in VSOut v2f;
     37 out vec4 screen_colour;
     38 
     39 void main() {
     40 	vec3 normal = vec3( 0.0, 0.0, 1.0 );
     41 	vec3 ground = vec3( 0.0, 0.25, 1.0 );
     42 
     43 	float sunlight_lambert = max( 0, dot( normal, sun_dir ) );
     44 	vec3 sunlight = sunlight_lambert * vec3( 0.9, 0.9, 0.5 );
     45 	vec3 ambient = vec3( 0.05, 0.05, 0.15 );
     46 
     47 	vec3 c = ( sunlight + ambient ) * ground;
     48 
     49 	screen_colour = vec4( linear_to_srgb( apply_fog( c + get_dither_noise( blue_noise ), length( v2f.view_position ) ) ), 1.0 );
     50 }
     51 
     52 #endif