textures disapearing with lighting

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
fisk
Posts: 9
Joined: Sun Jan 07, 2007 11:11 am

textures disapearing with lighting

Post by fisk »

Ive been banging my head on this for some days now and havent been able to find any documentation on it either : /

Im loading in a couple of .x models with a single texture each and it looks as expected with lighting flag off. I then add a point light to the scene and turn lighting on. this gives me a number of strange reactions. depending on which ones of the models I flag on, and in what order, either all models lose their texture and show as lighted whites, or some seemingly random models gets their nicely shaded textures. (not all though or I wouldnt be posting)

it feels like Im missing out on something fairly basic here, so any help is greatly appreciated. I isolated the problem in the code below, it should be runnable.

Code: Select all

#include <windows.h>
#include <irrlicht.h>

using namespace irr;
using namespace core;

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShw ) 
{
	IrrlichtDevice *device = createDevice( video::EDT_OPENGL,dimension2d<s32>(800, 600), 16, false, false, false, 0);

	video::IVideoDriver* driver = device->getVideoDriver();
	scene::ISceneManager* smgr = device->getSceneManager();
	gui::IGUIEnvironment* guienv = device->getGUIEnvironment();

	scene::IAnimatedMesh* model1 = smgr-> getMesh("model1.x");
	scene::ISceneNode* model1Node = smgr->addAnimatedMeshSceneNode(model1);

	scene::IAnimatedMesh* model2 = smgr-> getMesh("model2.x");
	scene::ISceneNode* model2Node = smgr->addAnimatedMeshSceneNode(model2);

	scene::IAnimatedMesh* model3 = smgr-> getMesh("model3.x");
	scene::ISceneNode* model3Node = smgr->addAnimatedMeshSceneNode(model3);

	model1Node->setMaterialFlag(video::EMF_LIGHTING, true);
	model2Node->setMaterialFlag(video::EMF_LIGHTING, true);
	model3Node->setMaterialFlag(video::EMF_LIGHTING, true);
	
	scene::ILightSceneNode* light1 = smgr->addLightSceneNode(0, vector3df(0.0f,100.0f,0.0f), video::SColorf(1.0f,1.0f,1.0f),150.0f,-1);

	smgr->addCameraSceneNodeFPS(0, 100.0f,500.0f,-1,0,0,false); 	

	while( device->run() )
	{
		driver->beginScene(true, true, video::SColor(255,100,101,140));

		smgr->drawAll();
		guienv->drawAll();

		driver->endScene();
	}

	device->drop();

	return 0;
}
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Give us a screenshot to see where your meshes are located and what's the actual view. You might also want to enable debug information which will give you the light range of your light scene node. It might also be that you put the light inside of a mesh which will only light inner frames, i.e. those which are usually not visible.
fisk
Posts: 9
Joined: Sun Jan 07, 2007 11:11 am

Post by fisk »

the light is positioned straight above the models and isnt enclosed, and considering the lighting is visible on the models when turned on I think it should be ok position and range wise, its just that the models renders without their texture.

heres the screenies
Image
all lighting flags set false
all models are showing with unshaded textures (as expected)

Image
all lighting flags set true
although barely visible, both model1 and model3 gets their textures shaded (unlike my main program where only model1 does, if any) while model2 seems to get shaded, but the texture isnt there anymore :S
sgt_pinky
Posts: 149
Joined: Sat Oct 14, 2006 11:20 am
Location: Melbourne, Australia

Post by sgt_pinky »

Have you checked the normal vectors of your polys on the models that don't shade to make sure they are facing outwards?
Intellectuals solve problems - geniuses prevent them. -- Einstein
#irrlicht on irc.freenode.net
fisk
Posts: 9
Joined: Sun Jan 07, 2007 11:11 am

Post by fisk »

hmm, Ill doublecheck. my .x-exporter is acting a bit weird.

but anyway theres something Im missing, dont know if its scenegraph related or order related or what it is, but I took some more screenies for you to see

Image
this one is with m1:false m2:true m3:true
as expected from earlier, asuming model2 is messed up somehow. 1st model is unshaded and the rest remains as before.

Image
m1:true m2:false m3:true
Im clueless here. why doesnt it render the textures? and why would changing the lighting flag to false on another model change how the others render?

Image
m1:true m2:true m3:false
same as above. setting the 3rd model's lighting to false somehow messed up how the 1st one rendered.

