COLLADA - support for shadeless material (SHADER_CONSTANT)

This patch make it possible to export and import shadeless material.

Reviewers: sergey, sauraedron

Subscribers: sergey

Projects: #collada

Differential Revision: https://developer.blender.org/D1094
This commit is contained in:
Gaia Clary 2015-03-05 18:44:04 +01:00
parent 23af8984bb
commit 04b0a9f4b8
Notes: blender-bot 2023-02-14 11:21:43 +01:00
Referenced by commit 37d7b2d3b6, Revert "COLLADA - support for shadeless material (SHADER_CONSTANT)"
Referenced by issue #49077, Collada exporter does not respect 'shadeless' flag
2 changed files with 67 additions and 28 deletions

View File

@ -800,10 +800,13 @@ void DocumentImporter::write_profile_COMMON(COLLADAFW::EffectCommon *ef, Materia
else if (shader == COLLADAFW::EffectCommon::SHADER_LAMBERT) {
ma->diff_shader = MA_DIFF_LAMBERT;
}
else if (shader == COLLADAFW::EffectCommon::SHADER_CONSTANT) {
ma->mode = MA_SHLESS;
}
// default - lambert
else {
ma->diff_shader = MA_DIFF_LAMBERT;
fprintf(stderr, "Current shader type is not supported, default to lambert.\n");
fprintf(stderr, "Shader type %d is not supported, default to lambert.\n", shader);
}
// reflectivity
ma->ray_mirror = ef->getReflectivity().getFloatValue();
@ -899,7 +902,7 @@ void DocumentImporter::write_profile_COMMON(COLLADAFW::EffectCommon *ef, Materia
COLLADAFW::Texture ctex = ef->getEmission().getTexture();
mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map);
if (mtex != NULL) {
mtex->mapto = MAP_EMIT;
mtex->mapto = (shader == COLLADAFW::EffectCommon::SHADER_CONSTANT) ? MAP_COL : MAP_EMIT;
i++;
}
}
@ -930,6 +933,21 @@ void DocumentImporter::write_profile_COMMON(COLLADAFW::EffectCommon *ef, Materia
}
}
#endif
/**
* <constant> cannot have diffuse, ambient, specular, shininnes as its child.
* So color is solely based on
* the emission color, so we map emission color to material's color
*/
if (shader == COLLADAFW::EffectCommon::SHADER_CONSTANT) {
COLLADAFW::Color col_emmission;
if (ef->getEmission().isValid()) {
col_emmission = ef->getEmission().getColor();
ma->r = col_emmission.getRed();
ma->g = col_emmission.getGreen();
ma->b = col_emmission.getBlue();
}
}
material_texture_mapping_map[ma] = texindex_texarray_map;
}

View File

@ -173,37 +173,44 @@ void EffectsExporter::writeTextures(COLLADASW::EffectProfile &ep,
void EffectsExporter::operator()(Material *ma, Object *ob)
{
bool is_shadeless = ma->mode & MA_SHLESS;
// create a list of indices to textures of type TEX_IMAGE
std::vector<int> tex_indices;
if (this->export_settings->include_material_textures)
createTextureIndices(ma, tex_indices);
openEffect(translate_id(id_name(ma)) + "-effect");
COLLADASW::EffectProfile ep(mSW);
ep.setProfileType(COLLADASW::EffectProfile::COMMON);
ep.openProfile();
// set shader type - one of three blinn, phong or lambert
if (ma->spec > 0.0f) {
if (ma->spec_shader == MA_SPEC_BLINN) {
writeBlinn(ep, ma);
}
else {
// \todo figure out handling of all spec+diff shader combos blender has, for now write phong
// for now set phong in case spec shader is not blinn
writePhong(ep, ma);
}
/* set shader type */
if (is_shadeless) {
ep.setShaderType(COLLADASW::EffectProfile::CONSTANT);
}
else {
if (ma->diff_shader == MA_DIFF_LAMBERT) {
writeLambert(ep, ma);
if (ma->spec > 0.0f) {
if (ma->spec_shader == MA_SPEC_BLINN) {
writeBlinn(ep, ma);
}
else {
// \todo figure out handling of all spec+diff shader combos blender has, for now write phong
// for now set phong in case spec shader is not blinn
writePhong(ep, ma);
}
}
else {
// \todo figure out handling of all spec+diff shader combos blender has, for now write phong
writePhong(ep, ma);
if (ma->diff_shader == MA_DIFF_LAMBERT) {
writeLambert(ep, ma);
}
else {
// \todo figure out handling of all spec+diff shader combos blender has, for now write phong
writePhong(ep, ma);
}
}
}
// index of refraction
if (ma->mode & MA_RAYTRANSP) {
ep.setIndexOfRefraction(ma->ang, false, "index_of_refraction");
@ -216,28 +223,40 @@ void EffectsExporter::operator()(Material *ma, Object *ob)
// transparency
if (ma->mode & MA_TRANSP) {
// Tod: because we are in A_ONE mode transparency is calculated like this:
// Todo: because we are in A_ONE mode transparency is calculated like this:
ep.setTransparency(ma->alpha, false, "transparency");
// cot = getcol(1.0f, 1.0f, 1.0f, 1.0f);
// ep.setTransparent(cot);
}
// emission
cot = getcol(ma->emit, ma->emit, ma->emit, 1.0f);
if (is_shadeless) {
cot = getcol(ma->r, ma->g, ma->b, 1.0f);
}
else {
cot = getcol(ma->emit, ma->emit, ma->emit, 1.0f);
}
ep.setEmission(cot, false, "emission");
// diffuse multiplied by diffuse intensity
cot = getcol(ma->r * ma->ref, ma->g * ma->ref, ma->b * ma->ref, 1.0f);
ep.setDiffuse(cot, false, "diffuse");
if (!is_shadeless) {
cot = getcol(ma->r * ma->ref, ma->g * ma->ref, ma->b * ma->ref, 1.0f);
ep.setDiffuse(cot, false, "diffuse");
}
// ambient
/* ma->ambX is calculated only on render, so lets do it here manually and not rely on ma->ambX. */
if (this->scene->world)
cot = getcol(this->scene->world->ambr * ma->amb, this->scene->world->ambg * ma->amb, this->scene->world->ambb * ma->amb, 1.0f);
else
if (is_shadeless)
cot = getcol(ma->amb, ma->amb, ma->amb, 1.0f);
else {
if (this->scene->world)
cot = getcol(this->scene->world->ambr * ma->amb,
this->scene->world->ambg * ma->amb,
this->scene->world->ambb * ma->amb, 1.0f);
ep.setAmbient(cot, false, "ambient");
}
ep.setAmbient(cot, false, "ambient");
// reflective, reflectivity
if (ma->mode & MA_RAYMIRROR) {
@ -253,8 +272,10 @@ void EffectsExporter::operator()(Material *ma, Object *ob)
// specular
if (ep.getShaderType() != COLLADASW::EffectProfile::LAMBERT) {
cot = getcol(ma->specr * ma->spec, ma->specg * ma->spec, ma->specb * ma->spec, 1.0f);
ep.setSpecular(cot, false, "specular");
if (!is_shadeless) {
cot = getcol(ma->specr * ma->spec, ma->specg * ma->spec, ma->specb * ma->spec, 1.0f);
ep.setSpecular(cot, false, "specular");
}
}
// XXX make this more readable if possible