From: Mikko Rasa Date: Fri, 6 Jan 2017 11:49:20 +0000 (+0200) Subject: Simplify reflections in the singlepass shader X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=a873639a9346082f9e71145a2b318bea32bfdeb6;p=libs%2Fgl.git Simplify reflections in the singlepass shader 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. --- diff --git a/shaderlib/singlepass.glsl b/shaderlib/singlepass.glsl index 67e04e6d..a1062fed 100644 --- a/shaderlib/singlepass.glsl +++ b/shaderlib/singlepass.glsl @@ -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) {