From 1cd9239578c0073cd33de9ec96bf94ac1eafcc36 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 11 Sep 2012 23:55:25 +0300 Subject: [PATCH] Make it possible to customize texture sampling in standard shaders --- source/programbuilder.cpp | 20 +++++++++++++++++--- source/programbuilder.h | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/source/programbuilder.cpp b/source/programbuilder.cpp index 2f38c93c..c97ec1cb 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"; @@ -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(f) { + add("colorify", &StandardFeatures::colorify); add("lighting", &StandardFeatures::lighting); add("material", &StandardFeatures::material); add("normalmap", &StandardFeatures::normalmap); diff --git a/source/programbuilder.h b/source/programbuilder.h index 82a954b5..a6eb3fde 100644 --- a/source/programbuilder.h +++ b/source/programbuilder.h @@ -30,6 +30,7 @@ public: bool shadow; bool reflection; bool transform; + bool colorify; StandardFeatures(); -- 2.43.0