tree.glsl (943B)
1 layout( std140 ) uniform view { 2 mat4 V; 3 mat4 P; 4 }; 5 6 layout( std140 ) uniform sun { 7 vec3 sun_dir; 8 }; 9 10 struct VSOut { 11 vec3 view_position; 12 vec3 normal; 13 vec3 colour; 14 }; 15 16 uniform sampler2D blue_noise; 17 18 #ifdef VERTEX_SHADER 19 20 in vec3 position; 21 in vec3 normal; 22 in vec3 colour; 23 in mat4 model_to_world; 24 out VSOut v2f; 25 26 void main() { 27 vec4 view_position = V * model_to_world * vec4( position, 1.0 ); 28 v2f.view_position = vec3( view_position ); 29 v2f.normal = mat3( model_to_world ) * normal; 30 v2f.colour = colour; 31 gl_Position = P * view_position; 32 } 33 34 #else 35 36 in VSOut v2f; 37 out vec4 screen_colour; 38 39 float sq( float x ) { 40 return x * x; 41 } 42 43 void main() { 44 // sunlight 45 float lambert = dot( sun_dir, v2f.normal ); 46 float half_lambert = sq( lambert * 0.5 + 0.5 ); 47 vec3 c = v2f.colour * half_lambert; 48 49 // fog 50 c = apply_fog( c, length( v2f.view_position ) ); 51 52 screen_colour = vec4( linear_to_srgb( c + get_dither_noise( blue_noise ) ), 1.0 ); 53 } 54 55 #endif