]> git.tdb.fi Git - libs/gl.git/blobdiff - shaderlib/cooktorrance.glsl
Split the Light class into subclasses by light type
[libs/gl.git] / shaderlib / cooktorrance.glsl
index f8aed8267273fcb4f1ac97c929e3823ba29dbcb0..f441a6d392088fe05f8152dc3430d2de1b701c3a 100644 (file)
@@ -28,8 +28,7 @@ layout(constant_id=auto) const bool use_roughness_map = false;
 layout(constant_id=auto) const bool use_occlusion_map = false;
 layout(constant_id=auto) const bool use_emission = false;
 layout(constant_id=auto) const bool use_emission_map = false;
-
-const float PI = 3.1415926535;
+layout(constant_id=auto) const bool use_image_based_lighting = false;
 
 #pragma MSP stage(fragment)
 virtual vec4 get_base_color()
@@ -139,15 +138,27 @@ vec3 cooktorrance_environment(vec3 normal, vec3 look, vec3 base_color, float met
        vec3 k_spec = f0*scale_bias.x+scale_bias.y;
        vec3 k_diff = (1.0-k_spec)*(1.0-metalness);
 
-       return (k_diff*base_color+k_spec)*ambient_color.rgb;
+       if(use_image_based_lighting)
+       {
+               vec3 irradiance = get_irradiance_sample(normal);
+               vec3 reflection = get_environment_sample(reflect(look, normal), roughness).rgb;
+
+               return k_diff*irradiance*base_color+k_spec*reflection;
+       }
+       else
+               return (k_diff*base_color+k_spec)*ambient_color.rgb;
 }
 
 vec3 cooktorrance_lighting(vec3 normal, vec3 look, vec3 base_color, float metalness, float roughness)
 {
-       vec3 light = normalize(world_light_dir);
-
-       float shadow = get_shadow_factor(0);
-       vec3 color = cooktorrance_one_light_direct(normal, look, light, light_sources[0].color, base_color, metalness, roughness)*shadow;
+       vec3 color = vec3(0.0);
+       for(int i=0; i<max_lights; ++i)
+               if(light_sources[i].type!=0)
+               {
+                       vec3 light = get_light_direction(i);
+                       float shadow = get_shadow_factor(i);
+                       color += cooktorrance_one_light_direct(normal, look, light, light_sources[i].color, base_color, metalness, roughness)*shadow;
+               }
 
        color += cooktorrance_environment(normal, look, base_color, metalness, roughness);