]> git.tdb.fi Git - libs/gl.git/commitdiff
Simplify reflections in the singlepass shader
authorMikko Rasa <tdb@tdb.fi>
Fri, 6 Jan 2017 11:49:20 +0000 (13:49 +0200)
committerMikko Rasa <tdb@tdb.fi>
Fri, 6 Jan 2017 12:35:48 +0000 (14:35 +0200)
Specular reflection of the sky was dropped.  It's better implemented
through an environment map.  In the future I'll add a skybox utility
class which provides a simple environment map.

shaderlib/singlepass.glsl

index 67e04e6d8fc3f05909e79c670a6a003b3ec55708..a1062fed7125bd2f69886e33c3d9a61bec25b7a3 100644 (file)
@@ -63,7 +63,6 @@ uniform ShadowMap
        mat4 shd_eye_matrix;
 };
 
-const bool use_reflection = false;
 const bool use_environment_map = false;
 uniform samplerCube environment;
 uniform EnvMap
@@ -141,6 +140,11 @@ vec3 get_normal_sample()
        return texture(normal_map, texcoord.xy).xyz*2.0-1.0;
 }
 
+vec4 get_environment_sample(vec3 direction)
+{
+       return texture(environment, direction);
+}
+
 vec3 normal;
 vec4 diffuse_sample;
 
@@ -195,19 +199,8 @@ vec3 singlepass_reflection()
        vec3 reflect_dir = reflect(incident_dir, normal);
        if(use_normal_map)
                reflect_dir = eye_tbn_matrix*reflect_dir;
-       vec3 result = vec3(0.0);
-
-       if(use_environment_map)
-               result += texture(environment, env_eye_matrix*reflect_dir).rgb*reflectivity;
 
-       if(use_sky && use_specular)
-       {
-               float reflect_altitude = clamp(dot(reflect_dir, eye_sky_dir)-horizon_limit, -1.0, 0.0);
-               float sky_specular_intensity = pow((1.0-reflect_altitude*reflect_altitude), material.shininess/2.0);
-               result += sky_specular_intensity*sky_color.rgb;
-       }
-
-       return result;
+       return get_environment_sample(env_eye_matrix*reflect_dir).rgb;
 }
 
 vec4 singlepass_color()
@@ -235,7 +228,7 @@ void main()
        else
                final_color = singlepass_color();
 
-       if(use_reflection)
+       if(use_environment_map)
                final_color += vec4(singlepass_reflection(), 0.0);
        if(use_fog)
        {