How to use material colors?
How to use material colors?
I am trying to improve material support for my anim8or importer. Anim8or's materials have ambient, diffuse, specular, and emissive. It was pretty easy to set those colors but how do I get irrlicht to use all of them. Also, how can I set the factor for how much each impacts the color of the mesh.
Re: How to use material colors?
What I have noticed, is that in irrEdit when loading a model with the color of the material a dark instead of full white, the texture of the material is darkened, however, changing the color of the property from the editor does not seem to affect it, giving me to understand that the changes need to restart the application of irrlicht, of course, I do not know if this is the same for the new versions of irrlicht
**
If you are looking for people with whom to develop your game, even to try functionalities, I can help you, free. CC0 man.
**
If you are looking for people with whom to develop your game, even to try functionalities, I can help you, free. CC0 man.
**
Re: How to use material colors?
Hm, I had similar question recently here: viewtopic.php?t=53033
But in short - these are all colors for the lighting model. So they _only_ are use when lighting is enabled (SMaterial::Lighting = true). Otherwise the only colors used by default are vertex colors and texture values (for diffuse).
When you enable lighting and have no lights in the scene then only Emissive will have an effect. All other values are factors for the available light.
Diffuse (also called albedo in other tools): What you typcially think of as the color of an object.
Ambient: Is a simplification for environment light. Because reflections of light were too hard to calculate in the past people generally assumed some basic light reflected everywhere. Often set to the sky color. The object ambient is then multiplied by that and in most cases all objects have the same factor here. Note that you can set the ambient light source in 2 way in Irrlicht - per light and per scene. I don't know what this is about right now - maybe they are added or something.
Specular: Color for highlights. Generally set to white - except maybe for metals.
Emissive: Self-lighting. So when you have no light otherwise in the scene it will still add that color to the polygon. In more modern pipelines this is sometimes used for area-lights - so it really emits light. In Irrlicht it won't be used as light-emitter.
How material colors interact with vertex colors is controlled via the ColorMaterial parameter of SMaterial. Check the E_COLOR_MATERIAL enum for options.
For anything more advanced than this basic color model you will have to write your own shaders.
Note: For a quick test check the Material Viewer example - it allows to play around with most of those settings.
But in short - these are all colors for the lighting model. So they _only_ are use when lighting is enabled (SMaterial::Lighting = true). Otherwise the only colors used by default are vertex colors and texture values (for diffuse).
When you enable lighting and have no lights in the scene then only Emissive will have an effect. All other values are factors for the available light.
Diffuse (also called albedo in other tools): What you typcially think of as the color of an object.
Ambient: Is a simplification for environment light. Because reflections of light were too hard to calculate in the past people generally assumed some basic light reflected everywhere. Often set to the sky color. The object ambient is then multiplied by that and in most cases all objects have the same factor here. Note that you can set the ambient light source in 2 way in Irrlicht - per light and per scene. I don't know what this is about right now - maybe they are added or something.
Specular: Color for highlights. Generally set to white - except maybe for metals.
Emissive: Self-lighting. So when you have no light otherwise in the scene it will still add that color to the polygon. In more modern pipelines this is sometimes used for area-lights - so it really emits light. In Irrlicht it won't be used as light-emitter.
How material colors interact with vertex colors is controlled via the ColorMaterial parameter of SMaterial. Check the E_COLOR_MATERIAL enum for options.
For anything more advanced than this basic color model you will have to write your own shaders.
Note: For a quick test check the Material Viewer example - it allows to play around with most of those settings.
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: How to use material colors?
Thanks for the info. I will probably need to write a custom shader for it but I found a simple solution that seems to be working for now. I set the vertex color for the mesh to the diffuse color and set shineniess to 128 minus the factor*100 (This seems to be the closest to how anim8or's material looks at a factor of 1). I also set emissive to 0 and just decided to ignore this value for anim8or meshes. I can adjust it after import if I really needed to.
If there is a texture set for the mesh, I decided to just set the vertex color to (255,255,255,255) since anim8or does not seem to use the diffuse color when a texture is set but it will still use specular color for highlights. I have only tested it on a few models so I am not 100% sure about that and anim8or's documentation on its format does not mention how these colors are used.
Basically, this page describes how different values should affect the mesh in anim8or but its not 1 to 1 with how irrlicht uses these values: https://anim8or.com/learn/manual/9_materials.html
I might create a template with some pre-built materials and have custom built-in materials that are used when ever those materials are used in anim8or.
If there is a texture set for the mesh, I decided to just set the vertex color to (255,255,255,255) since anim8or does not seem to use the diffuse color when a texture is set but it will still use specular color for highlights. I have only tested it on a few models so I am not 100% sure about that and anim8or's documentation on its format does not mention how these colors are used.
Basically, this page describes how different values should affect the mesh in anim8or but its not 1 to 1 with how irrlicht uses these values: https://anim8or.com/learn/manual/9_materials.html
I might create a template with some pre-built materials and have custom built-in materials that are used when ever those materials are used in anim8or.
Re: How to use material colors?
Yeah, same meaning in general, thought calculations might differ slightly. Note that Rough value can probably be translated to Shininess (my guess would be approximately Shininess = ((101-Rough)-0.5)*1.28). Never heard about Brilliance parameter, not sure about that one - maybe related to metallicity in PBR?
Emissive should be directly useable. Except maybe some linear to srgb conversion (don't know which color space Anim8tor uses).
I just noticed DiffuseColor in Irrlicht material is completely ignored (at least in OpenGL, didn't try others) by default due to ColorMaterial being set to ECM_DIFFUSE. Which means diffuse color is coming from vertices. And when that value is set to ECM_NONE instead - then material DiffuseColor is used together with textures (multiplied I think, so only can make texture darker). So pure texture for diffuse means, depending on ColorMaterial parameter, that either vertex color or the material DiffuseColor has to be all 255.
Note that all those values should also depend on the lighting you have in Anim8tor. Thought it might have some "standard" lighting.
Emissive should be directly useable. Except maybe some linear to srgb conversion (don't know which color space Anim8tor uses).
I just noticed DiffuseColor in Irrlicht material is completely ignored (at least in OpenGL, didn't try others) by default due to ColorMaterial being set to ECM_DIFFUSE. Which means diffuse color is coming from vertices. And when that value is set to ECM_NONE instead - then material DiffuseColor is used together with textures (multiplied I think, so only can make texture darker). So pure texture for diffuse means, depending on ColorMaterial parameter, that either vertex color or the material DiffuseColor has to be all 255.
Note that all those values should also depend on the lighting you have in Anim8tor. Thought it might have some "standard" lighting.
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm