Material Files: Difference between revisions

From The DarkMod Wiki
Jump to navigationJump to search
m (typo)
 
(32 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Original_Reference|Fingernail & greebo|127}}
''Originally written by Fingernail & greebo on forums.thedarkmod.com''


<!-- keywords for search: surftype -->
<!-- keywords for search: surftype -->
Line 20: Line 20:
  }
  }


If you're using the ''material'' called '''textures/darkmod/stone/brick/redbrick_with_mortar''' in your map, Doom looks up the name in the material definition and loads the according image files (as specified by the [[Map Expressions]]). 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 ''material'' called '''textures/darkmod/stone/brick/redbrick_with_mortar''' in your map, TDM looks up the name in the material definition and loads the according image files (as specified by the [[Map Expressions]]). 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''')
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.
The .mtr files are read upon launching TDM - changing your material file therefore requires either restarting TDM or typing '''reloadDecls''' in the console.


== Create a new Texture Definition ==
== Create a new Texture Definition ==
Line 35: Line 35:
  textures/darkmod/stone/brick/redbrick_with_mortar
  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 Dark Mod parser might complain (e.g. no "&" (ampersand) or "-" (dash) characters, etc.)


Then, open up a squiggly bracket ({), and start to fill in the texture paths as below, changing the paths and names for your texture.
Then, open up a squiggly bracket ({), and start to fill in the texture paths as below, changing the paths and names for your texture.
Line 49: Line 49:
Close the definition with a close squiggly bracket (}).
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.
Save the file. Now you can load your new texture in [[DarkRadiant]] provided you did it all correctly.


Alternatively you can also have a look a the existing material files and learn from them.
Alternatively you can also have a look a the existing material files and learn from them.
== Add the Ambient Light Stage ==
This should go on all Dark Mod textures - see [[Virtual Ambient Light Textures]].
{{infobox|Note: If there is no specular map then substitute '''_black''', and if there is no bumpmap then use '''_flat''' instead.}}
<pre>
        // TDM Ambient Method Related
        {
                if (global5 == 1)
                blend add
                map                            <mappath/name>
                scale                  1, 1
                red                            global2
                green                  global3
                blue                    global4
        }
        {
                if (global5 == 2)
                blend add
                program ambientEnvironment.vfp
                vertexParm              0              1, 1, 1, 1              // UV Scales for Diffuse and Bump
                vertexParm              1              1, 1, 1, 1              // (X,Y) UV Scale for specular
                vertexParm              2              global2, global3, global4, 1
                fragmentMap            0              cubeMap env/gen1
                fragmentMap            1              <mappath/name>_local    // Bump
                fragmentMap            2              <mappath/name>          // Diffuse
                fragmentMap            3              _black                  // Specular
        }
</pre>
== 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 and bumpmap references.


== Full example ==
== Full example ==
Line 112: Line 76:
     diffusemap      textures/darkmod/stone/brick/redbrick_with_mortar
     diffusemap      textures/darkmod/stone/brick/redbrick_with_mortar
     specularmap      textures/darkmod/stone/brick/redbrick_with_mortar_s
     specularmap      textures/darkmod/stone/brick/redbrick_with_mortar_s
   
  }
    // This is the code required for frob highlighting this texture
</pre>
    {
 
        if ( parm11 > 0 )
In the above example the [[Surface Types|surface type]] is defined as well.
        blend      gl_dst_color, gl_one
 
        map        _white.tga
== Special Keywords ==
        rgb        0.40 * parm11
 
    }
There are also some special keywords you can use:
    {
 
        if ( parm11 > 0 )
* noshadows - surface does not cast a shadow
        blend      add
* noselfshadows - casts shadows, but not on itself
        map        textures/darkmod/stone/brick/redbrick_with_mortar
* translucent - for things like glass
        rgb        0.15 * parm11
* [[twosided]] - the surface will be duplicated and flipped, this causes it to be rendered twice. Useful for half-transparent things that should be visible from both sides. Normally surfaces are only visible from the front side (see note below)
    }
* noFog - do not render fog on this surface
* Discrete - Dmap will not merge brushes with this material applied
* NoFragment - Dmap will not split brushes with the material applied
* nopicmip - The image_downsize settings will not affect this texture. Use sparingly, as low-end users need to use image_downsize to load larger maps.
 
 
Note:
 
https://iddevnet.dhewm3.org/doom3/materials.html
 
twoSided Draw the front and back. '''Implies no-shadows''', because the shadow volume would be coplanar with the surface, giving depth fighting
 
Use a nodraw surface with forceShadows to address this.
 
 
== Optional: Customizing frob-highlight ==
 
By default frob highlight is done automatically by the engine. It's also possible to customise this.
 
