I'm trying to come up the learning curve on Ogre. Great work everyone, this is really an impressive library!
I have worked with a couple of other closed-source libraries on past projects. Both had material systems, but they used a different level of abstraction. You could define an "effect" (using CgFX or D3DX Effects) which provided the technique and passes. Then you could define one or more "materials", which referenced the effect and added parameters values to influence the appearance.
For example, I might have a "water" effect which defines the render states and a vertex program. Then a could have several materials like "choppy water", "smooth water", etc. which set variables to control wave height, color, and the like.
Is it possible to do something like this with Ogre's materials? After a quick read through the docs and code I'm not sure. Say I have 20 cars, each using a two-tone glossy metal effect, but with different base colors. If I want to tweak the effect, I would have to change all 20 scripts, right?
Thanks for the clarification.
Clarification on Materials?
-
sim8
- Gnoblar
- Posts: 9
- Joined: Mon Dec 06, 2004 11:13 pm
- Contact:
- tuan kuranes
- OGRE Retired Moderator

- Posts: 2653
- Joined: Wed Sep 24, 2003 8:07 am
- Location: Haute Garonne, France
- x 4
- Contact:
Yes, same here : "one or more "materials", which referenced the effect and added parameters values to influence the appearance. "
Just to make sure, the 20 materials can share the same effect, but having different parameters.
So you'd end up wiht 20 mats, all referencing same effects and textures, but with different parameters.
This can also be done by Code, having a "Water" or "Car" Object that tweak his material effects parameters upon its state, as shaders parameters can be changed during run-time.
It's a little early, are you just having hands on Ogre, but can you give some infos, comparison with other commercial engines used (and possibly their names.) ?
[edit]typos and final question[edit]
Just to make sure, the 20 materials can share the same effect, but having different parameters.
So you'd end up wiht 20 mats, all referencing same effects and textures, but with different parameters.
This can also be done by Code, having a "Water" or "Car" Object that tweak his material effects parameters upon its state, as shaders parameters can be changed during run-time.
It's a little early, are you just having hands on Ogre, but can you give some infos, comparison with other commercial engines used (and possibly their names.) ?
[edit]typos and final question[edit]
- sinbad
- OGRE Retired Team Member

- Posts: 19269
- Joined: Sun Oct 06, 2002 11:19 pm
- Location: Guernsey, Channel Islands
- x 67
- Contact:
To get a real grasp of all the options available, you have to read the Material section of the manual. http://www.ogre3d.org/docs/manual/manual_16.html#SEC25
-
sim8
- Gnoblar
- Posts: 9
- Joined: Mon Dec 06, 2004 11:13 pm
- Contact:
I did read the manual, and my understanding is that Ogre works like this:
material -> program
Where the material contains all of the rendering states and parameter values. What I would like to have is this:
material -> effect -> program
Call things what you will. In this case "effect" contains rendering states and default parameters. "Material" contains more specific parameters. This is confusing to explain.
Say I have 20 cars. I have a shader that can do diffuse and environment mapping. I create an Ogre material with all of the renderstates and default textures. I want to use the same environment map for all of the cars, but I want to specify a different diffuse map for each car. If I am reading the docs correctly, I would have to create 20 material scripts that are identical except for the diffuse map. And if I wanted to change the environment map, I would have to change all 20 material scripts.
I would like to add another layer of abstraction, and be able to override parameters for a particular object (or group of objects). Is it possible to do this with the material scripts, or is this something I would have to code up myself (not a big deal, just trying to avoid unnecessary work).
To tuan kuranes: I'm just scratching the surface of Ogre, I don't know enough to compare it to anything yet.
material -> program
Where the material contains all of the rendering states and parameter values. What I would like to have is this:
material -> effect -> program
Call things what you will. In this case "effect" contains rendering states and default parameters. "Material" contains more specific parameters. This is confusing to explain.
Say I have 20 cars. I have a shader that can do diffuse and environment mapping. I create an Ogre material with all of the renderstates and default textures. I want to use the same environment map for all of the cars, but I want to specify a different diffuse map for each car. If I am reading the docs correctly, I would have to create 20 material scripts that are identical except for the diffuse map. And if I wanted to change the environment map, I would have to change all 20 material scripts.
I would like to add another layer of abstraction, and be able to override parameters for a particular object (or group of objects). Is it possible to do this with the material scripts, or is this something I would have to code up myself (not a big deal, just trying to avoid unnecessary work).
To tuan kuranes: I'm just scratching the surface of Ogre, I don't know enough to compare it to anything yet.
- tuan kuranes
- OGRE Retired Moderator

- Posts: 2653
- Joined: Wed Sep 24, 2003 8:07 am
- Location: Haute Garonne, France
- x 4
- Contact:
yes. effects (shaders) can be defined outside the material but referenced into.I would have to create 20 material scripts that are identical except for the diffuse map. And if I wanted to change the environment map, I would have to change all 20 material scripts.
Texture (more precisely texture unit states) are defined in material, and cannot be defined outside.
But it's easy to do a "template" material code instantiation :
Code: Select all
MaterialPtr templateMaterial = MaterialManager::getSingleton().getByName(String ("CarTemplate"));
// Create a new Materialusing the template
MaterialPtr myMaterial = templateMaterial->clone("CarMAt15");
// load the texture
String diffmapname = "mydiffusemap15.png";
TexturePtr Texture = TextureManager::getSingleton().load (diffmapname , ResourcesgroupName, TEX_TYPE_2D, 7, 1.0f);
// assign this texture to the material mMaterial->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName (diffmapname);
-
sim8
- Gnoblar
- Posts: 9
- Joined: Mon Dec 06, 2004 11:13 pm
- Contact: