Jump to content
The Dark Mod Forums

Material generator bash script


Recommended Posts

I created this script for personal use, but thought it would be of enough interest to share here. I'm in the process of porting a few texture packs into TDM from Xonotic... each texture containing a diffuse / normal / specular map, as well as optionally a glow / reflection map. Obviously I don't want to have to manually create the same material for every texture, so I made a script to do it for me!

 

Usage: Save this as a .sh file and place it in your texture pack's directory, next to the texture pack's subdirectories. Adjust the variables to match your texture package. Then just run the script: A mtr file should be generated, containing entries for each texture based on the maps it offers.

#!/bin/bash
# idTech4 material generator, by MirceaKitsune

# texture pack info
name="mypack"
author="myself"

# file and directory paths
base="textures/mymod/${name}"
mat="tdm_${name}.mtr"
ext="tga"

# special maps
map_glow="glow"
map_norm="norm"
map_gloss="gloss"
map_reflect="reflect"
cubemap="env/gen2"

# special parameter
param="metal"

rm "./${mat}"
echo "// Name: ${name}" >> "./${mat}"
echo "// Author: ${author}" >> "./${mat}"
echo "// Material Directory: ${base}" >> "./${mat}"
for d in *; do
    if [[ -d "${d}" ]]; then
        cd "./${d}"
        for f in *.tga; do
            if [[ -f "${f}" ]] && [[ "${f}" != *"_${map_glow}.${ext}"* ]] && [[ "${f}" != *"_${map_norm}.${ext}"* ]] && [[ "${f}" != *"_${map_gloss}.${ext}"* ]] && [[ "${f}" != *"_${map_reflect}.${ext}"* ]]; then
                f_noext=$(echo "${f}" | cut -d "." -f 1)

                echo "" >> "../${mat}"
                echo "${base}/${d}/${f_noext}" >> "../${mat}"
                echo "{" >> "../${mat}"

                echo "    qer_editorimage ${base}/${d}/${f_noext}" >> "../${mat}"
                echo "    description \"${name}, ${d}, ${f_noext}\"" >> "../${mat}"

                echo "" >> "../${mat}"
                echo "    ${param}" >> "../${mat}"

                echo "" >> "../${mat}"
                echo "    diffusemap ${base}/${d}/${f_noext}" >> "../${mat}"
                if [[ -f "${f_noext}_${map_norm}.${ext}" ]]; then
                    echo "    bumpmap ${base}/${d}/${f_noext}_${map_norm}" >> "../${mat}"
                fi
                if [[ -f "${f_noext}_${map_gloss}.${ext}" ]]; then
                    echo "    specularmap ${base}/${d}/${f_noext}_${map_gloss}" >> "../${mat}"
                fi
                if [[ -f "${f_noext}_${map_glow}.${ext}" ]]; then
                    echo "" >> "../${mat}"
                    echo "    // Glow" >> "../${mat}"
                    echo "    {" >> "../${mat}"
                    echo "        blend add" >> "../${mat}"
                    echo "        map ${base}/${d}/${f_noext}_${map_glow}" >> "../${mat}"
                    echo "    }" >> "../${mat}"
                fi
                if [[ -f "${f_noext}_${map_reflect}.${ext}" ]]; then
                    echo "" >> "../${mat}"
                    echo "    // Reflection" >> "../${mat}"
                    echo "    {" >> "../${mat}"
                    echo "        maskcolor" >> "../${mat}"
                    echo "        map makealpha(${base}/${d}/${f_noext}_${map_reflect})" >> "../${mat}"
                    echo "    }" >> "../${mat}"
                    echo "    {" >> "../${mat}"
                    echo "        blend gl_dst_alpha, gl_one" >> "../${mat}"
                    echo "        maskalpha" >> "../${mat}"
                    echo "        cubeMap ${cubemap}" >> "../${mat}"
                    echo "        texgen reflect" >> "../${mat}"
                    echo "    }" >> "../${mat}"
                fi

                echo "" >> "../${mat}"
                echo "    // Frob highlighting" >> "../${mat}"
                echo "    {" >> "../${mat}"
                echo "        if ( parm11 > 0 )" >> "../${mat}"
                echo "        blend gl_dst_color, gl_one" >> "../${mat}"
                echo "        map _white.tga" >> "../${mat}"
                echo "        rgb 0.40 * parm11" >> "../${mat}"
                echo "    }" >> "../${mat}"
                echo "    {" >> "../${mat}"
                echo "        if ( parm11 > 0 )" >> "../${mat}"
                echo "        blend add" >> "../${mat}"
                echo "        map ${base}/${d}/${f_noext}" >> "../${mat}"
                echo "        rgb 0.15 * parm11" >> "../${mat}"
                echo "    }" >> "../${mat}"

                echo "" >> "../${mat}"
                echo "    // TDM Ambient Method" >> "../${mat}"
                echo "    {" >> "../${mat}"
                echo "        if ( global5 == 1 )" >> "../${mat}"
                echo "        blend add" >> "../${mat}"
                echo "        map ${base}/${d}/${f_noext}" >> "../${mat}"
                echo "        scale 1, 1" >> "../${mat}"
                echo "        red global2" >> "../${mat}"
                echo "        green global3" >> "../${mat}"
                echo "        blue global4" >> "../${mat}"
                echo "    }" >> "../${mat}"

                echo "}" >> "../${mat}"
            fi
        done
        cd ".."
    fi
done
Edited by MirceaKitsune
  • Like 4
Link to comment
Share on other sites

Looks cool, I know nothing about scripts, but I'm sure it's useful. Will you be posting those texture packs?

I have an eclectic YouTube channel making videos on a variety of games. Come and have look here:

