-
Notifications
You must be signed in to change notification settings - Fork 14
16. Tutorials & Overviews
The default material templates currently don't support PBR textures yet. Luckily, thanks to the customisable material templating system, it's possible to add in this support yourself. This section gives you an overview with useful information on adding PBR support.
The material templating system is written to be very customisable and overridable, just like the normal resource pack system. This means that you don't have to edit the default material templates of MiEx, but instead can put your modifications into a separate resource pack which you can then enable and disable by enabling or disabling the resource pack.
Let's start with creating a new resource pack called PBR and in there we make the folder materials/minecraft/templates. Then in that templates folder, we make a JSON file called base.json and put in the following JSON data:
{
"priority": 0,
"selection": ["*"],
"include": ["base"],
"network": {
}
}selection allows you to say which textures this template is for. In this case it's the base template, so we use an asterisk to say that it's for all textures. priority is in case you have multiple templates whose selection strings match the texture. Then it'll pick the highest priority material template. Since this is the base template, we use a priority of 0. include is the interesting part. That allows you to include other templates, so that you can build on top of them. Normally, it'll search for that template in the highest priority resource pack and then work its way down until it finds a template with that name. But because this is the "base" template and we include "base", it will search for the "base" template file in the resource pack below the current resource pack. In other words, this allows us to modify the existing "base" template. If we would leave the include key out, then we would fully override the "base" template.
Now we can add in our modifications in the network object. With that we can check whether certain textures exist and then add in the right nodes and make the necessary connections. So something like:
{
"priority": 0,
"selection": ["*"],
"include": ["base"],
"network": {
"@texture@_normal": {
Nodes for when there is a normal texture.
},
"@texture@_roughness": {
Nodes for when there is a roughness texture.
}
}
}With this you are checking if there is a texture file the same name as the current texture but with _normal or _roughness at the end of it. Based on that you can modify the material network. There are also many other checks that you can do, which you can read about here.
Now you can create your specific nodes to load in the different PBR textures and hook everything up the right way. This is all dependent on the specific PBR resource pack that you use. You can read more about how to specify nodes here.
To connect your PBR textures to the material shading node, you need to override that node. That can simply be done by specifying the material shading node with then new values or connections for its attributes. Here's an example of what it could look like for the UsdPreviewSurface material:
{
"priority": 0,
"selection": ["*"],
"include": ["base"],
"network": {
"@texture@_emission": { # If there is an emission texture
"MAT": { # Override the MAT material shading node, no need to specify a type because that's already specified.
"attributes": {
"inputs:emissiveColor": { # Specify a new value for inputs:emissiveColor
"type": "color3f",
"connection": "FILE_EMISSION.outputs:rgb" # Connect it to the FILE_EMISSION node.
}
}
},
"FILE_EMISSION": { # Add in a new node to load in the emission texture.
"type": "UsdUVTexture",
"attributes": {
"outputs:rgb": {
"type": "float3"
},
"inputs:file": {
"type": "asset",
"value": "@texture@_emission" # Specify the texture but with "_emission" at the end of it
},
"inputs:wrapS": {
"type": "string",
"value": "repeat"
},
"inputs:wrapT": {
"type": "string",
"value": "repeat"
},
"inputs:st": {
"type": "float2",
"connection": "UV.outputs:result" # Hook the UVs up to the already existing UV node used by the normal FILE node.
}
}
}
}
}
}