From bb52497591bb827c2581cbf02e53785e39f9cfcd Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 21 May 2014 01:09:49 +0300 Subject: [PATCH] Rearrange ProgramBuilder's standard variables The rgb_light_foo names were getting a bit stupid, and the hierarchy also makes more sense this way. The use of gl_FrontLightProduct was dropped as too cumbersome to maintain. The future is with modern shaders anyway. Texture now only affects ambient and diffuse colors, not specular. There will likely be support for a separate specular map in the future. --- source/programbuilder.cpp | 70 +++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 28 deletions(-) diff --git a/source/programbuilder.cpp b/source/programbuilder.cpp index 26689bce..8e4d1385 100644 --- a/source/programbuilder.cpp +++ b/source/programbuilder.cpp @@ -43,39 +43,53 @@ anything that might need them. */ const ProgramBuilder::VariableDefinition ProgramBuilder::standard_variables[] = { { FRAGMENT, "gl_FragColor", "vec4", "frag_color", "g" }, - { FRAGMENT, "frag_color", "vec4", "color_base", "!t" }, - { FRAGMENT, "frag_color", "vec4", "tex_sample", "!l!s!mt" }, - { FRAGMENT, "frag_color", "vec4", "tex_sample*color_base", "l|s|mt" }, - { FRAGMENT, "color_base", "vec4", "vec4(1.0)", "!l!s!m" }, - { 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_env, 1.0)", "l!m" }, - { FRAGMENT, "color_base", "vec4", "vec4(rgb_light_env, material.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+ambient_product_diffuse.rgb", "m" }, - { FRAGMENT, "rgb_light_full", "vec3", "rgb_light_shadow", "!m" }, - { FRAGMENT, "ambient_product_diffuse", "vec4", "gl_FrontLightModelProduct.sceneColor", "g" }, - { FRAGMENT, "ambient_product_diffuse", "vec4", "ambient_color*material.diffuse", "!g" }, - { FRAGMENT, "rgb_light_shadow", "vec3", "rgb_light*l_shadow", "s" }, - { FRAGMENT, "rgb_light_shadow", "vec3", "rgb_light", "!s" }, - { FRAGMENT, "rgb_light[i]", "vec3", "vec3(l_diffuse[i])", "!m!p" }, - { FRAGMENT, "rgb_light[i]", "vec3", "vec3(l_diffuse[i]+l_specular[i])", "!mp" }, - { FRAGMENT, "rgb_light[i]", "vec3", "l_diffuse[i]*light_product_diffuse[i].rgb", "m!p" }, - { FRAGMENT, "rgb_light[i]", "vec3", "l_diffuse[i]*light_product_diffuse[i].rgb+l_specular[i]*light_product_specular[i].rgb", "mp" }, - { FRAGMENT, "light_product_diffuse[i]", "vec4", "gl_FrontLightProduct[i].diffuse", "g" }, - { FRAGMENT, "light_product_diffuse[i]", "vec4", "light_sources[i].diffuse*material.diffuse", "!g" }, - { FRAGMENT, "light_product_specular[i]", "vec4", "gl_FrontLightProduct[i].specular", "g" }, - { FRAGMENT, "light_product_specular[i]", "vec4", "light_sources[i].specular*material.specular", "!g" }, + { FRAGMENT, "frag_color", "vec4", "basic_color", "!e!l" }, + { FRAGMENT, "frag_color", "vec4", "vec4(rgb_surface, surface_alpha)", "!el" }, + { FRAGMENT, "frag_color", "vec4", "vec4(rgb_surface+rgb_reflection, surface_alpha)", "e" }, + + { FRAGMENT, "rgb_reflection", "vec3", "reflect_sample.rgb*reflectivity", 0 }, { 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, "rgb_surface", "vec3", "rgb_unlit_surface", "!l" }, + { FRAGMENT, "rgb_surface", "vec3", "rgb_lit_surface", "l" }, + { FRAGMENT, "rgb_unlit_surface", "vec3", "basic_color.rgb", "!s" }, + { FRAGMENT, "rgb_unlit_surface", "vec3", "basic_color.rgb*l_shadow", "s" }, + { FRAGMENT, "rgb_lit_surface", "vec3", "rgb_illumination_diffuse", "!m" }, + { FRAGMENT, "rgb_lit_surface", "vec3", "rgb_surface_ambient+rgb_surface_diffuse", "m!p" }, + { FRAGMENT, "rgb_lit_surface", "vec3", "rgb_surface_ambient+rgb_surface_diffuse+rgb_surface_specular", "mp" }, + + { FRAGMENT, "surface_alpha", "float", "basic_color.a", "!m" }, + { FRAGMENT, "surface_alpha", "float", "basic_color.a", "m!l" }, + { FRAGMENT, "surface_alpha", "float", "material.diffuse.a", "ml!t" }, + { FRAGMENT, "surface_alpha", "float", "material.diffuse.a*tex_sample.a", "mlt" }, + { FRAGMENT, "basic_color", "vec4", "vec4(1.0)", "!m!t" }, + { FRAGMENT, "basic_color", "vec4", "tex_sample", "!mt" }, + { FRAGMENT, "basic_color", "vec4", "color", "m!t" }, + { FRAGMENT, "basic_color", "vec4", "color*tex_sample", "mt" }, + + { FRAGMENT, "rgb_surface_ambient", "vec3", "rgb_illumination_ambient*material.ambient.rgb", "!t" }, + { FRAGMENT, "rgb_surface_ambient", "vec3", "rgb_illumination_ambient*material.ambient.rgb*tex_sample.rgb", "t" }, + { FRAGMENT, "rgb_illumination_ambient", "vec3", "ambient_color.rgb", 0 }, + + { FRAGMENT, "rgb_surface_specular", "vec3", "rgb_illumination_specular*material.specular.rgb", 0 }, + { FRAGMENT, "rgb_illumination_specular", "vec3", "rgb_light_specular", "!s" }, + { FRAGMENT, "rgb_illumination_specular", "vec3", "rgb_light_specular*l_shadow", "s" }, + { FRAGMENT, "rgb_light_specular[i]", "vec3", "l_specular[i]*light_sources[i].specular.rgb", 0 }, + { FRAGMENT, "l_specular[i]", "float", "pow(max(dot(n_zzz_half_vec[i], n_zzz_normal), 0.0), material.shininess)", 0 }, + + { FRAGMENT, "rgb_surface_diffuse", "vec3", "rgb_illumination_diffuse*material.diffuse.rgb", "!t" }, + { FRAGMENT, "rgb_surface_diffuse", "vec3", "rgb_illumination_diffuse*material.diffuse.rgb*tex_sample.rgb", "t" }, + { FRAGMENT, "rgb_illumination_diffuse", "vec3", "rgb_light_diffuse", "!s" }, + { FRAGMENT, "rgb_illumination_diffuse", "vec3", "rgb_light_diffuse*l_shadow", "s" }, + { FRAGMENT, "rgb_light_diffuse[i]", "vec3", "l_diffuse[i]*light_sources[i].diffuse.rgb", 0 }, + { FRAGMENT, "l_diffuse[i]", "float", "max(dot(n_zzz_normal, n_zzz_light_dir[i]), 0.0)", 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[i]", "float", "max(dot(n_zzz_normal, n_zzz_light_dir[i]), 0.0)", 0 }, - { FRAGMENT, "l_specular[i]", "float", "pow(max(dot(n_zzz_half_vec[i], n_zzz_normal), 0.0), material.shininess)", 0 }, + + { FRAGMENT, "zzz_reflect_dir", "vec3", "reflect(zzz_incident_dir, n_zzz_normal)", 0 }, { FRAGMENT, "n_zzz_half_vec[i]", "vec3", "normalize(zzz_light_dir[i]-zzz_incident_dir)", 0 }, { FRAGMENT, "n_zzz_light_dir[i]", "vec3", "normalize(zzz_light_dir[i])", 0 }, { FRAGMENT, "n_tbn_normal", "vec3", "normal_sample*2.0-1.0", "n" }, -- 2.45.2