I created a custom scene node that simply draws a textured plane with DrawIndexedTriangleList. All I want is flat shading. When I just set colors for each of the vertices, everything looks fine. However, when I create and assign a texture to a material for the plane, the texture draws correctly but it gets totally black when I move the camera toward the side or slightly away from it. Setting Gouraud to false doesn't do anything. Any ideas? This only happens in Direct3d. In OpenGL and the software renderer, it *only* does flat shading - turning on Gouraud doesn't do anything.
Thanks,
bigfish
Can't disable Gouraud shading!
Are you providing normals for your vertices? The following code works just fine for me will all of the drivers.
Travis
Code: Select all
#include <irrlicht.h>
#pragma comment(lib, "Irrlicht.lib")
using namespace irr;
struct setMaterialFlag
{
setMaterialFlag(video::E_MATERIAL_FLAG flag, bool value)
: Flag(flag)
, Value(value)
{
}
void operator()(scene::ISceneNode* node)
{
node->setMaterialFlag(Flag, Value);
}
video::E_MATERIAL_FLAG Flag;
bool Value;
};
template< class Fun >
void ISceneNode_applyToScene(Fun function, scene::ISceneNode* node)
{
function(node);
core::list<scene::ISceneNode*>::Iterator it = node->getChildren().begin();
for (; it != node->getChildren().end(); ++it)
ISceneNode_applyToScene(function, *it);
}
template< class Fun >
void ISceneNode_applyToScene(Fun function, scene::ISceneManager* smgr)
{
ISceneNode_applyToScene(function, smgr->getRootSceneNode());
}
int main()
{
// create device and exit if creation failed
IrrlichtDevice* device =
createDevice(video::EDT_DIRECT3D8, core::dimension2d<s32>(1024, 768));
if (device == 0)
return 1; // could not create selected driver.
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
// load the scene
scene::ILightSceneNode* light = smgr->addLightSceneNode();
if (light)
{
scene::ISceneNode* bill = smgr->addBillboardSceneNode(light);
bill->setMaterialTexture(0, driver->getTexture("../../media/particlewhite.bmp"));
bill->setMaterialFlag(video::EMF_LIGHTING, false);
bill->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
scene::ISceneNodeAnimator* animator = smgr->createFlyCircleAnimator(core::vector3df(0, 10, 0), 40, .001f, core::vector3df(0, .707, .707));
light->addAnimator(animator);
animator->drop();
}
scene::IAnimatedMesh* animatedMesh = smgr->addHillPlaneMesh("plane", core::dimension2df(10, 10), core::dimension2di(8, 8));
if (animatedMesh)
{
smgr->addMeshSceneNode(animatedMesh->getMesh(0));
}
smgr->addSphereSceneNode(10);
ISceneNode_applyToScene(setMaterialFlag(video::EMF_GOURAUD_SHADING, false), smgr);
// add a user controlled camera
scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(0, 30.f, 80.f);
camera->setPosition(core::vector3df(0, 40, 80));
camera->setTarget(core::vector3df(0, 0, 0));
// and draw everything.
while(device->run())
{
if (device->isWindowActive())
{
if (driver->beginScene(true, true, video::SColor(0,200,200,200)))
{
smgr->drawAll();
driver->endScene();
}
}
}
device->drop();
return 0;
}