Request for a more flexible material system

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
Jedive
Posts: 146
Joined: Wed Apr 28, 2004 5:51 pm

Request for a more flexible material system

Post by Jedive »

The current material system in IrrLicht is cool to define material types easy, but it is not very flexible when you want to achieve advanced effects (For example, a lightmapped mesh with a sphere-mapped texture below the lightmap). I have here a proposal for a interesting material implementation.

Mainly, this new material would be compatible with the current one. It simply adds two new methods to ISceneNode: setTextureFlag() and setTextureBlend(), which allows to define the blend mode and flags for each texture layer individually, instead of using a global setMaterialType which affects the whole material. ISceneNode::setMaterialType() would be rewritten so, for the user, it will be exactly like it currently is, but internally, it should call different combinations of setTextureFlag() and setTextureType() to match the given material type.

It would be something like this:

void ISceneNode::setMaterialType(video::E_MATERIAL_TYPE newType)
This is the same method as we currently have. This would simply be a fast way of defining material types without worrying about the individual blend modes of each texture layer. Internally, this method should call the appropiate texture flag and blend modes to match the specified type.

void ISceneNode::setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue)
Also the same as the current method. Sets some flags which affects the whole material, like wireframe, cull mode, light & fog sensitivity, etc.

You would need to add EMF_VERTEX_ALPHA to tell the material that you want to use the vertex alpha defined in the mesh.

void ISceneNode::setTextureFlag(s32 textureLayer, video::E_TEXTURE_FLAG flag, bool newvalue)
This new method would be used to set the flags for the specified texture layer in the material. The values would be:

ETF_ALPHA_MAP The texture will be drawn transparent based on the alpha map contained. If the texture were loaded from a file format which does not support alpha information, an alpha channel should be generated based on the color info (darker=more transparent).
ETF_MASKED The parts of the texture which match the color of the mask defined in the texture will be drawn transparent.
ETF_SPHERE_MAP The texture will be used as a sphere map

void ISceneNode::setTextureBlend(s32 textureLayer, video::E_TEXTURE_BLEND blendMode)
This set the blend mode of one texture layer over the layer which is below it. For texture layer 0, it will define how it will blend over the background.

ETB_SOLID Texture will overwrite the layer below. Have in mind that if the layer uses ETF_ALPHA_MAP, the layer below it (or the background in the caseof layer 0) will still be visible.
ETB_ADD The layer will be added to the one below it (or the background).
ETB_MODULATE The color values of this layer will be multiplied with the one below it. Standard blend mode used for lightmaps.
ETB_MODULATE_2X Same as above, but multiplies by 2 the color values, giving brighter lightmaps.
ETB_MODULATE_4X Same as above, but multiplies by 4 the color values, giving much brighter lightmaps.
ETB_NORMAL The layer will be blended wiith the one below it using normal mapping. The layer below should contain the diffuse texture.

Probably more texture flags & blend modes should be added to these ones, I am not sure, but this gives a general idea of what would be a better material system for IrrLicht.

What do you think? (specially you, Niko :D)
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post by bal »

NX++'s material- and rendersystem will be (completely) rewritten. It would be better indeed to refactor those classes, as they are getting bloated.
General Tools List
General FAQ
System: AMD Barton 2600+, 512MB, 9600XT 256MB, WinXP + FC3
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

shaders, shaders, shaders
Image
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

It's right, the current material system is a little bit inflexible. Most of the additions could be achieved using shaders, but if would be nice that the basic things would be done using the fixed function pipeline, and the blending modes are another thing. A simple solution for this would be to create a new internal material renderer which can be modified using the things you mentioned. With that, it would be possible to create new more complex fixed function materials quite easily without breaking the interface. Just an idea.
Jedive
Posts: 146
Joined: Wed Apr 28, 2004 5:51 pm

Post by Jedive »

Cool niko. Then, will you make something like this for 0.9?
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

Maybe, I cannot promise. :)
Jedive
Posts: 146
Joined: Wed Apr 28, 2004 5:51 pm

Post by Jedive »

Awesome, do you like the model I explained above? :D
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

Yes, it would be a possiblity. But I'll have to think it over first. :)
Post Reply