From de3a3b21df2dcf48ce99a41bf22ef15333318bb7 Mon Sep 17 00:00:00 2001 From: "Asad M. Zaman" Date: Thu, 15 Dec 2005 21:50:25 +0000 Subject: [PATCH] fixes the maya2egg alpha --- pandatool/src/maya/mayaShaderColorDef.cxx | 21 +++------ pandatool/src/maya/mayaShaderColorDef.h | 2 +- pandatool/src/mayaegg/mayaToEggConverter.cxx | 46 +++++++++++++++----- 3 files changed, 41 insertions(+), 28 deletions(-) diff --git a/pandatool/src/maya/mayaShaderColorDef.cxx b/pandatool/src/maya/mayaShaderColorDef.cxx index 79543b0525..d37034b4b1 100644 --- a/pandatool/src/maya/mayaShaderColorDef.cxx +++ b/pandatool/src/maya/mayaShaderColorDef.cxx @@ -59,7 +59,7 @@ MayaShaderColorDef() { _wrap_u = true; _wrap_v = true; - _alpha_is_luminance = false; + _has_alpha_channel = false; _blend_type = BT_unspecified; @@ -101,7 +101,7 @@ MayaShaderColorDef(MayaShaderColorDef ©) { _wrap_v = copy._wrap_v; _blend_type = copy._blend_type; - _alpha_is_luminance = copy._alpha_is_luminance; + _has_alpha_channel = copy._has_alpha_channel; _repeat_uv = copy._repeat_uv; _offset = copy._offset; @@ -278,21 +278,13 @@ read_surface_color(MayaShader *shader, MObject color, bool trans) { _has_texture = false; set_string_attribute(color, "fileTextureName", ""); } - /* - // Asad: testcode - bool file_has_alpha = false; - get_bool_attribute(color, "fileHasAlpha", file_has_alpha); - if (file_has_alpha) { - maya_cat.info() << _texture_filename << " : has alpha" << endl; - } - */ } get_vec2f_attribute(color, "coverage", _coverage); get_vec2f_attribute(color, "translateFrame", _translate_frame); get_angle_attribute(color, "rotateFrame", _rotate_frame); - get_bool_attribute(color, "alphaIsLuminance", _alpha_is_luminance); + //get_bool_attribute(color, "alphaIsLuminance", _alpha_is_luminance); get_bool_attribute(color, "mirror", _mirror); get_bool_attribute(color, "stagger", _stagger); @@ -403,10 +395,9 @@ read_surface_color(MayaShader *shader, MObject color, bool trans) { string pla_name = pla[j].name().asChar(); // sometimes, by default, maya gives a outAlpha on subsequent plugs, ignore that if (pla_name.find("outAlpha") != string::npos) { - maya_cat.debug() << pl.name().asChar() << " ignoring: " << pla_name << endl; - // In this case the artist is wanting to retain alpha at the result - // So make sure that this alpha is not thrown out by the egg file - _alpha_is_luminance = true; + // top texture has an alpha channel, so make sure that this alpha is retained by egg file + maya_cat.debug() << pl.name().asChar() << ":has alpha channel" << pla_name << endl; + _has_alpha_channel = true; continue; } if (!first) { diff --git a/pandatool/src/maya/mayaShaderColorDef.h b/pandatool/src/maya/mayaShaderColorDef.h index 72ca3cf5b3..0813255ff3 100755 --- a/pandatool/src/maya/mayaShaderColorDef.h +++ b/pandatool/src/maya/mayaShaderColorDef.h @@ -95,7 +95,7 @@ public: bool _wrap_u; bool _wrap_v; - bool _alpha_is_luminance; + bool _has_alpha_channel; LVector2f _repeat_uv; LVector2f _offset; diff --git a/pandatool/src/mayaegg/mayaToEggConverter.cxx b/pandatool/src/mayaegg/mayaToEggConverter.cxx index f7ce806115..73a5402f1c 100644 --- a/pandatool/src/mayaegg/mayaToEggConverter.cxx +++ b/pandatool/src/mayaegg/mayaToEggConverter.cxx @@ -1755,6 +1755,8 @@ make_polyset(MayaNodeDesc *node_desc, const MDagPath &dag_path, for (size_t ui=0; uiadd_child(egg_poly); @@ -2317,14 +2316,27 @@ void MayaToEggConverter:: set_shader_attributes(EggPrimitive &primitive, const MayaShader &shader, const MItMeshPolygon *pi) { - //mayaegg_cat.spam() << " set_shader_attributes : begin\n"; + // determine if the base texture or any of the top texture need to be rgb only + MayaShaderColorDef *color_def = NULL; + bool is_rgb = false; + int i; + for (i=0; i<(int)shader._color.size(); ++i) { + color_def = shader.get_color_def(i); + if (color_def->_has_texture && i != (int)shader._color.size()-1) { + if ((EggTexture::EnvType)color_def->_blend_type == EggTexture::ET_modulate) { + // read the _has_alpha_cahnnel to figure out rgb or rgba + //if (!color_def->_has_alpha_channel) { + //Maya's multiply is slightly different than panda's. Hence we are dropping the alpha. + is_rgb = true; // modulate forces the alpha to be ignored + //} + } + } + } // In Maya, a polygon is either textured or colored. The texture, // if present, replaces the color. Also now there could be multiple textures - MayaShaderColorDef *color_def = NULL; const MayaShaderColorDef &trans_def = shader._transparency; - //for (size_t i=0; i=0; --i) { + for (i=shader._color.size()-1; i>=0; --i) { color_def = shader.get_color_def(i); mayaegg_cat.spam() << "slot " << i << ":got color_def: " << color_def << endl; if (color_def->_has_texture || trans_def._has_texture) { @@ -2401,13 +2413,19 @@ set_shader_attributes(EggPrimitive &primitive, const MayaShader &shader, // last shader on the list is the base one, which should always pick up the alpha // from the texture file. But the top textures may have to strip the alpha if (i!=shader._color.size()-1) { - // read the _alpha_is_luminance to figure out env_type tex.set_env_type((EggTexture::EnvType)color_def->_blend_type); - // multitexture modulate mode should always turn alpha - // off. The texture and textures.txa will determine - // whether to keep it or not if (tex.get_env_type() == EggTexture::ET_modulate) { - tex.set_alpha_mode(EggRenderMode::AM_off); // Force alpha to be 'off' + if (color_def->_has_alpha_channel) { + // lets caution the artist that they should not be using a alpha channel on + // this texture. + maya_cat.spam() + << color_def->_texture_name + << " should not have alpha channel in multiply mode: ignoring\n"; + } + if (is_rgb) { + //tex.set_alpha_mode(EggRenderMode::AM_off); // force alpha off + tex.set_format(EggTexture::F_rgb); // Change the format to be rgb only + } } } } @@ -2424,6 +2442,10 @@ set_shader_attributes(EggPrimitive &primitive, const MayaShader &shader, } mayaegg_cat.debug() << "ssa:tref_name:" << tex.get_name() << endl; + if (is_rgb && i == (int)shader._color.size()-1) { + // make base layer rgb only + tex.set_format(EggTexture::F_rgb); // Change the format to be rgb only + } EggTexture *new_tex = _textures.create_unique_texture(tex, ~0);