Here is a simplified sample showing two scaled models with lighting in OpenGL without any problems.
Now when I add a third model of the tree, the lighting gets messed up in the first 2 models. It really obvious on the car, but you also tell that the faerie example model also becomes brighter.
Under direct3d, this does not occur, however, the leaf texture is no longer transparent properly.
I downloaded this model, so I don't know if the model is corrupt somehow. Though I'm more concerned with the effect on the other models of the scene, and don't know what could be causing it. The only thing I could think of other than some sorta state confusion is emmisive lighting, which is not present on any of the materials.
Here is the tree model: http://filebox.vt.edu/users/abacha/irr/oaktree.3DS
http://filebox.vt.edu/users/abacha/irr/BARK.PNG
http://filebox.vt.edu/users/abacha/irr/LEAF.PNG
and here is my code:
Code: Select all
#include <irrlicht.h>
#include <iostream>
using namespace irr;
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif
void setDirectional(scene::ILightSceneNode *light)
{
video::SLight lightData;
lightData = light->getLightData();
lightData.CastShadows=false;
lightData.Type= video::ELT_DIRECTIONAL;
light->setLightData(lightData);
}
void addLights(scene::ISceneManager* smgr)
{
scene::ILightSceneNode * light;
light = smgr->addLightSceneNode(0, core::vector3df(0,0,0),
video::SColorf(0.7f, 0.7f, 0.7f, 1.f), 2000.f, 0);
setDirectional(light);
light->setRotation(core::vector3df(40.f, 330.f, 0));
light = smgr->addLightSceneNode(0, core::vector3df(0,0,0),
video::SColorf(0.7f, 0.7f, 0.7f, 1.f), 2000.f, 0);
setDirectional(light);
light->setRotation(core::vector3df(20.f, 210.f, 0.f));
light = smgr->addLightSceneNode(0, core::vector3df(0,0,0),
video::SColorf(0.7f, 0.7f, 0.7f, 1.f), 2000.f, 0);
setDirectional(light);
light->setRotation(core::vector3df(20.f, 90.f, 0.f));
}
int main()
{
IrrlichtDevice* device = createDevice( video::EDT_OPENGL, core::dimension2d<s32>(640, 480),
16, false, false, false);
if (device == 0)
return 1; // could not create selected driver.
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
scene::IAnimatedMesh* carMesh = smgr->getMesh("../../media/Honda_Element.obj");
scene::ISceneNode* carNode = smgr->addMeshSceneNode(carMesh);
if (carMesh)
{
carNode->setMaterialFlag(video::EMF_LIGHTING, true);
carNode->setScale(core::vector3df(20.f, 20.f, 20.f));
carNode->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
}
/// Adding this block of code seems to undo the normalize normals for other nodes
scene::IAnimatedMesh* treeMesh = smgr->getMesh("../../media/oaktree.3ds");
scene::ISceneNode* treeNode = smgr->addMeshSceneNode(treeMesh);
if (treeNode)
{
treeNode->setPosition(core::vector3df(0,0,20));
treeNode->setMaterialFlag(video::EMF_LIGHTING, false);
treeNode->getMaterial(1).MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
treeNode->setScale(core::vector3df(0.2f, 0.2f, 0.2f));
}
scene::IAnimatedMesh* otherMesh = smgr->getMesh("../../media/faerie.md2");
scene::IAnimatedMeshSceneNode* otherNode = smgr->addAnimatedMeshSceneNode(otherMesh);
if (otherNode)
{
otherNode->setMaterialTexture(0, driver->getTexture("../../media/faerie2.bmp"));
otherNode->setPosition(core::vector3df(0,0,10));
otherNode->setMaterialFlag(video::EMF_LIGHTING, true);
otherNode->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
otherNode->setScale(core::vector3df(0.1f, 0.1f, 0.1f));
otherNode->setFrameLoop(160, 183);
}
/*
To be able to look at and move around in this scene, we create a first
person shooter style camera and make the mouse cursor invisible.
*/
scene::ICameraSceneNode * cam = smgr->addCameraSceneNodeFPS(0, 20.0f, 20.0f);
device->getCursorControl()->setVisible(false);
addLights(smgr);
while(device->run())
{
driver->beginScene(true, true, video::SColor(255,113,113,133));
smgr->drawAll(); // draw the 3d scene
device->getGUIEnvironment()->drawAll(); // draw the gui environment (the logo)
driver->endScene();
int fps = driver->getFPS();
}
/*
In the end, delete the Irrlicht device.
*/
device->drop();
return 0;
}