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.
Post Reply
PuG
Posts: 13
Joined: Wed Mar 05, 2008 12:11 pm

Materials

Post by PuG »

Hi! I have object file (.obj) with a UV map and two defined surfaces (TempSurface & Floor). My question is how can I apply textures specifically to these surface without applying globally?

My IRRSCENE file object currently is as the following:

Code: Select all

	<node type="mesh">

		<attributes>
			<string name="Name" value="" />
			<int name="Id" value="-1" />
			<vector3d name="Position" value="3.333332, 1.666666, -3.333332" />
			<vector3d name="Rotation" value="0.000000, 0.000000, 0.000000" />
			<vector3d name="Scale" value="1.000000, 1.000000, 1.000000" />
			<bool name="Visible" value="true" />
			<enum name="AutomaticCulling" value="box" />
			<int name="DebugDataVisible" value="0" />
			<bool name="IsDebugObject" value="false" />
			<string name="Mesh" value="Data\\scenes\\test.obj" />
			<bool name="ReadOnlyMaterials" value="false" />
		</attributes>

		<materials>
			<attributes>
				<enum name="Type" value="solid" />
				<color name="Ambient" value="ff333333" />
				<color name="Diffuse" value="ffcccccc" />
				<color name="Emissive" value="00000000" />
				<color name="Specular" value="ffffffff" />
				<float name="Shininess" value="0.000000" />
				<float name="Param1" value="0.000000" />
				<float name="Param2" value="0.000000" />
				<texture name="Texture1" value="Data\\scenes\\temp256.png" />
				<texture name="Texture2" value="" />
				<texture name="Texture3" value="" />
				<texture name="Texture4" value="" />
				<bool name="Wireframe" value="false" />
				<bool name="GouraudShading" value="true" />
				<bool name="Lighting" value="false" />
				<bool name="ZWriteEnable" value="true" />
				<int name="ZBuffer" value="1" />
				<bool name="BackfaceCulling" value="true" />
				<bool name="FogEnable" value="false" />
				<bool name="NormalizeNormals" value="false" />
				<bool name="BilinearFilter1" value="true" />
				<bool name="BilinearFilter2" value="true" />
				<bool name="BilinearFilter3" value="true" />
				<bool name="BilinearFilter4" value="true" />
				<bool name="TrilinearFilter1" value="false" />
				<bool name="TrilinearFilter2" value="false" />
				<bool name="TrilinearFilter3" value="false" />
				<bool name="TrilinearFilter4" value="false" />
				<bool name="AnisotropicFilter1" value="false" />
				<bool name="AnisotropicFilter2" value="false" />
				<bool name="AnisotropicFilter3" value="false" />
				<bool name="AnisotropicFilter4" value="false" />
				<enum name="TextureWrap1" value="texture_clamp_repeat" />
				<enum name="TextureWrap2" value="texture_clamp_repeat" />
				<enum name="TextureWrap3" value="texture_clamp_repeat" />
				<enum name="TextureWrap4" value="texture_clamp_repeat" />
			</attributes>
		</materials>
	</node>
I assume I would need to define two materials, but where abouts do I set the object surface definition for the material to apply to.?

Also ontop of that, if I export two UV sets, one for the textures and a second for the lightmap, is their an area to allow me to define which uv set is used for the lighting pass texture?

Yes I have searched the forums, :) and short of finding 85 pages ive not found any anything directly related (though im sure its their - somewhere), and nothing on the Wiki?

Best Regards!
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

.obj files don't support two UV maps per material. So you cannot do that. Materials are assigned just one after the other. So if your loaded mesh has two meshbuffers you can have two material sections which are assigned to the mesh buffers (one for each, first material to first meshbuffer).
The meshbuffer creation is driven by the obj file and its mtl specification. Only if you have created two materials there, and assigned the proper vertices to those materials/meshbuffers you will get the desired results.
PuG
Posts: 13
Joined: Wed Mar 05, 2008 12:11 pm

Post by PuG »

Thank you for the reply - ignoring the 2nd UV channel issue, its now working as you mentioned, all I had todo was to duplicate the "attributes".

Does this apply specifically to the .obj file, or all formats? its seems concerning that you can't attach a attribute to a surface name - if for instance went back and edited the model, added new surface then I would possibly end up having to resort the materials to match.

I was only using Object for the time being, as when I bring in a .dae file it comes up with 0 polygons (in irrEdit) - but should I get it working, I assume then texture 2 is for the 2nd channel (e.g. Lightmap), but if change "type" to lightmap_m4 how does that work with parallax or normal mapping?

Thanks for the help.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

There is no parallax with lightmaps, but it also seems a little strange, because lightmaps are for static simple lighting, while parallax is for highly dynamic and pretty exact lighting.
You can easily put the material definitions into the obj file, which will allow for a proper binding of materials and buffers without problems when renaming or rearranging the mesh. For a proper integration into irrEdit this would need an obj exporter, though.
The Collada problems might be due to version problems, most tools export Collada 1.4, which will only be supported beginning with Irrlicht 1.5 (and irrEdit thereafter), so you have to wait a little more. But then the second UV map will be supported.
PuG
Posts: 13
Joined: Wed Mar 05, 2008 12:11 pm

Post by PuG »

Seems slightly bizarre? you could still have non-dynamic parallax mapping, calculated from either a node or from where the light source was/is? also what about using a sun object placed in the scene?

So from what I read, by using a the advantages of a lightmap on your geometry, your also removing any form of surface shading (transparency's) which is a shame?

Thats means if you have a lovely building, with lightmap, and then an object without, but a parallax or normal instead you would end up with a horrid diffuse jump?

Just seems to be ruling out a number of options, which if supported would allow allot more flexibility.

Is their any way to to define a second (or more) surface shader? could you not just have a "type" for each texture channel?

Right, sounds good in respect to Collada.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You can have separate objects with any of those material types. Also, there are lightmaps which allow for dynamic lighting (just not per-pixel). Transparency is lost, that's right. And yes, a per-layer material would help in these cases. However, this won't come in before Irrlicht 2.0 (with the current schedule at least).
Of course you can always add new material renderers or pixel shaders which do the necessary shading for you.
PuG
Posts: 13
Joined: Wed Mar 05, 2008 12:11 pm

Post by PuG »

Ok, thats a shame - as you mentioned, dynamic lightmaps & a parallax would be a good example.

I'm not sure how difficult it would be to extend.
Post Reply