Generalization for material files

What it says on the tin: a place to discuss proposed new features.
Post Reply
User avatar
Blakharaz
Gnoblar
Posts: 19
Joined: Wed Jun 02, 2004 8:51 pm
Location: Potsdam, Germany

Generalization for material files

Post by Blakharaz »

Hi,

in the example for bumpmapping the material files contain a lot of text for all the fallbacks. If I define more textures with bumpmapping I have to copy the whole file an just exchange the texture and normalmap files. I would suggest something like a macro system with a preprocessor which expands the macros to the correct material syntax.
So I just have to write something like "bumpmapping enabled normalmap=nm.png texture=tex.png", not two pages of repeating text like now.
Is there someone working on a feature like this? I'm not experienced with parsers. My workaround for our project would be a generator tool.
Coder in the Pantheon team - creators of Rastullahs Lockenpracht
User avatar
:wumpus:
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3067
Joined: Tue Feb 10, 2004 12:53 pm
Location: The Netherlands
x 1

Post by :wumpus: »

I'd suggest a generator tool too; or even better, a full GUI editor :)
User avatar
Blakharaz
Gnoblar
Posts: 19
Joined: Wed Jun 02, 2004 8:51 pm
Location: Potsdam, Germany

Post by Blakharaz »

But maybe a macro processor could be useful for other examples.

My generator tools are usually fast hacked java applications.
Coder in the Pantheon team - creators of Rastullahs Lockenpracht
User avatar
Cyberdigitus
Halfling
Posts: 55
Joined: Thu Mar 04, 2004 7:08 pm
Location: Belgium
Contact:

Post by Cyberdigitus »

i suppose that batch or macro tool would create the material scripts? That will still give you a material per thing that is different, like the texture in your example...

You could also create just one material, and use a AutoGpuParameter to use the given texture. That way you have just one material. I suppose that works only with shader based materials though.
. . .
User avatar
Blakharaz
Gnoblar
Posts: 19
Joined: Wed Jun 02, 2004 8:51 pm
Location: Potsdam, Germany

Post by Blakharaz »

How could I do that? Don't I need one material per texture?
Could you please give an example? Let's say I have a chair, a person and a sword with textures tex_chair.png, tex_person.png, tex_sword.png and normal maps nm_chair.png, nm_person.png, nm_sword.png .
Coder in the Pantheon team - creators of Rastullahs Lockenpracht
User avatar
guyver6
Greenskin
Posts: 106
Joined: Mon Dec 23, 2002 10:16 pm
Location: Warsaw, Poland

Post by guyver6 »

You can generate materials on the fly from one "template" material. I did it for our current project, here's source code:

Code: Select all

void EarthPane::regenerateMaterials(Ogre::Mesh* mesh)
{
    using Ogre::Material;
    using Ogre::MaterialManager;
    using Ogre::Pass;
    using Ogre::Technique;
    using Ogre::TextureUnitState;

    Material* templateMat = (Material*)MaterialManager::getSingleton().getByName("Planetview/Globe/Template");

    if (mesh->getNumSubMeshes() != 10)
        return;

    // Suffixes for textures
    String detailNames[3] = { "vlo", "lo", "hi" };
    Uint i;

    // Generate materials for all Globe submeshes
    for (i = 0; i < 10; i++)
    {
        char matNumber[16];
        sprintf(matNumber, "%02d%02d", i*2, i*2 + 1);

        // New name for materials
        String matBaseName = "Planetview/Globe/Earth";
        String matName = matBaseName + "_" + matNumber;

        // Clone template
        Material* mat = templateMat->clone(matName);

        // Iterate through all texture units to change names of textures
        Material::TechniqueIterator tech_it = mat->getTechniqueIterator();

        while (tech_it.hasMoreElements())
        {
            Technique::PassIterator pass_it = tech_it.getNext()->getPassIterator();
            
            while (pass_it.hasMoreElements())
            {
                Pass::TextureUnitStateIterator tex_it = pass_it.getNext()->getTextureUnitStateIterator();

                while (tex_it.hasMoreElements())
                {
                    TextureUnitState* tex = tex_it.getNext();

                    if (tex->getTextureType() != Ogre::TEX_TYPE_2D)
                        continue;

                    String origName = tex->getTextureName();
                    String baseName;
                    String texName; // new texture name
                    String ext;

                    size_t dot = origName.find_last_of(".");

                    if (dot == String::npos)
                        continue;

                    baseName = origName.substr(0, dot);
                    ext = origName.substr(dot);

                    // don't touch anything but known texture names
                    if ((origName.find("color") == String::npos) &&
                        (origName.find("spec") == String::npos) &&
                        (origName.find("normal") == String::npos) &&
                        (origName.find("night") == String::npos))
                        continue;

                    texName = baseName + "_" + detailNames[detailLevel] + "_" + matNumber + ext;

                    // now name looks like "<textureTemplateName>_<detailLevel>_<facePairs>.ext"
                    tex->setTextureName(texName);
                } // while (tex_it.hasMoreElements())
            } // while (pass_it.hasMoreElements())
        } // while (tech_it.hasMoreElements())

        mesh->getSubMesh(i)->setMaterialName(mat->getName());
    } // for
}
What it does is it creates new material from template. changes texture names and then assigns new material to our globe submesh (10 submeshes). You can do something like that to assign material per mesh. Just make your own texture name pattern (I change color.png, normal.png, night.png, spec.png to something like color_lo_1314.png which is actual texture, while color.png is not).

Guyver
jonnii
Halfling
Posts: 81
Joined: Sat Jun 19, 2004 1:10 am

Post by jonnii »

i'm working on a tool for this that will generate shaders for you based on parameters, for example you can ask for lighting, skinning, normal mapping etc... and it will generate the shaders and material files for you.

not sure on the eta on this project but hopefully soon!

=))
User avatar
IFASS
Gnome
Posts: 387
Joined: Tue Jan 04, 2005 12:07 pm
Location: Netherlands

Post by IFASS »

jonnii wrote:i'm working on a tool for this that will generate shaders for you based on parameters, for example you can ask for lighting, skinning, normal mapping etc... and it will generate the shaders and material files for you.

not sure on the eta on this project but hopefully soon!

=))
Sounds really interesting.. hope to hear more soon about it.
User avatar
:wumpus:
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3067
Joined: Tue Feb 10, 2004 12:53 pm
Location: The Netherlands
x 1

Post by :wumpus: »

jonnii wrote:i'm working on a tool for this that will generate shaders for you based on parameters, for example you can ask for lighting, skinning, normal mapping etc... and it will generate the shaders and material files for you.

not sure on the eta on this project but hopefully soon!

=))
It should be quite straightforward (I'm not saying easy as there's always pitfalls), especially when you use high level languages you can just combine code fragments / function calls.
Gluber
Gnoblar
Posts: 18
Joined: Mon Oct 18, 2004 11:42 pm

Post by Gluber »

Please see this thread too, as we disicussed that some time ago:
http://www.ogre3d.org/phpBB2/viewtopic.php?t=7177


As an interim solution, i expanded on the Maya exporter ( we use Maya exclusivly for our art content ) so that we have an easy material templating system in it. I will of course release the source code and everything once its stable.
Post Reply