Here is a single class utility that can be used to pack textures together. Its helpful for optimizing and reducing the total number of texture reads for any materials that use many texture maps.
It can be used to pack any color channel from one texture to another, but it also has two convenience methods so you can easily pack Normal-Parallax as well as Metallic-Roughness maps
Normal-Parallax Map
- Normal map packed into RGB channels
- Parallax map packed to Alpha
Currently, JME’s stock phong and PBR shaders both allow for the usage of a packed normal parallax map.
Metallic-Roughness Map
- Ambient Occlusion map packed to Red
- Roughness map packed into the Green
- Metallic map packed into the Blue
- Emissive Intensity map packed to Alpha
Currently, the stock PBR shader only uses the Green and Blue channels for determining the Roughnes and Metallic values respectively. Custom shaders may vary
Here’s some example code showing how you can quickly use the texture packer to pack a Normal-Parallax map
//change this to match your project's asset directory!
String assetDirectory = System.getProperty("user.home") + "\\Desktop\\JME_Projects\\TheAfflictedForests\\assets";
//create a new TexturePacker object
TextureChannelPacker texturePacker = new TextureChannelPacker(app, assetDirectory);
//load textures
Texture normalMap = app.getAssetManager().loadTexture("Textures/");
Texture parallaxMap = app.getAssetManager().loadTexture("Textures/");
//pack texture!
try {
String newTexSavePath = "/Textures/packedNormalParallaxTextures/packedNormalParallaxTexture.png";
Texture packedNormalParallaxTexture = texturePacker.packNormalParallaxMap(normalMap, parallaxMap, filePath , ColorSpace.Linear, null);
} catch (IOException ex) {
}
I am also wondering if it would be a good addition to the SDK if I were to add a button into the Material editor interface, so the user could conveniently pack the selected material’s current textures into a normal-parallax or metallic-roughness map with a single click.
@Darkchaos do you think this could be an acceptable addition to the SDK’s material editor ?