For info [https://forums.thedarkmod.com/index.php?/topic/21629-211-frobstages-automatic-generation-and-customization/ see this forum post].
 
== See also ==
* [[Texture Guidelines]]
* [[How to add Textures to The Dark Mod]]
* [[Texture Creation - Basic Tutorial]]
* Youtube video: [https://www.youtube.com/watch?v=lFYJkBssMbM Getting textures into Dark Radiant and The Dark Mod – a short tutorial] (ignore the part about ambient stage)
 
== Deprecated stages ==
<div class="mw-collapsible mw-collapsed" style="width: 70%">
As of TDM 2.08, none of the ambient stages are needed.
<div class="mw-collapsible-content">


<pre>
         // TDM Ambient Method Related
         // TDM Ambient Method Related
         {
         {
                 if (global5 == 1)
                 if (global5 == 1)
                 blend add
                 blend add
                 map                            textures/darkmod/stone/brick/redbrick_with_mortar
                 map                            <mappath/name>
                 scale                  1, 1
                 scale                  1, 1
                 red                            global2
                 red                            global2
                 green                  global3
                 green                  global3
                 blue                    global4
                 blue                    global4
         }
         }  
        {
</pre>
 
<pre>
{
                 if (global5 == 2)
                 if (global5 == 2)
                 blend add
                 blend add
Line 150: Line 148:
                 fragmentMap            3              _black                  // Specular
                 fragmentMap            3              _black                  // Specular
         }
         }
}
</pre>
</pre>


== Special Keywords ==
<br>Ambient rendering has its own dedicated function in the renderer now, and it doesn't use textures for it.
 
<br><s>The option is no longer in the game menu, but you can check it in the game console by typing '''tdm_ambient_method'''. It should be set to '''0'''.</s>
There are also some special keywords you can use:
<br>As of 2.09, there is no longer any '''tdm_ambient_method''' cvar.
</div>


* noshadows - surface does not cast a shadow
* noselfshadows - casts shadows, but not on itself
* transparent - for things like glass
* [[twosided]] - the surface will be duplicated and flipped, this causes it to be rendered twice. Useful for half-transparent things that should be visible from both sides. Normally surfaces are only visible from the front side (see note below)
* noFog - do not render fog on this surface
* Discrete - Dmap will not merge brushes with this material applied
* NoFragment - Dmap will not split brushes with the material applied


As of TDM 2.11, none of the frob stages are needed.
<div class="mw-collapsible-content">


Note:
<pre>
    // 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
    } 
}
</pre>


http://www.iddevnet.com/doom3/materials.php
See also: https://forums.thedarkmod.com/index.php?/topic/21629-211-frobstages-automatic-generation-and-customization/
</div>


twoSided Draw the front and back. '''Implies no-shadows''', because the shadow volume would be coplanar with the surface, giving depth fighting


Use a nodraw surface with forceShadows to address this.
Click '''Expand''', for more details.
</div>


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


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

Latest revision as of 14:23, 15 January 2024

Originally written by Fingernail & greebo on forums.thedarkmod.com


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.

In fact, it's the material (=shader) which gets applied to surfaces of brushes, patches and models, not the actual TGA/DDS texture image. A TGA file cannot be applied to surfaces, it's the shader name which gets used.

Polygons ==> Shader ==> Image(s) + Processing => Appearance

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     
   bumpmap          textures/darkmod/custom/redbrick_local  
   specularmap      textures/darkmod/custom/redbrick_s     
}

If you're using the material called textures/darkmod/stone/brick/redbrick_with_mortar in your map, TDM looks up the name in the material definition and loads the according image files (as specified by the Map Expressions). 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 TDM - changing your material file therefore requires either restarting TDM 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 Dark Mod parser might complain (e.g. no "&" (ampersand) or "-" (dash) characters, etc.)

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
    bumpmap           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 DarkRadiant provided you did it all correctly.

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

Full example

Here is the full example with the final material definition:

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

    // Or use "surftype15" and add the surface type as the first (or only) word of the description,
    // the following are possible:
    // tile, carpet, dirt, gravle, grass, rock, twigs, foliage, sand, mud, brokeglass, snow, ice, squeakboard,
    // puddle, moss, cloth, ceramic, slate, straw, armor_leath, armor_chain, armor_plate, climbable, paper, hardwood

    //surftype15
    //description "carpet This is a carpet texture."

    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
 }

In the above example the surface type is defined as well.

Special Keywords

There are also some special keywords you can use:

  • noshadows - surface does not cast a shadow
  • noselfshadows - casts shadows, but not on itself
  • translucent - for things like glass
  • twosided - the surface will be duplicated and flipped, this causes it to be rendered twice. Useful for half-transparent things that should be visible from both sides. Normally surfaces are only visible from the front side (see note below)
  • noFog - do not render fog on this surface
  • Discrete - Dmap will not merge brushes with this material applied
  • NoFragment - Dmap will not split brushes with the material applied
  • nopicmip - The image_downsize settings will not affect this texture. Use sparingly, as low-end users need to use image_downsize to load larger maps.


Note:

https://iddevnet.dhewm3.org/doom3/materials.html

twoSided Draw the front and back. Implies no-shadows, because the shadow volume would be coplanar with the surface, giving depth fighting

Use a nodraw surface with forceShadows to address this.


Optional: Customizing frob-highlight

By default frob highlight is done automatically by the engine. It's also possible to customise this.

For info see this forum post.

See also

Deprecated stages

As of TDM 2.08, none of the ambient stages are needed.

        // TDM Ambient Method Related
        {
                if (global5 == 1)
                blend add
                map                             <mappath/name>
                scale                   1, 1
                red                             global2
                green                   global3
                blue                    global4
        }   
{
                if (global5 == 2)
                blend add
                program ambientEnvironment.vfp
                vertexParm              0               1, 1, 1, 1              // UV Scales for Diffuse and Bump
                vertexParm              1               1, 1, 1, 1              // (X,Y) UV Scale for specular
                vertexParm              2               global2, global3, global4, 1

                fragmentMap             0               cubeMap env/gen1
                fragmentMap             1               textures/darkmod/stone/brick/redbrick_with_mortar_local                  // Bump
                fragmentMap             2               textures/darkmod/stone/brick/redbrick_with_mortar                        // Diffuse
                fragmentMap             3               _black                  // Specular
        }


Ambient rendering has its own dedicated function in the renderer now, and it doesn't use textures for it.
The option is no longer in the game menu, but you can check it in the game console by typing tdm_ambient_method. It should be set to 0.
As of 2.09, there is no longer any tdm_ambient_method cvar.


As of TDM 2.11, none of the frob stages are needed.

    // 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: https://forums.thedarkmod.com/index.php?/topic/21629-211-frobstages-automatic-generation-and-customization/


Click Expand, for more details.