Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Guide for using third party textures

Discussion in 'General Graphics' started by jsx001, Mar 17, 2021.

  1. jsx001

    jsx001

    Joined:
    Nov 28, 2016
    Posts:
    12
    Hi,
    Can anyone point in a direction of a tutorial for using third party textures like textures.com and gametextures.com
    I have picked a cool SciFi panel (see below) and when I use it in Unity, (HDRP) it is flat with a hint of normal.
    The panel is not perfectly flat so it looks unnatural.
    Should I create a model that has extrusions to follow the profile, if so, that seems a lot of work, lots of geometry and how would I get it exact, what would the point be.
    I can't seem to figure out the correct flow to get this SciFi corridor going, which seems as it should be quite simple, so what am I missing.

    Would love to hear of any advice and guidance and strategies (don't get me started on Baking!).

    Thanks

    here is the reference pic:

    upload_2021-3-17_8-58-5.png
     
  2. Omniglitch

    Omniglitch

    Joined:
    May 29, 2017
    Posts:
    37
    This is something that took me forever to figure out, so I understand the confusion. The real trick was finding software that could put a grayscale image into whatever color channel I wanted so I could build texture files with the channels set up the way Unity requires. GIMP to the rescue.

    If you don't already have GIMP installed you can download it at www.gimp.org

    As you're no doubt aware, the texture files you get from sites like textures.com don't usually correspond to the color channel layout that Unity's shaders use. The typical PBR material from textures.com might include some, but maybe not all, of the following files:

    MaterialName_albedo - The Red, Green, and Blue channels contain the base color. The Alpha channel is typically unused, or absent.

    MaterialName_alpha - The Red, Green, and Blue channels are identical and contain the alpha/transparency map. Oddly, these textures rarely have an Alpha channel themselves.

    MaterialName_roughness - The Red, Green, and Blue channels are identical and contain the roughness map. With roughness maps, darker is smoother. Unity uses smoothness maps, where lighter is smoother.

    MaterialName_metallic - The Red, Green, and Blue channels are identical and contain the metallic map.

    MaterialName_normal - The Red, Green, and Blue channels contain the normal map.

    MaterialName_ao - The Red, Green, and Blue channels are identical and contain the ambient occlusion map.

    MaterialName_height - The Red, Green, and Blue channels are identical and contain the height map.

    Sometimes an alpha, roughness, metallic, ao, or height map will come in a grayscale image format instead of the RGB format. For the purpose of these conversion steps, these will need to be converted to having R, G, and B
    channels. (Open the texture in GIMP and select Image > Mode > RGB)

    OK, so that's what the downloaded files look like, but what files you need to make for Unity depends on your rendering pipeline:
    There's the Standard Shader for the Built-in Render Pipeline: https://docs.unity3d.com/Manual/StandardShaderMaterialParameters.html
    The Lit Shader for the Universal/Lightweight Render Pipeline: https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@7.1/manual/lit-shader.html
    And the Lit Shader for the High Definition Render Pipeline: https://docs.unity3d.com/Packages/c...es.high-definition@6.7/manual/Lit-Shader.html

    Select a material, and in the inspector hover over a map name (e.g. Albedo), and the tool tip will tell you how the channels are used, e.g. Albedo (RGB) and Transparency (A).

    Lets start with how to make an albedo texture for a transparent material, since that's the same for all of the render pipelines. The problem is you have two downloaded files you need to merge. You need to move the transparency map from the R, G, or B channel of the MaterialName_alpha texture into the Alpha channel of the MaterialName_albedo texture.
    ChannelTransferDiagram.png
    Step 1: Open the MaterialName_alpha texture in GIMP and inspect the channels. (On the right side of GIMP there will be tabs for Layers and Channels, and we'll be making use of both)

    Step 2: Add an alpha channel if it isn't there already. Select Layer > Transparency > Add Alpha Channel.

    Step 3: Copy the Red channel to the Alpha channel using Decompose and Compose:

    Step 3a: Select Colors > Components > Decompose. In the Decompose dialog, select RGBA for the Color model. Look at the Layers tab and you will see four layers now, one layer for each channel.

    Step 3b: Select Colors > Components > Compose. In the Compose dialog, select RGBA for the Color model, and for the Alpha channel select Red (or Green or Blue, they're all the same). You now have a texture with one layer and the Alpha channel should look the same as the Red, Green, and Blue channels.

    Step 4: File > Save this new version of the alpha texture. We'll need to drag and drop it into a layer later.

    Step 5: Open the MaterialName_albedo texture in GIMP.

    Step 6: Add an alpha channel if there isn't one already. Select Layer > Transparency > Add Alpha Channel.

    Step 7: On the right side of GIMP, select the Layers tab. There should only be one layer there called MaterialName_albedo.

    Step 8: Drag the alpha texture you saved earlier from the file Explorer to the Layer tab in GIMP. You should now see a second layer with the filename of your alpha texture.

    Step 9: Right-click the layer called MaterialName_albedo and select Add Layer Mask. In the dialog, select Transfer layer's alpha channel, and click Add.

    Step 10: Do the same thing for the alpha texture's layer. Both layers will now have a "Transfer layer's alpha channel" layer mask applied.

    Step 11: Now we will copy/paste the alpha channel across layers. In the Layers tab, click on the alpha texture's layer, then click on the image in the center of the screen and hit Ctrl+C (or select Edit > Copy). Click on the MaterialName_albedo layer, click on the image in the center of the screen, and hit Ctrl+V (or Edit > Paste).

    Step 12: In the Layer's tab, right-click the new layer that appeared called Floating Selection and select Anchor Layer. The transfer is now complete. Go to the Channels tab to confirm the Alpha channel looks as it should and isn't all white.

    Step 13: Select File > Export As..., choose a filename for your new ready-for-Unity albedo texture, and choose a file type that Unity can read such as PNG.

    Using these two techniques in GIMP, the shifting of channels within a texture through Decompose and Compose, and the technique of moving the Alpha channel from one texture to another, with a little creativity you can get a texture into any arrangement you want. If anyone knows of an easier way to build textures, I'd really appreciate any tips you have so we can all speed up our art pipelines.

    Using the Standard Shader for the Built-in Render Pipeline, the metallic, normal, ao, and height maps don't typically need any rearranging. They just need to be exported in a file format that Unity will load. I've been using PNG, but I'm really not sure if it's the best format. If anyone knows the best file format for optimizing load times, please let us know.

    The roughness map needs a little work. Open it in GIMP and select Colors > Invert to change it from a roughness map to a smoothness map. For the Built-in Render Pipeline's Standard Shader, the smoothness map can go into either the albedo texture's alpha channel or the metallic texture's alpha channel (the Standard Shader has a source field where you can choose which of those options you want). If you're making an opaque texture with no metallic map, putting smoothness into the albedo texture can save you from making an unnecessary metallic texture.

    Once all the textures are made, just follow the manual on making a material: https://docs.unity3d.com/Manual/Materials.html

    As for making materials for the HDRP's Lit Shader, I haven't done any of that HDRP stuff myself, but it looks pretty straightforward from reading the manual. Looks like they did away with putting smoothness in the Base Map (albedo), and now it's alpha channel is only ever for transparency. Now the metallic, ambient occlusion, height, and smoothness are all packed into the Mask Map texture. Getting that texture put together is possible using my steps, but you'll have to repeat them for each of those maps: e.g. move the metallic/ao/height/smoothness into the alpha channel, then transfer the alpha channel to the Mask Map texture, then shift it from the alpha channel to the appropriate channel using Decompose and Compose. Rinse and repeat for each map you need.

    I noticed the option to select a height map for the material is a bit obfuscated at first. You'll want your height map in the Blue channel of your Mask Map texture. You need to set the Material's Displacement mode to Vertex displacement. Only then can you set the height map in the Material. See this post for more info: https://forum.unity.com/threads/hdrp-displacement-maps.532173/

    Any questions, let me know.