https://www.youtube.com/c/NeonsStyleHD

 

Dark Mod Missions: Briarwood Manor - available here or in game

http://forums.thedarkmod.com/topic/18980-fan-mission-briarwood-manor-by-neonsstyle-first-mission-6082017-update-16/

 

 

Link to comment
Share on other sites

Looks cool, I know nothing about scripts, but I'm sure it's useful. Will you be posting those texture packs?

 

They'll be available in the repository of DarkModule, a cyberpunk conversion for TDM based on Xonotic (currently in very early stages). You can follow it over in this thread.

Link to comment
Share on other sites

Does the script add the material stages for from highlighting and ambient lighting stages?

 

I don't know what those even mean, so probably not. What the script does is check whether given suffixes exist in textures, and add specific paragraphs to each entry of the mtr file if yes. For instance if mytexture_norm.tga exists, it adds a bumpmap line... it's flexible to allow defining any special map, but not very self aware if it comes to complex parameters. Its primary use is to generate the base entries so people don't have to do this tedious task by hand, some manual correction afterward is usually necessary though.

Link to comment
Share on other sites

It's the two stages for ambient world light and frob highlight to work right:

 

 

 

// 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
}

// TDM Ambient Method Related
{
if (global5 == 1)
blend add
map textures/darkmod/stone/brick/redbrick_with_mortar
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
}
}

 

 

Edited by Judith
Link to comment
Share on other sites

It's the two stages for ambient world light and frob highlight to work right:

 

 

 

// 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

}

// TDM Ambient Method Related

{

if (global5 == 1)

blend add

map textures/darkmod/stone/brick/redbrick_with_mortar

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

}

}

 

 

 

This stage:

 

 

 
{
                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
        }
 

 

is no longer needed as of TDM 2.0 standalone. Rebb moved the ambient shader to it's own dedicated path in v1.08 when the Doom 3 source code was integrated.

Please visit TDM's IndieDB site and help promote the mod:

 

http://www.indiedb.com/mods/the-dark-mod

 

(Yeah, shameless promotion... but traffic is traffic folks...)

Link to comment
Share on other sites

Then this wiki page must be updated as soon as possible: http://wiki.thedarkmod.com/index.php?title=Basic_Material_File

I based all my materials on that info, and new mappers may do the same.

 

Edit: But that's also a good news, since adding texture paths to this section was extra work.

Edited by Judith
Link to comment
Share on other sites

Interesting. I never knew materials needed special parameters for highlighting to work properly. But considering the corrections above, is it still needed at this stage, and what exactly should I still add if so? Anyway unless it requires specific different values for each texture, I can easily add a common paragraph for this as well.

Link to comment
Share on other sites

I'm assuming the frob highlighting stages are still required if you want a material to highlight when a player looks at an item that can be used or picked up. Anyone feel free to correct me if that's no longer relevant though, I haven't paid close attention to all the major code changes.

Link to comment
Share on other sites

You still need the other two stages, you just don't need the "if (global5 == 2)" stage anymore, as Nbohr noted.

 

 

Link to comment
Share on other sites

Updated the script to include frobbing and ambient method. Here's one of the materials generated with it for an example:

textures/darkmodule/ex/light/light_panel01{	qer_editorimage textures/darkmodule/ex/light/light_panel01	description "ex, light, light_panel01"	metal	diffusemap textures/darkmodule/ex/light/light_panel01	bumpmap textures/darkmodule/ex/light/light_panel01_norm	specularmap textures/darkmodule/ex/light/light_panel01_gloss	// Glow	{		blend add		map textures/darkmodule/ex/light/light_panel01_glow	}	// Frob highlighting	{		if ( parm11 > 0 )		blend gl_dst_color, gl_one		map _white.tga		rgb 0.40 * parm11	}	{		if ( parm11 > 0 )		blend add		map textures/darkmodule/ex/light/light_panel01		rgb 0.15 * parm11	}	// TDM Ambient Method	{		if ( global5 == 1 )		blend add		map textures/darkmodule/ex/light/light_panel01		scale 1, 1		red global2		green global3		blue global4	}}
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recent Status Updates

    • OrbWeaver

      Does anyone actually use the Normalise button in the Surface inspector? Even after looking at the code I'm not quite sure what it's for.
      · 3 replies
    • Ansome

      Turns out my 15th anniversary mission idea has already been done once or twice before! I've been beaten to the punch once again, but I suppose that's to be expected when there's over 170 FMs out there, eh? I'm not complaining though, I love learning new tricks and taking inspiration from past FMs. Best of luck on your own fan missions!
      · 4 replies
    • The Black Arrow

      I wanna play Doom 3, but fhDoom has much better features than dhewm3, yet fhDoom is old, outdated and probably not supported. Damn!
      Makes me think that TDM engine for Doom 3 itself would actually be perfect.
      · 6 replies
    • Petike the Taffer

      Maybe a bit of advice ? In the FM series I'm preparing, the two main characters have the given names Toby and Agnes (it's the protagonist and deuteragonist, respectively), I've been toying with the idea of giving them family names as well, since many of the FM series have named protagonists who have surnames. Toby's from a family who were usually farriers, though he eventually wound up working as a cobbler (this serves as a daylight "front" for his night time thieving). Would it make sense if the man's popularly accepted family name was Farrier ? It's an existing, though less common English surname, and it directly refers to the profession practiced by his relatives. Your suggestions ?
      · 9 replies
    • nbohr1more

      Looks like the "Reverse April Fools" releases were too well hidden. Darkfate still hasn't acknowledge all the new releases. Did you play any of the new April Fools missions?
      · 5 replies
×
×
  • Create New...