Jump to content


Photo

Material generator bash script

linux bash shell script material texture generator tool assets editor

16 replies to this topic

#1 MirceaKitsune

MirceaKitsune

    Advanced Member

  • Member
  • PipPipPip
  • 673 posts

Posted 08 May 2017 - 07:58 AM

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, 10 May 2017 - 03:46 PM.

  • HMart, Epifire and Goldwell like this

#2 NeonsStyle

NeonsStyle

    Advanced Member

  • Member
  • PipPipPip
  • 1266 posts

Posted 08 May 2017 - 01:18 PM

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


I have a small YouTube channel making videos on a variety of games. Come and have look here:
 
https://www.youtube.com/c/NeonsStyleHD

 

Briarwood Manor - available here or in game

http://forums.thedar...2017-update-16/

 

 

 


#3 MirceaKitsune

MirceaKitsune

    Advanced Member

  • Member
  • PipPipPip
  • 673 posts

Posted 08 May 2017 - 01:50 PM

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.



#4 New Horizon

New Horizon

    Mod hero

  • Active Developer
  • PipPipPipPipPip
  • 13784 posts

Posted 09 May 2017 - 05:47 AM

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

#5 MirceaKitsune

MirceaKitsune

    Advanced Member

  • Member
  • PipPipPip
  • 673 posts

Posted 09 May 2017 - 07:58 AM

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.



#6 Judith

Judith

    Advanced Member

  • Member
  • PipPipPip
  • 758 posts

Posted 09 May 2017 - 08:35 AM

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

 

Spoiler

Edited by Judith, 09 May 2017 - 08:42 AM.


#7 nbohr1more

nbohr1more

    Darkmod PR, Wordsmith

  • Development Role
  • PipPipPipPipPip
  • 8176 posts

Posted 09 May 2017 - 09:17 AM

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

 

Spoiler

 

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.c...ds/the-dark-mod

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

#8 Judith

Judith

    Advanced Member

  • Member
  • PipPipPip
  • 758 posts

Posted 09 May 2017 - 09:23 AM

Then this wiki page must be updated as soon as possible: http://wiki.thedarkm...c_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, 09 May 2017 - 09:36 AM.


#9 nbohr1more

nbohr1more

    Darkmod PR, Wordsmith

  • Development Role
  • PipPipPipPipPip
  • 8176 posts

Posted 09 May 2017 - 09:35 AM

Fixed two of the wikis where this is prominent.


  • Judith and Epifire like this
Please visit TDM's IndieDB site and help promote the mod:

http://www.indiedb.c...ds/the-dark-mod

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

#10 MirceaKitsune

MirceaKitsune

    Advanced Member

  • Member
  • PipPipPip
  • 673 posts

Posted 09 May 2017 - 10:16 AM

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.



#11 New Horizon

New Horizon

    Mod hero

  • Active Developer
  • PipPipPipPipPip
  • 13784 posts

Posted 09 May 2017 - 12:40 PM

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.



#12 Springheel

Springheel

    Creative Director (retired)

  • Admin
  • 36631 posts

Posted 09 May 2017 - 01:43 PM

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

 

 



#13 MirceaKitsune

MirceaKitsune

    Advanced Member

  • Member
  • PipPipPip
  • 673 posts

Posted 09 May 2017 - 02:42 PM

Good to know. I should update the script and add this then, might do so later. Kinda sucks that it has to be added to each material manually... though I guess the code has its own limitation and requires it.



#14 rich_is_bored

rich_is_bored

    Advanced Member

  • Member
  • PipPipPip
  • 861 posts

Posted 09 May 2017 - 05:04 PM

Those stages should get wrapped in their own global macro keywords.


  • Judith likes this

#15 New Horizon

New Horizon

    Mod hero

  • Active Developer
  • PipPipPipPipPip
  • 13784 posts

Posted 09 May 2017 - 06:24 PM

Those stages should get wrapped in their own global macro keywords.

 

That sounds Groovy.



#16 MirceaKitsune

MirceaKitsune

    Advanced Member

  • Member
  • PipPipPip
  • 673 posts

Posted 10 May 2017 - 03:45 PM

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


#17 MirceaKitsune

MirceaKitsune

    Advanced Member

  • Member
  • PipPipPip
  • 673 posts

Posted 11 May 2017 - 09:20 AM

Since people were curious, see this post for image examples of the textures I ported with this script.





Reply to this topic



  



Also tagged with one or more of these keywords: linux, bash, shell, script, material, texture, generator, tool, assets, editor

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users