Im getting really confused :(
fisk
Posts: 9
Joined: Sun Jan 07, 2007 11:11 am

Post by fisk »

the normals are pointing outwards as they should on all models. the maya .x exporter Im using is 'XExporter 1.3'.

in the readme it tells me to: "Flip the Z-axis to convert Maya's right hand coordinate system to DirectX left hand."
Im using opengl but unsure what system it used I tested
Image
the previous screenies are with scale(1,1,1) and this one is with scale(1,1,-1)

I think the problem is code based tbh, but I thought Id add this as well in case Im missing something there.
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

FIRST) Try to completely reduce lighting.
In your code:

Code: Select all

scene::ILightSceneNode* light1 = smgr->addLightSceneNode(0, vector3df(0.0f,100.0f,0.0f), video::SColorf(1.0f,1.0f,1.0f),150.0f,-1);
make like this:

Code: Select all

scene::ILightSceneNode* light1 = smgr->addLightSceneNode(0, vector3df(0.0f,100.0f,0.0f), video::SColorf(1.0f,1.0f,1.0f),20.0f);
SECOND) For every material that have any texture set diffuse color to 0,0,0. I had the same problems with lighting. ( look here http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=18656 ).
fisk
Posts: 9
Joined: Sun Jan 07, 2007 11:11 am

Post by fisk »

yea, Ive been following your thread as well. I tried playing around with the materials' diffuse and specular color, and their shininess, as well as the light's specular color, but unfortunately none of it had any effect on the problem : /

if I could at least point out the problem I could try to do something about it, but since changing the property of one node seems to have a huge impact on some other node even though it afaik shouldnt, I really have no idea what to do.
coordinatepositions are ok, materials are ok, normals are ok, textures are seemingly ok since they work without light and at random with light, same thing with models apart from one of em which never renders correctly with light, although changing formats doesnt seem to have any effect on it.

hopefully its something obvious codewise that Im missing.
the above code is the complete testprogram for it, if you wanna try it with my meshes Ill load some up
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

yes. i can try to play around the code :)
but please -- zip the source with textures and models ( so i can run it and render ).
fisk
Posts: 9
Joined: Sun Jan 07, 2007 11:11 am

Post by fisk »

thanks man, appriciated

I added meshes, textures and the source file here: http://www.student.itn.liu.se/~davda952/meshes.rar
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

while i downloading the code -- you may look into my solving of the problem -- http://irrlicht.sourceforge.net/phpBB2/ ... 349#103349
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

fisk,

i could rich good result.
i found that for some reason irrlicht works with errors with your biljard_bord_mod.x mesh.

there is kind of memory leak in irrlicht i guess.
just try to add this line to your code:
model2Node->getMaterial(0).SpecularColor = video::SColor(50,50,50,50);
this line will control all the lighting for the scene ( all 3 objects ) -- but indeed as you see in code we changing properties for model2Node only! i do not know how it may touches model1Node and model3Node, but it does.

p.s.: try replace "50,50,50,50" with "150,150,150,150" -- you will get all object lighter -- very strange.
fisk
Posts: 9
Joined: Sun Jan 07, 2007 11:11 am

Post by fisk »

greenya thanks a bunch man, I tried changing specularcolor before but mustve used too big steps when testing around with it. I also added some emissivecolor now as you mentioned in your other post and thats what made me notice it worked ^^

however I still cant change this node independant of the others by using modelNode->getMaterial(0). Ill see if I can set the materials through the driver instead tomorrow, Ill keep ya posted
fisk
Posts: 9
Joined: Sun Jan 07, 2007 11:11 am

Post by fisk »

the problem was in the .x importer in irrlicht and the exporter in maya. the exporter only handled 'blinn' and 'lambert' materialtypes which in irrlicht means that blinn materials would recieve a vastly bigger shininess.

this can either be resolved by reexporting the model with lambert material or manually editing the last lines of the .x file from this:

Code: Select all

Material {
0;0;0;0;;
0.3;
0.5;0.5;0.5;;
0;0;0;;
to this:

Code: Select all

Material {
0;0;0;0;;
0;
0;0;0;;
0;0;0;;
or setting the materials shininess to 0

Code: Select all

node->getMaterial(0).Shininess = 0.0f;
hope this helps anyone having the same problem I had.

ps. still havent solved why changing attributes on one node can effect another completely different node. ds.
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

cool.. a test case for the opengl material problem some people have been having, thanks for sharing :)

edit:
strange.. the lighting affecting another node's texture problem seems to be something to do with GL_EXT_separate_specular_color.

for the moment, if you don't need specular highlights on materials with textures, and you need to mix lighting modes, put this at the top of COpenGLDriver.cpp after the #ifdef _IRR_COMPILE_WITH_OPENGL_ line

Code: Select all

#ifdef GL_EXT_separate_specular_color
#undef GL_EXT_separate_specular_color
#endif
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Post Reply