From: Mikko Rasa Date: Sun, 9 Sep 2012 21:02:36 +0000 (+0300) Subject: Bring back reflection mapping support to standard shaders X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=f657e545d461948f9d014d65c7546b26671f2828;p=libs%2Fgl.git Bring back reflection mapping support to standard shaders --- diff --git a/demos/cubemap.cpp b/demos/cubemap.cpp index 512f519f..4679590d 100644 --- a/demos/cubemap.cpp +++ b/demos/cubemap.cpp @@ -93,6 +93,8 @@ int main() GL::ProgramData shdata; shdata.uniform("environment", 0); shdata.uniform("reflectivity", 0.5f); + float env_mat[9] = { 1, 0, 0, 0, 1, 0, 0, 0, 1 }; + shdata.uniform_matrix3("env_eye_matrix", env_mat); GL::MatrixStack::projection() = GL::Matrix::frustum_centered(0.15, 0.1, 0.1, 10); diff --git a/source/programbuilder.cpp b/source/programbuilder.cpp index 636d87a9..2f38c93c 100644 --- a/source/programbuilder.cpp +++ b/source/programbuilder.cpp @@ -19,6 +19,7 @@ Naming conventions: eye_* Eye space tbn_* Tangent-Binormal-Normal space shd_* Shadow space + env_* Environment space *_dir Direction vector zzz_* Wildcard space, resolved by the builder @@ -45,8 +46,10 @@ const ProgramBuilder::StandardVariable ProgramBuilder::standard_variables[] = { FRAGMENT, "color_base", "vec4", "color", "!l!sm" }, { FRAGMENT, "color_base", "vec4", "vec4(vec3(l_shadow), 1.0)", "!ls!m" }, { FRAGMENT, "color_base", "vec4", "color*vec4(vec3(l_shadow), 1.0)", "!lsm" }, - { FRAGMENT, "color_base", "vec4", "vec4(rgb_light_full, 1.0)", "l!m" }, - { FRAGMENT, "color_base", "vec4", "vec4(rgb_light_full, gl_FrontMaterial.diffuse.a)", "lm" }, + { FRAGMENT, "color_base", "vec4", "vec4(rgb_light_env, 1.0)", "l!m" }, + { FRAGMENT, "color_base", "vec4", "vec4(rgb_light_env, gl_FrontMaterial.diffuse.a)", "lm" }, + { FRAGMENT, "rgb_light_env", "vec3", "rgb_light_full+reflect_sample.rgb*reflectivity", "e" }, + { FRAGMENT, "rgb_light_env", "vec3", "rgb_light_full", "!e" }, { FRAGMENT, "rgb_light_full", "vec3", "rgb_light_shadow+gl_FrontLightModelProduct.sceneColor.rgb", "m" }, { FRAGMENT, "rgb_light_full", "vec3", "rgb_light_shadow", "!m" }, { FRAGMENT, "rgb_light_shadow", "vec3", "rgb_light*l_shadow", "s" }, @@ -55,6 +58,10 @@ const ProgramBuilder::StandardVariable ProgramBuilder::standard_variables[] = { FRAGMENT, "rgb_light", "vec3", "vec3(l_diffuse+l_specular)", "!mp" }, { FRAGMENT, "rgb_light", "vec3", "l_diffuse*gl_FrontLightProduct[0].diffuse.rgb", "m!p" }, { FRAGMENT, "rgb_light", "vec3", "l_diffuse*gl_FrontLightProduct[0].diffuse.rgb+l_specular*gl_FrontLightProduct[0].specular.rgb", "mp" }, + { FRAGMENT, "reflect_sample", "vec4", "textureCube(environment, env_reflect_dir)", 0 }, + { FRAGMENT, "env_reflect_dir", "vec3", "env_eye_matrix*eye_reflect_dir", 0 }, + { FRAGMENT, "eye_reflect_dir", "vec3", "eye_tbn_matrix*tbn_reflect_dir", "n" }, + { FRAGMENT, "zzz_reflect_dir", "vec3", "reflect(zzz_incident_dir, n_zzz_normal)", 0 }, { FRAGMENT, "l_shadow", "float", "mix(1.0, shadow_sample, shadow_darkness)", 0 }, { FRAGMENT, "shadow_sample", "float", "shadow2D(shadow, shd_vertex).r", 0 }, { FRAGMENT, "l_diffuse", "float", "max(dot(n_zzz_normal, n_zzz_light_dir), 0.0)", 0 }, @@ -92,6 +99,9 @@ const ProgramBuilder::StandardVariable ProgramBuilder::standard_variables[] = { UNIFORM, "shadow", "sampler2DShadow", 0, 0 }, { UNIFORM, "shadow_darkness", "float", 0, 0 }, { UNIFORM, "normalmap", "sampler2D", 0, 0 }, + { UNIFORM, "environment", "samplerCube", 0, 0 }, + { UNIFORM, "env_eye_matrix", "mat3", 0, 0 }, + { UNIFORM, "reflectivity", "float", 0, 0 }, // Terminator entry { NO_SCOPE, 0, 0, 0, 0 }