diff --git a/panda/src/egg2pg/config_egg2pg.cxx b/panda/src/egg2pg/config_egg2pg.cxx index 5cf3fa03d1..e51ef31366 100644 --- a/panda/src/egg2pg/config_egg2pg.cxx +++ b/panda/src/egg2pg/config_egg2pg.cxx @@ -184,6 +184,13 @@ ConfigVariableInt egg_vertex_max_num_joints "more than this number of joints, the joints with the lesser membership " "value are ignored. Set this to -1 to allow any number of joints.")); +ConfigVariableBool egg_implicit_alpha_binary +("egg-implicit-alpha-binary", false, + PRC_DESC("If this is true, then a alpha value appearing in an egg " + "file that appears to specify only a binary (0 or 1) value for alpha " + "will automatically be downgraded to alpha type \"binary\" instead of " + "whatever appears in the egg file.")); + ConfigureFn(config_egg2pg) { init_libegg2pg(); } diff --git a/panda/src/egg2pg/config_egg2pg.h b/panda/src/egg2pg/config_egg2pg.h index 62fe95ce22..e0fe18cd90 100644 --- a/panda/src/egg2pg/config_egg2pg.h +++ b/panda/src/egg2pg/config_egg2pg.h @@ -54,6 +54,7 @@ extern EXPCL_PANDAEGG ConfigVariableBool egg_emulate_bface; extern EXPCL_PANDAEGG ConfigVariableBool egg_preload_simple_textures; extern EXPCL_PANDAEGG ConfigVariableDouble egg_vertex_membership_quantize; extern EXPCL_PANDAEGG ConfigVariableInt egg_vertex_max_num_joints; +extern EXPCL_PANDAEGG ConfigVariableBool egg_implicit_alpha_binary; extern EXPCL_PANDAEGG void init_libegg2pg(); diff --git a/panda/src/egg2pg/eggRenderState.cxx b/panda/src/egg2pg/eggRenderState.cxx index 7ba27b16d2..508687e734 100644 --- a/panda/src/egg2pg/eggRenderState.cxx +++ b/panda/src/egg2pg/eggRenderState.cxx @@ -247,10 +247,15 @@ fill_state(EggPrimitive *egg_prim) { } if (egg_prim->has_material()) { + PT(EggMaterial) material = egg_prim->get_material(); CPT(RenderAttrib) mt = - get_material_attrib(egg_prim->get_material(), - egg_prim->get_bface_flag()); + get_material_attrib(material, egg_prim->get_bface_flag()); add_attrib(mt); + + if (material->has_diff() && material->get_diff()[3] != 1.0) { + implicit_alpha = true; + binary_alpha_only = false; + } } @@ -294,11 +299,13 @@ fill_state(EggPrimitive *egg_prim) { case EggRenderMode::AM_ms: case EggRenderMode::AM_ms_mask: case EggRenderMode::AM_dual: - // Any of these modes gets implicitly downgraded to AM_binary, if - // all of the alpha sources only contribute a binary value to - // alpha. - if (binary_alpha_only) { - am = EggRenderMode::AM_binary; + if (egg_implicit_alpha_binary) { + // Any of these modes gets implicitly downgraded to AM_binary, if + // all of the alpha sources only contribute a binary value to + // alpha. + if (binary_alpha_only) { + am = EggRenderMode::AM_binary; + } } break;