Material Files: Difference between revisions

From The DarkMod Wiki
Jump to navigationJump to search
No edit summary
Line 2: Line 2:


== What the Heck is a Material File? ==
== What the Heck is a Material File? ==
The material files (extension .mtr) contain lists of 'material definitions' that tell the engine where to find the source files for the specified textures and what features it should have. All material files should be located in the '''darkmod/materials''' folder.   
The material files (.mtr) contain lists of 'material definitions' that tell the engine where to find the source files for the specified textures and what features it should have. All material files should be located in the '''darkmod/materials''' folder and have the extension '''.mtr'''.   


Material definitions apply to a single 'texture', though it may be made up of multiple texture files blended together.  A simple material definition looks like this:
Material definitions apply to a single 'texture', though it may be made up of multiple texture files blended together.  A simple material definition looks like this:


  textures/darkmod/custom/redbrick
  textures/darkmod/stone/brick/redbrick_with_mortar
  {
  {
     qer_editorimage  textures/darkmod/custom/redbrick_ed
     qer_editorimage  textures/darkmod/custom/redbrick_ed
Line 14: Line 14:
  }
  }


If you're using the texture called '''textures/darkmod/custom/wall1''' in your map, Doom looks up the name in the material definition and loads the according files. Note that you '''don't''' need to specify the file extension, the engine is automatically adding it (depending on your quality setting) and finds the according texture file. You also don't need to include the '''dds/''' prefix in the path, this is also added automatically.
If you're using the texture called '''textures/darkmod/stone/brick/redbrick_with_mortar''' in your map, Doom looks up the name in the material definition and loads the according files. Note that you '''don't''' need to specify the file extension, the engine is automatically adding it (depending on your quality setting) and finds the according texture file. You also don't need to include the '''dds/''' prefix in the path, this is also added automatically.


A single material file contains lots of material definitions. This is useful as textures that logically belong to each other (e.g. several wall textures) can be summarized in one material file (e.g. '''materials/darkmod_walls.mtr''')
A single material file contains lots of material definitions. This is useful as textures that logically belong to each other are summarized in one material file (e.g. '''materials/tdm_stone_brick.mtr''')


The .mtr files are read upon launching Doom 3 - changing your material file therefore requires restarting Doom.
The .mtr files are read upon launching Doom 3 - changing your material file therefore requires either restarting Doom or typing '''reloadDecls''' in the console.


== Create a new Texture Definition ==
== Create a new Texture Definition ==
Line 27: Line 27:
First, specify the name of your new material. If it is not a model texture, then the name should include the path to the texture files used.  Example:
First, specify the name of your new material. If it is not a model texture, then the name should include the path to the texture files used.  Example:


  textures/darkmod/stone/brick/redbrick_wall1
  textures/darkmod/stone/brick/redbrick_with_mortar


'''Note:''' Do not use special characters for your shader name or the Doom 3 parser might complain (e.g. no & characters)
'''Note:''' Do not use special characters for your shader name or the Doom 3 parser might complain (e.g. no & characters)
Line 35: Line 35:
  textures/darkmod/stone/brick/redbrick_with_mortar
  textures/darkmod/stone/brick/redbrick_with_mortar
  {
  {
        qer_editorimage  textures/darkmod/stone/brick/redbrick_with_mortar_ed      // editor image
    qer_editorimage  textures/darkmod/stone/brick/redbrick_with_mortar_ed      // editor image
        diffusemap      textures/darkmod/stone/brick/redbrick_with_mortar        // diffuse map
    diffusemap      textures/darkmod/stone/brick/redbrick_with_mortar        // diffuse map
        normalmap        textures/darkmod/stone/brick/redbrick_with_mortar_local  // normal map
    normalmap        textures/darkmod/stone/brick/redbrick_with_mortar_local  // normal map
        specularmap      textures/darkmod/stone/brick/redbrick_with_mortar_s      // specular map
    specularmap      textures/darkmod/stone/brick/redbrick_with_mortar_s      // specular map
  }
  }


Line 77: Line 77:
== See also ==
== See also ==
* [[Texture Guidelines]]
* [[Texture Guidelines]]
* [[How to add Textures to The Dark Mod]]
* [[Texture Creation - Basic Tutorial]]


{{tutorial-textures|sort=Material}}
{{tutorial-textures|sort=Material}}

Revision as of 02:24, 30 October 2007

Originally written by Fingernail & greebo on http://forums.thedarkmod.com/topic/127

What the Heck is a Material File?

The material files (.mtr) contain lists of 'material definitions' that tell the engine where to find the source files for the specified textures and what features it should have. All material files should be located in the darkmod/materials folder and have the extension .mtr.

Material definitions apply to a single 'texture', though it may be made up of multiple texture files blended together. A simple material definition looks like this:

textures/darkmod/stone/brick/redbrick_with_mortar
{
   qer_editorimage  textures/darkmod/custom/redbrick_ed
   diffusemap       textures/darkmod/custom/redbrick     
   normalmap        textures/darkmod/custom/redbrick_local  
   specularmap      textures/darkmod/custom/redbrick_s     
}

If you're using the texture called textures/darkmod/stone/brick/redbrick_with_mortar in your map, Doom looks up the name in the material definition and loads the according files. Note that you don't need to specify the file extension, the engine is automatically adding it (depending on your quality setting) and finds the according texture file. You also don't need to include the dds/ prefix in the path, this is also added automatically.

A single material file contains lots of material definitions. This is useful as textures that logically belong to each other are summarized in one material file (e.g. materials/tdm_stone_brick.mtr)

The .mtr files are read upon launching Doom 3 - changing your material file therefore requires either restarting Doom or typing reloadDecls in the console.

Create a new Texture Definition

Provided you already saved your texture source file (the .tga or .dds) in the appropriate folder, you can go on and create your texture definition. You cannot use your textures without this step.

Open up or create your personal material file with a text editor. There are existing guidelines for where texture definitions should go, for the sake of organization, but the engine doesn't care what the filename is as long as it's in the materials folder and has a .mtr extension.

First, specify the name of your new material. If it is not a model texture, then the name should include the path to the texture files used. Example:

textures/darkmod/stone/brick/redbrick_with_mortar

Note: Do not use special characters for your shader name or the Doom 3 parser might complain (e.g. no & characters)

Then, open up a squiggly bracket ({), and start to fill in the texture paths as below, changing the paths and names for your texture.

textures/darkmod/stone/brick/redbrick_with_mortar
{
    qer_editorimage  textures/darkmod/stone/brick/redbrick_with_mortar_ed      // editor image
    diffusemap       textures/darkmod/stone/brick/redbrick_with_mortar         // diffuse map
    normalmap        textures/darkmod/stone/brick/redbrick_with_mortar_local   // normal map
    specularmap      textures/darkmod/stone/brick/redbrick_with_mortar_s       // specular map
}

Close the definition with a close squiggly bracket (}).

Save the file. Now you can load your new texture in DoomEdit or DarkRadiant provided you did it all correctly.

Alternatively you can also have a look a the existing material files and learn from them.

Add the Frob Highlight Stage

All materials need to have a conditional shader stage added to let the material highlight when the objects are frobbed. The technical details are of minor interest here, just copy and paste such a stage from other materials and adjust the diffusemap reference:

textures/darkmod/stone/brick/redbrick_with_mortar
{
   // Use on of the predefined surface types like stone, glass, wood
   stone

   qer_editorimage  textures/darkmod/stone/brick/redbrick_with_mortar_ed
   bumpmap          textures/darkmod/stone/brick/redbrick_with_mortar_local
   diffusemap       textures/darkmod/stone/brick/redbrick_with_mortar
   specularmap      textures/darkmod/stone/brick/redbrick_with_mortar_s

   // This is the code required for frob highlighting this texture
   {
       if ( parm11 > 0 )
       blend       gl_dst_color, gl_one
       map         _white.tga
       rgb         0.40 * parm11
   }
   {
       if ( parm11 > 0 )
       blend       add
       map         textures/darkmod/stone/brick/redbrick_with_mortar
       rgb         0.15 * parm11
   }
}

See also