Yeah, I was confused myself. Maybe I can explain more clearly with some examples.
In blender, a mesh starts with no material, but one can be added. A material has diffuse/ambient/specular/emissive colors and shininess, among other things. Blender lets you set all these. They get exported into Collada and imported by Irrlicht as SMaterial settings. If the mesh has no material then these settings don't exist in the Collada file, so Irrlicht sets some default values for them.
ColorMaterial sets which of diffuse/ambient/specular/emissive is
overridden by vertex colors.
To demonstrate, I made a sphere with a vertex-painted pattern on it. Not a texture! I exported two versions, with and without a purple material (meaning, the diffuse color is purple).
Then I made a program that renders four variations of each. There is a white light above and bluish ambient lighting. I ran this app with three versions of Irrlicht: Before and after your fix, and after additional changes.
Irrlicht 1.8.1
This shows the original bug: vertex colors completely ignored.
First fix: Revision 4727
In the top row, vertex colors are applied correctly. ECM_DIFFUSE only shows the pattern on diffuse-lit areas. ECM_AMBIENT only shows it on the bottom (no, the light didn't get brighter, the sphere is just not being patterned on top). ECM_DIFFUSE_AND_AMBIENT gives the most natural result (which, on a side note, makes it seem like a saner default than ECM_DIFFUSE).
But in the bottom row, when a material is present, the pattern is missing. It has been completely overwritten by the purple diffuse color!
Second fix
This is after I commented out the code that overwrites the vertex colors. It's what I expect to happen. Well, mostly. I'm actually not sure why the AmbientColor is black on the bottom row, since ambient is set to 100% in blender. Of course, you see the dim blue again in the last two spheres, because AmbientColor is being (correctly) overridden there.
Now, does this
need to be fixed? I don't actually know. My original goal before I got so caught up was to combine vertex colors with
textures, so I guess I'll look into that next... But I hope this explains the problem I was perceiving.
In any case, I learned a lot about Irrlicht!
Source code
Code: Select all
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
IrrlichtDevice *device;
IVideoDriver *driver;
ISceneManager *smgr;
void addMesh(const char *path, vector3df pos, u8 colorMaterial){
ISceneNode *node = smgr->addMeshSceneNode(smgr->getMesh(path), 0, -1, pos);
node->setMaterialFlag(EMF_LIGHTING, 1);
node->getMaterial(0).ColorMaterial = colorMaterial;
}
void addVariations(const char *path, float yPos){
addMesh(path, vector3df(-4.5, yPos, 5), ECM_NONE);
addMesh(path, vector3df(-1.5, yPos, 5), ECM_DIFFUSE);
addMesh(path, vector3df(+1.5, yPos, 5), ECM_AMBIENT);
addMesh(path, vector3df(+4.5, yPos, 5), ECM_DIFFUSE_AND_AMBIENT);
}
int main(){
device = createDevice(EDT_OPENGL, dimension2d<u32>(512, 256));
driver = device->getVideoDriver();
smgr = device->getSceneManager();
smgr->addCameraSceneNode();
// white light from above
smgr->addLightSceneNode(0, vector3df(0,50,-10));
// bluish ambient
smgr->setAmbientLight(SColorf(0.1f,0.2f,0.3f));
addVariations("no_mat.dae", +1.5f);
addVariations("mat.dae", -1.5f);
while (device->run())
if (device->isWindowActive()) {
driver->beginScene(true, true, 0);
smgr->drawAll();
driver->endScene();
}
device->drop();
return 0;
}
Mesh files
Collada without material:
https://dl.dropboxusercontent.com/u/305 ... no_mat.dae
Collada with material:
https://dl.dropboxusercontent.com/u/305 ... st/mat.dae
Blender:
https://dl.dropboxusercontent.com/u/305 ... /mat.blend