how to add lights?

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
radomiro
Posts: 7
Joined: Fri Dec 26, 2008 3:34 am

how to add lights?

Post by radomiro »

hi,
in the first tutorial http://irrlicht.sourceforge.net/docu/example001.html
theres no lights right? (why not?, well ok)

here http://www.irrlicht3d.org/wiki/index.ph ... dMaterials
there is but im still getting this (see picture):

Image
the relevant code is this:

Code: Select all

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

	  	IAnimatedMesh* mesh = smgr->getMesh("../../media/rata.obj");

        if (!mesh) return 1;

        IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );

		ILightSceneNode* light = smgr->addLightSceneNode( 0, core::vector3df(0,400,-200), video::SColorf(0.3f,0.3f,0.3f), 1.0f, 1 );

        node->setMaterialFlag(EMF_LIGHTING, true);

		smgr->addCameraSceneNode(0, vector3df(100,10,0), vector3df(0,0,0));
?¿?¿?¿ some help please.
twilight17
Posts: 362
Joined: Sun Dec 16, 2007 9:25 pm

Post by twilight17 »

Are you loading a texture along with the model?

Is the light too far away?

Theres a lot of information (console output), etc that we would like :lol:
Post this userbar I made on other websites to show your support for Irrlicht!
Image
http://img147.imageshack.us/img147/1261 ... wernq4.png
Pumpkinpino
Posts: 3
Joined: Thu Dec 11, 2008 12:57 am

Post by Pumpkinpino »

Like stated above, I don't see any code applying a texture to your model unless you are just trying to see a gray untextured model to make sure the the lighting is working. A little more information on what you want the final product to look like would help.

-Greg
radomiro
Posts: 7
Joined: Fri Dec 26, 2008 3:34 am

Post by radomiro »

there is no texture but I expected a flat shading at least (since I added a light) , and that is not flat shading. (I tried changing EMF_LIGHTING for EMF_LIGHTING_GOURAUD too without getting other than the shown above).
You can see the coords. for the light (I tried other positions too). :(

What I expected is something like this (3dsmax renders, in the gouraud case):
Image
Or this in the flat shading case:
Image
Virion
Competition winner
Posts: 2148
Joined: Mon Dec 18, 2006 5:04 am

Post by Virion »

you have to apply texture.
radomiro
Posts: 7
Joined: Fri Dec 26, 2008 3:34 am

Post by radomiro »

Virion wrote:you have to apply texture.
:shock: ok, I'll try
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

No, vertex colors would also do with most mesh formats. However, the normals have to be correct for proper lighting. And LIGHTING is very different from GOURAUD as long as we talk about the SMaterial properties. please read the API docs on those first.
radomiro
Posts: 7
Joined: Fri Dec 26, 2008 3:34 am

Post by radomiro »

thanks, but if I was able to do the renders correctly in 3dsmax I guess the normals are right.
Ok, just tell me (please) if this is right or wrong:
(the sphere model is a 3ds generated with 3dsmax (standar sphere).

Code: Select all

createDevice( video::EDT_DIRECT3D9, dimension2d<s32>(800, 600), 16,
                        false, false, false, 0);

        if (!device)    return 1;

        device->setWindowCaption(L"Proyecto Zombie2.5D rata en Irrlicht test 1");

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

	  	IAnimatedMesh* mesh = smgr->getMesh("../../media/sphere.3ds");

	
        if (!mesh) return 1;

        IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );

    	node->setMaterialTexture( 0, driver->getTexture("../../media/text.bmp") );

		ILightSceneNode* light = smgr->addLightSceneNode( 0, core::vector3df(0,1500,0), video::SColorf(1.0f,1.0f,1.0f), 10.0f, 100 );

//smgr->setAmbientLight(video::SColorf(.5,.5,.5));

		light->setLightType(ELT_POINT);
		

       node->setMaterialFlag(EMF_LIGHTING, true);

		smgr->addCameraSceneNode(0, vector3df(-150,10,0), vector3df(0,0,0));

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

                smgr->drawAll();

				guienv->drawAll();

                driver->endScene();
        }
and Im getting this:
Image
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Code: Select all

smgr->addAnimatedMeshSceneNode( mesh );
Assuming the sphere mesh you're using is the Irrlicht provided sphere mesh, you are creating a sphere model that it is going to be located at the world coordinate system origin.

Code: Select all

smgr->addLightSceneNode( 0, core::vector3df(0,1500,0), video::SColorf(1.0f,1.0f,1.0f), 10.0f, 100 ); 
Then you create a white point light that is 1500 units away from the origin, and has a radius of 10 units. Things that are more than 10 units away from the light will not be affected by this light.

Have you tried creating a light that is closer to the model, or at least has a radius that will allow it to affect meshes that are in the scene?

Travis
radomiro
Posts: 7
Joined: Fri Dec 26, 2008 3:34 am

Post by radomiro »

vitek wrote:

Code: Select all

smgr->addAnimatedMeshSceneNode( mesh );
Assuming the sphere mesh you're using is the Irrlicht provided sphere mesh, you are creating a sphere model that it is going to be located at the world coordinate system origin.

Code: Select all

smgr->addLightSceneNode( 0, core::vector3df(0,1500,0), video::SColorf(1.0f,1.0f,1.0f), 10.0f, 100 ); 
Then you create a white point light that is 1500 units away from the origin, and has a radius of 10 units. Things that are more than 10 units away from the light will not be affected by this light.

Have you tried creating a light that is closer to the model, or at least has a radius that will allow it to affect meshes that are in the scene?

Travis
thanks, at last some light! (though flat, I'll check smoothing groups), good point about radious!

Image



EDIT: That was, thanks.
Maybe the radious thing could be enphatized in the tutorial.
Image
Post Reply