i've read all the topics on this one, but couldnt find a solution that satisfies my needs. i need a material that is just a plain color (say, red), with lighting enabled. there seem to be two solutions to this:
a) vertex coloring. this is not an option for me, because i don't want to copy a mesh for each color. in particular, i want to have "changing" colors in realtime, so i'd have a seperate mesh for each frame, which sucks.
b) using emissive color. this works to an extent, but if there's no light, then the mesh gets rendered in plain red. i want it to be black/invisible if there's no light.
c) using ambient/diffuse color. this does not work - the mesh is always white. highlights and shadows are as expected.
i've setup a small example to reproduce the issue:
Code: Select all
#include <irrlicht/irrlicht.h>
using namespace irr;
using namespace core;
using namespace video;
using namespace scene;
// color constants
const SColor Black(255,0,0,0);
const SColor White(255,255,255,255);
const SColor Red(255,255,0,0);
const SColor Green(255,0,255,0);
int main(int argc, char** argv) {
// setup
IrrlichtDevice* device = createDevice(EDT_OPENGL);
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* scene = device->getSceneManager();
// left cube
ISceneNode* left = scene->addCubeSceneNode(15.0f);
left->setPosition(vector3df(-20.0f, 0.0f, 0.0f));
SMaterial& m_left = left->getMaterial(0);
m_left.DiffuseColor = Green;
m_left.AmbientColor = Green;
m_left.MaterialType = EMT_SOLID;
// right cube
ISceneNode* right = scene->addCubeSceneNode(15.0f);
right->setPosition(vector3df(20.0f, 0.0f, 0.0f));
SMaterial& m_right = right->getMaterial(0);
m_right.DiffuseColor = Black;
m_right.AmbientColor = Black;
m_right.SpecularColor = Black;
m_right.EmissiveColor = Red;
m_right.MaterialType = EMT_SOLID;
// light
ILightSceneNode* light = scene->addLightSceneNode(0, vector3df(0.0f, 50.0f, -50.0f), White, 50);
// camera
ICameraSceneNode* camera = scene->addCameraSceneNodeFPS();
camera->setPosition(vector3df(0.0f, 0.0f, -30.0f));
// device loop
while(device->run()) {
driver->beginScene(true, true, Black);
scene->drawAll();
driver->endScene();
}
return 0;
}
edit: i'm testing with irrlicht 1.6