polyadvent

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

main.f.glsl (1259B)


      1 #include profile
      2 
      3 out vec4 frag_color;
      4 
      5 #include uniforms.glsl
      6 
      7 in shader_data {
      8 #include shadervars.glsl
      9 } vertex;
     10 
     11 uniform sampler2D shadow_map;
     12 uniform samplerCube skybox;
     13 
     14 #include lighting.glsl
     15 #include shadows.glsl
     16 #include fog.glsl
     17 
     18 vec3 reflect_env(vec3 vert_pos) {
     19     vec3 I = normalize(vert_pos - camera_position);
     20     vec3 R = reflect(I, normalize(vertex.normal));
     21     vec3 color = texture(skybox, R).rgb;
     22     return color;
     23 }
     24 
     25 // vec3 refract_env(vec3 vert_pos) {
     26 //     const float ratio = 1.00 / 1.52;
     27 
     28 //     vec3 I = normalize(vert_pos - camera_position);
     29 //     vec3 R = refract(I, normalize(vertex.normal), ratio);
     30 //     vec3 color = texture(skybox, R).rgb;
     31 //     return color;
     32 // }
     33 
     34 
     35 void main() {
     36   vec3 V = camera_position - vertex.position;
     37   vec4 v4_pos = vec4(vertex.position, 1.0);
     38   vec4 v4_normal = vec4(vertex.normal, 1.0);
     39 
     40   // vec3 color = standard_light(vertex.color, v4_pos, v4_normal);
     41   // vec3 color = reflect_env(vertex.color);
     42   vec3 color = pbr(vertex.color, normalize(V), vertex.normal);
     43 
     44   if (fog_on == 1) {
     45     vec3 fog = apply_fog(color, vertex.position, length(V), camera_position, V);
     46     color = fog;
     47   }
     48 
     49   color *= shadow_strength(v4_pos, v4_normal, vertex.shadow_coord);
     50 
     51   frag_color = vec4(color, 1.0);
     52 }