Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGaia Clary <gaia.clary@machinimatrix.org>2015-03-05 20:44:04 +0300
committerGaia Clary <gaia.clary@machinimatrix.org>2015-03-05 20:44:04 +0300
commit04b0a9f4b885e8e3b0b3207f3b3cda74b936df3e (patch)
tree30f71912565f7084245503713393ef29523af940 /source/blender/collada
parent23af8984bb6be579115a4b0e81b65f8cb5a31e83 (diff)
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
Diffstat (limited to 'source/blender/collada')
-rw-r--r--source/blender/collada/DocumentImporter.cpp22
-rw-r--r--source/blender/collada/EffectExporter.cpp73
2 files changed, 67 insertions, 28 deletions
diff --git a/source/blender/collada/DocumentImporter.cpp b/source/blender/collada/DocumentImporter.cpp
index 462b7b6f200..655e01a6dad 100644
--- a/source/blender/collada/DocumentImporter.cpp
+++ b/source/blender/collada/DocumentImporter.cpp
@@ -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;
}
diff --git a/source/blender/collada/EffectExporter.cpp b/source/blender/collada/EffectExporter.cpp
index 13dc1eda580..f0ef0cb7c20 100644
--- a/source/blender/collada/EffectExporter.cpp
+++ b/source/blender/collada/EffectExporter.cpp
@@ -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