X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fprogrambuilder.cpp;h=30457838e89bae1270ff3648a79250624a82d69e;hb=5281356f7e81ffed6337d3ac67c0e8d3e1605000;hp=2f38c93c10eb03a3b48d2dcbb8948151ddf98deb;hpb=f657e545d461948f9d014d65c7546b26671f2828;p=libs%2Fgl.git diff --git a/source/programbuilder.cpp b/source/programbuilder.cpp index 2f38c93c..30457838 100644 --- a/source/programbuilder.cpp +++ b/source/programbuilder.cpp @@ -68,9 +68,12 @@ const ProgramBuilder::StandardVariable ProgramBuilder::standard_variables[] = { FRAGMENT, "l_specular", "float", "pow(max(dot(n_zzz_half_vec, n_zzz_normal), 0.0), gl_FrontMaterial.shininess)", 0 }, { FRAGMENT, "n_zzz_half_vec", "vec3", "normalize(zzz_light_dir-zzz_incident_dir)", 0 }, { FRAGMENT, "n_zzz_light_dir", "vec3", "normalize(zzz_light_dir)", 0 }, - { FRAGMENT, "n_tbn_normal", "vec3", "texture2D(normalmap, texture_coord).xyz*2.0-1.0", "n" }, + { FRAGMENT, "n_tbn_normal", "vec3", "normal_sample*2.0-1.0", "n" }, { FRAGMENT, "n_eye_normal", "vec3", "normalize(eye_normal)", "!n" }, - { FRAGMENT, "tex_sample", "vec4", "texture2D(texture, texture_coord)", 0 }, + { FRAGMENT, "normal_sample", "vec3", "texture2D(normalmap, texture_coord).xyz", "!c" }, + { FRAGMENT, "normal_sample", "vec3", "sample_normalmap(texture_coord)", "c" }, + { FRAGMENT, "tex_sample", "vec4", "texture2D(texture, texture_coord)", "!c" }, + { FRAGMENT, "tex_sample", "vec4", "sample_texture(texture_coord)", "c" }, { VERTEX, "gl_Position", 0, "gl_ProjectionMatrix*eye_vertex", 0 }, { VERTEX, "shd_vertex", "vec3", "(eye_vertex*eye_shd_rmatrix).xyz", 0 }, @@ -232,6 +235,13 @@ string ProgramBuilder::create_source(const list &variables, Va source += "vec4 transform_vertex(vec4);\n"; source += "vec3 transform_normal(vec3);\n"; } + else if(scope==FRAGMENT && features.colorify) + { + if(features.texture) + source += "vec4 sample_texture(vec2);\n"; + if(features.normalmap) + source += "vec3 sample_normalmap(vec2);\n"; + } source += "void main()\n{\n"; @@ -365,7 +375,8 @@ vector ProgramBuilder::extract_identifiers(const char *expression) { vector result; const char *ptr = expression; - unsigned start, length; + unsigned start = 0; + unsigned length = 0; while(parse_identifier(ptr, start, length)) { result.push_back(string(ptr+start, length)); @@ -378,7 +389,8 @@ string ProgramBuilder::replace_identifiers(const char *expression, const map(f) { + add("colorify", &StandardFeatures::colorify); add("lighting", &StandardFeatures::lighting); add("material", &StandardFeatures::material); add("normalmap", &StandardFeatures::normalmap);