Adding materials

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.
ProjectIRR
Posts: 21
Joined: Mon Oct 26, 2009 3:21 am

Adding materials

Post by ProjectIRR »

I exported a mesh from Maya in .obj and got it to load however the materials didn't. Is there a material attach class I need to use, and is this the kind of thing I should search the hierarchy for, or is it ok to ask here?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

The materials for .obj files are saved into a .mtl file. If this file is in the same directory as the .obj then Irrlicht should load it.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
ProjectIRR
Posts: 21
Joined: Mon Oct 26, 2009 3:21 am

Post by ProjectIRR »

I thought that might be the case but here's what's happening:

How it looks in the maya:
Image

How it looks in maya rendered with materials:
Image



The code from example 1 used to load the mesh: (The only other change was the render engine to OpenGL.)

Code: Select all

	/*
	To let the mesh look a little bit nicer, we change its material. We
	disable lighting because we do not have a dynamic light in here, and
	the mesh would be totally black otherwise. Then we set the frame loop,
	such that the predefined STAND animation is used. And last, we apply a
	texture to the mesh. Without it the mesh would be drawn using only a
	color.
	*/
	if (node)
	{
		node->setMaterialFlag(EMF_LIGHTING, false);
		node->setMD2Animation(scene::EMAT_STAND);
		node->setMaterialTexture( 0, driver->getTexture("../../media/buildingtest2.obj") );
	}
Showing I have both of the buildingtest2.mtl and .obj in the media folder:
Image

The result in the program:
Image

Any idea why it's not loading? (This is a rather crucial step for me.)
Virion
Competition winner
Posts: 2148
Joined: Mon Dec 18, 2006 5:04 am

Post by Virion »

the material has already loaded (therefore you can see the colors). the thing that you don't see now is the lighting because you had it disabled.
node->setMaterialFlag(EMF_LIGHTING, false);
what you should do now is
1. enable lighting
2. create a light scene node
ProjectIRR
Posts: 21
Joined: Mon Oct 26, 2009 3:21 am

Post by ProjectIRR »

Oh ok :) and that will give me the depth I need? (It looks like I could have 2 outlines of objects loaded, you can't tell the seams at all.) Ok, I'll give that a try and continue with the tutorials, thank you!
ProjectIRR
Posts: 21
Joined: Mon Oct 26, 2009 3:21 am

Post by ProjectIRR »

I added a light scene node but it still looks like it only carries over the color information. The shaders that give it a nice look didn't. Do you have to add sharers in personally and material is only flat color?
Image
Last edited by ProjectIRR on Sat Oct 31, 2009 2:00 am, edited 1 time in total.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

I don't know what sharers are (or do you mean shaders?). Probably it's something which can't be exported. Maybe play around with specular settings - the effect at the door could maybe be possible with those.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
ProjectIRR
Posts: 21
Joined: Mon Oct 26, 2009 3:21 am

Post by ProjectIRR »

(Sorry, I often just accept my spell check's changes, it doesn't know shader :) )
I'm not quite sure how to mess with the specular, not in maya, because it's not exporting anything but flat color, so I suppose I'd have to code it in, and I'm not sure how to do that. So your saying for anything besides flat color I'm going to have to code shaders...?

Is it this way with Blender and Max?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Specular-reflection are part of the material settings of your mesh and are probably multiplied with the specular part of the light. Maybe just try changing SpecularColor and Shininess values in the material. I don't know how to export such settings from Maya. In the mtl file the specular color settings are the Ks values and the shininess is the Ns value (range is 0-1000 in mtl files) so you can change those value there directly or check how they change depending on your export settings. I think specular colors are per-polygon, so the effect will probably only work if your door has many polygons.

For nicer effects you will have to use shaders. Maybe someone else can help you there as that's not my area of expertise.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
ProjectIRR
Posts: 21
Joined: Mon Oct 26, 2009 3:21 am

Post by ProjectIRR »

Shaders can do the same thing though, and can be applied to multiple objects via code, correct?
Virion
Competition winner
Posts: 2148
Joined: Mon Dec 18, 2006 5:04 am

Post by Virion »

try directional light maybe it will look closer to your maya shots.
ProjectIRR
Posts: 21
Joined: Mon Oct 26, 2009 3:21 am

Post by ProjectIRR »

I'm not familiar with directional lighting, is it a scene node?

Does no one here use maya, what programs do people use, because this engine isn't very Maya friendly at all. I'll have to hit some maya forums and see if it can export more than flat color.

Can shaders do all this and more? (make it look like the attributes I set in maya?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Shaders could probably do that, but I don't know of any way to export such settings from a 3D modeller and get the corresponding shader code in the engine automatically.

Also Maya does not have to do realtime, modeling realtime graphics is just different from modeling render-graphics used for example in movies. Finding ways around that to make games still look good is part of the job. For example you could render the effect into a texture. Which means light would be static and each copy of the node would look similar. So a better solution is often that you place the nodes first and then render a lightmap - light is still static but nodes look different now. That's actually the solution we used (and then we hacked up the .obj format to support this: http://www.michaelzeilfelder.de/irrlicht.htm#Lightmaps).

Or maybe you find even ways to write an exporter or some plugin which allows you to automatically generate shadercode for certain settings, but I can't help you much there.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Virion
Competition winner
Posts: 2148
Joined: Mon Dec 18, 2006 5:04 am

Post by Virion »

ProjectIRR wrote:I'm not familiar with directional lighting, is it a scene node?

Does no one here use maya, what programs do people use, because this engine isn't very Maya friendly at all. I'll have to hit some maya forums and see if it can export more than flat color.

Can shaders do all this and more? (make it look like the attributes I set in maya?
it's because in Maya you are just applying a flat color to it therefore it turns out to be... flat color. in Maya the material is called "shader" and that's exactly the thing you'll need. it's not that irrlicht isn't "MAYA FRIENDLY" (i'm maya user too) but the exporter does not export the whole shader and you'll need to write it yourself.
ProjectIRR
Posts: 21
Joined: Mon Oct 26, 2009 3:21 am

Post by ProjectIRR »

Phew! So Irrlicht isn't supposed to pick up the shaders from the .obj, just the flat picture texture?


btw, when you were talking about lightmaping, were you talking about baking the texture in maya while it had the shader, or in another program with shaders? Do you have an example of that looks?
Post Reply