Skip to content
r033 edited this page Jan 10, 2024 · 16 revisions

Welcome to the TexWizard wiki. Here you can read how to use this script correctly.

The following tutorial was written by elaymm4. He used this script for multiple mods, including Beta Visuals Mod.

Usage

Requirements

  • Binary tool (Version 2.8.3 or higher) (You can join Binary's discord server to read guides on how to use it. This tutorial will only briefly detail some of the workflow aspects of it)
  • Text editor of your choice (recommended: AkelPad, Notepad++)
  • Graphic editor of your choice that is capable of editing and saving dds files (recommended: Paint.NET, Photoshop)
  • Python / HEX editor of your choice (recommended: HxD)

Making a texture pack

  1. Set paths to your texture packs in a separate listing file.

    To modify the list, open the file scripts\TexWizard.json. After the brackets, set your path (relative to game root folder) to folders that contain texture package files, in quotes.

    • If you have multiple paths, put comma at the end of each path, except for the last one.
    • Use double slashes \\ instead of one \ when specifying a path.
  2. Create directory(-ies) you specified in the listing file. Create two empty files inside: meta.json and textures.bin.

  3. Open meta.json file with text editor of your choice. Paste next template and save the file.

    {
      "textures":
      [
        [ "", "" ]
      ]
    }
  4. List texture you want to replace in the first quote, and then the name of your texture in the second.

    {
      "textures":
      [
        [ "LICENSEPLATE", "MYLICENSEPLATE" ],
        [ "MW_LOGO", "COOL_LOGO" ],
        [ "HEADLIGHTOUTER", "HEADLIGHTNEW" ]
      ]
    }
    • If you have multiple textures, put comma at the end of each set, except for the last one.
    • If you don't know the real name of the texture, you can use hash.
  5. Open Binary tool (launch as Administrator), choose Modder mode (big icon on the right). Create launcher and set path to your root game folder.

  6. Open launcher .end file you created with a text editor of your choice. In the brackets after Files there's a list of files that will be loaded when you open launcher in the program.

    Add path to your textures.bin file (relative to root game folder) and save the file.

    • If you have multiple paths, put comma at the end of each path, except for the last one.
  7. Reload or reopen Binary tool. In the list of loaded files find your textures.bin file. Open it and find TPKBlocks category. Select it and then click on "Add Node" button above. You will be asked to enter the name, write any.

    • It's recommended to use only latin characters in the name.
    • It's recommended to keep the name short.
  8. Open collection you just created. You will be greeted with a new window.

  9. Before the next step, you should prepare your textures, since game expects them in a specific form.

    For textures with alpha channel it's recommended to use DXT5 / DXTC5 format. For textures without alpha channel: DXT1 / DXTC1 format. And for textures with or without alpha channel and in lossless (aka no compression artifacts) form you should used RGBA / 32BIT format.

    99% of the time textures should have mipmaps, so make sure to include those when you save your texture files in graphic editor of your choice.

    • Game expects different amount of mipmaps than what typical graphic editor provides.

      Texture's mipmap count depends on the resolution of the texture. Specifically the one which is the lowest vertically or horizontally. Example: 256x256 would make it "256"; 256x128 would make it "128"; 64x512 would make it "64".

      Suggested rule is that lowest mipmap should be not lower than "8" vertically or horizontally in terms of resolution.

      Texture resolution Mipmap count
      8x8 1
      16x16 2
      32x32 3
      64x64 4
      128x128 5
      256x256 6
      512x512 7
      1024x1024 8
      Texture resolution Mipmap count
      16x8 1
      32x16 2
      64x32 3
      128x64 4
      256x128 5
      512x256 6
      1024x512 7
      2048x1024 8

      If your graphic editor allows, change the mipmap count when saving texture file. You can use this Python script to set correct amount of mipmaps for your textures:

      import os
      import math
      import struct
      
      def get_mipmap_count(width, height):
          lowest_res = min(width, height)
          if not (lowest_res & (lowest_res - 1) == 0):
              return 1
          return int(math.floor(math.log(lowest_res, 2))) - 2
      
      directory_path = input("Enter directory to work with: ")
      
      for root, dirs, files in os.walk(directory_path):
          for file in files:
              if file.endswith(".dds"):
                  file_path = os.path.join(root, file)
                  with open(file_path, "rb+") as f:
                      file_bytes = bytearray(f.read())
                      height = struct.unpack("<I", file_bytes[12:16])[0]
                      width = struct.unpack("<I", file_bytes[16:20])[0]
                      mipmap_count = get_mipmap_count(width, height)
                      file_bytes[28:32] = mipmap_count.to_bytes(4, byteorder='little')
                      f.seek(0)
                      f.write(file_bytes)
      
                      print(f"Changed mipmap count to {mipmap_count} for {file_path}")

      Alternatively, you can change amount of mipmaps manually with a HEX editor. Open your texture file in HEX editor of your choice. Go to 0x1C offset. Mipmap count value is 4 bytes long (but only first one is used), and is presented in integer format. Change the value to one you need. Save the file.

  10. Add your new textures you listed into meta.json file.

  11. Change texture settings according to the type of its usage.

    Explanations for some of the texture settings:

    • AlphaBlendType - Acts sort of like layer blending in your graphic editor. If your texture doesn't have any visible transparency / alpha set it to TEXBLEND_SRCCOPY. Other cases will be mentioned later.
    • AlphaUsageType - Determines how soft or sharp alpha will be. For textures like tree it's a must to set it to punch through type, because otherwise you will have rendering order problems (tree textures will show up after the walls that supposed to cover them, etc).
    • Flags - Some extra flags that can be set. Not much is known, but one of them is important. Flag with value 3 will enable backface rendering (google if you don't understand what that is). Not recommended to enable it for every texture, as it might hurt performance, although that's just a logical guess.
    • RenderingOrder - 90% of the cases you want it to be set to 0. Otherwise your texture won't cast shadows or receive any from other objects. There are exclusions however, they will be mentioned later. TileableUV - Will your texture repeat (tile) or not, and on what axis it will be repeated (X = horizaontal or Y = vertical or both). Setting incorrect value might result in strange "stretching" glitch, it really depends on what object it's used on.

    Most of the time you should set parameters like this:

    Field Value
    AlphaBlendType TEXBLEND_SRCCOPY
    RenderingOrder 0
    TileableUV ALL_SIDES

    For decal textures like graffiti you need to set next parameters:

    Field Value
    AlphaBlendType TEXBLEND_BLEND
    RenderingOrder 5
    TileableUV ALL_SIDES

    For textures that are vertically long (like road textures, especially the ones that have merging surfaces, for example "road + grass") sometimes you need to set these parameters:

    Field Value
    AlphaBlendType TEXBLEND_SRCCOPY
    RenderingOrder 0
    TileableUV VERTICAL

    For organic (with ORG_ in the name) textures like tree / leaves, and sometimes some other textures with alpha (like ARC_FERRISWHEEL, ARC_WHOUSEBSTRUTSA_WH) you need to set next parameters:

    Field Value
    AlphaBlendType TEXBLEND_SRCCOPY
    AlphaUsageType TEXUSAGE_PUNCHTHRU
    RenderingOrder 0
    TileableUV ALL_SIDES

    For race barrier textures you need to set next parameters:

    SFX_TRACKBARRIERNEONARROW:

    Field Value
    AlphaBlendType TEXBLEND_ADDATIVE
    AlphaApplySort 1
    ClassKey 1802318419
    MipmapBiasInt 76
    RenderingOrder 7
    ScrollTimestep -160
    ScrollType TEXSCROLL_SNAP
    TileableUV HORIZONTAL

    SFX_TRACKBARRIERNEONARROW_SOLID:

    Field Value
    AlphaBlendType TEXBLEND_BLEND
    AlphaApplySort 1
    Flags 2
    MipmapBiasInt 76
    RenderingOrder 7
    TileableUV HORIZONTAL

    SFX_TRACKBARRIERLOCK:

    Field Value
    AlphaBlendType TEXBLEND_ADDATIVE
    AlphaApplySort 1
    RenderingOrder 7
    TileableUV ALL_SIDES

    SFX_TRACKBARRIERNEONLOCKED:

    Field Value
    AlphaBlendType TEXBLEND_BLEND
    AlphaApplySort 1
    Flags 2
    RenderingOrder 7
  12. Save your changes.

  13. Done!

Clone this wiki locally