]> git.tdb.fi Git - libs/gl.git/commitdiff
Make it possible to customize texture sampling in standard shaders
authorMikko Rasa <tdb@tdb.fi>
Tue, 11 Sep 2012 20:55:25 +0000 (23:55 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 11 Sep 2012 20:55:25 +0000 (23:55 +0300)
source/programbuilder.cpp
source/programbuilder.h

index 2f38c93c10eb03a3b48d2dcbb8948151ddf98deb..c97ec1cb490b1943e38f58544a522a6a22349b99 100644 (file)
@@ -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<ShaderVariable *> &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";
 
@@ -403,7 +413,8 @@ ProgramBuilder::StandardFeatures::StandardFeatures():
        normalmap(false),
        shadow(false),
        reflection(false),
-       transform(false)
+       transform(false),
+       colorify(false)
 { }
 
 string ProgramBuilder::StandardFeatures::create_flags() const
@@ -427,6 +438,8 @@ string ProgramBuilder::StandardFeatures::create_flags() const
                flags += 'e';
        if(transform)
                flags += 'r';
+       if(colorify)
+               flags += 'c';
 
        return flags;
 }
@@ -555,6 +568,7 @@ string ProgramBuilder::ShaderVariable::get_expression() const
 ProgramBuilder::StandardFeatures::Loader::Loader(StandardFeatures &f):
        DataFile::ObjectLoader<StandardFeatures>(f)
 {
+       add("colorify",  &StandardFeatures::colorify);
        add("lighting",  &StandardFeatures::lighting);
        add("material",  &StandardFeatures::material);
        add("normalmap", &StandardFeatures::normalmap);
index 82a954b58b481faf4809cac719baa3aa1c48079a..a6eb3fde8522dc097b19032c972cab399c078685 100644 (file)
@@ -30,6 +30,7 @@ public:
                bool shadow;
                bool reflection;
                bool transform;
+               bool colorify;
 
                StandardFeatures();