From d95f18442ea216a886bfddf75d349362d1e537bc Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Fri, 11 Jul 2014 19:37:17 +0000 Subject: Support material layer blending. --- src/model/material.cc | 57 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 9 deletions(-) (limited to 'src/model/material.cc') diff --git a/src/model/material.cc b/src/model/material.cc index 0f3487c..d4accc8 100644 --- a/src/model/material.cc +++ b/src/model/material.cc @@ -63,12 +63,16 @@ void Material::print() con_print << "bounds "; } } - con_print << " layers: " << layers().size() << std::endl; + + int count = 0; for (Layers::const_iterator lit = material_layers.begin(); lit != material_layers.end(); ++lit) { const Layer *layer = (*lit); - con_print << " - texture: "; + count++; + con_print << " layer " << count << std::endl; + + con_print << " texture: "; if (layer->texmap() == Layer::TexMapNone) { con_print << "none"; } else if (layer->texmap() == Layer::TexMapImage) { @@ -76,9 +80,9 @@ void Material::print() } con_print << std::endl; - con_print << " color: " << layer->color() << std::endl; + con_print << " color: " << layer->color() << std::endl; - con_print << " rgbgen: "; + con_print << " rgbgen: "; switch (layer->rgbgen()) { case Layer::RGBGenIdentity: con_print << "identity"; @@ -100,6 +104,21 @@ void Material::print() break; } con_print << std::endl; + + if (layer->fullbright()) { + con_print << " fullbright" << std::endl; + } + + switch(layer->blendfunc()) { + case Layer::BlendFuncNone: + break; + case Layer::BlendFuncAdd: + con_print << " blendfunc: add" << std::endl; + break; + case Layer::BlendFuncBlend: + con_print << " blendfunc: blend" << std::endl; + break; + } } } @@ -298,11 +317,26 @@ void Material::load_shaderfile(const std::string &shadername) layer->set_rgbgen(Layer::RGBGenSecondary); } else if (firstword.compare("entitythird") == 0) { layer->set_rgbgen(Layer::RGBGenTertiary); - } else if (firstword.compare("bright") == 0) { - layer->set_bright(true); + } else if ((firstword.compare("bright") == 0) || (firstword.compare("fullbright") == 0)) { + layer->set_fullbright(true); } else if (firstword.compare("environment") == 0) { layer->set_tcgen(Layer::TCGenEnvironment); - layer->set_texmap(Layer::TexMapEnvironment); + layer->set_texmap(Layer::TexMapEnvironment); + } else if (firstword.compare("blendfunc") == 0) { + if (linestream >> firstword) { + aux::to_lowercase(firstword); + if (firstword.compare("none") == 0) { + layer->set_blendfunc(Layer::BlendFuncNone); + } else if (firstword.compare("add") == 0) { + layer->set_blendfunc(Layer::BlendFuncAdd); + } else if (firstword.compare("blend") == 0) { + layer->set_blendfunc(Layer::BlendFuncBlend); + } else { + con_warn << shaderfile.name() << " unknown blend function '" << firstword << "' at line " << linenumber << std::endl; + } + } else { + con_warn << shaderfile.name() << " missing blend function at line " << linenumber << std::endl; + } } else if (firstword.compare("map") == 0) { if (linestream >> firstword) { @@ -323,6 +357,8 @@ void Material::load_shaderfile(const std::string &shadername) } } } + } else { + con_warn << shaderfile.name() << " missing texture map at line " << linenumber << std::endl; } } else { con_warn << shaderfile.name() << " unknown layer key '" << firstword << "' at line " << linenumber << std::endl; @@ -357,7 +393,7 @@ Material *Material::find(const std::string &name) return 0; } -Material *Material::load(const std::string &name, const bool bright) +Material *Material::load(const std::string &name, const bool ui_texture) { // check if the requested material already exist Material *material = find(name); @@ -374,7 +410,10 @@ Material *Material::load(const std::string &name, const bool bright) // add a texture layer->set_texture(name); - layer->set_bright(bright); + if (ui_texture) { + layer->set_fullbright(true); + layer->set_blendfunc(Layer::BlendFuncBlend); + } if (material_imageloaderfunc) { material_imageloaderfunc(layer); if ((layer->size().width() > 0) && (layer->size().height() > 0)) { -- cgit v1.2.3