QUESTION:
I have a specular/glossiness texture image for a model which is not yet being used by the GLTF model.
How can I use/add the texture to my model so that it is reflective/glossy where it should be ?
I don't know what to change inside the .gltf file to make use of the texture.
EDIT: Added more lines of the GLTF to get a better picture of the situation.
GLTF JSON:
"images": [
{
"name": "...",
"uri": "..."
},
{
"name": "...",
"uri": "..."
},
{
"name": "...",
"uri": "..."
},
{
"name": "...",
"uri": "..."
},
{
"name": "...",
"uri": "..."
}
],
"samplers": [
{}
],
"textures": [
{
"name": "T_N",
"sampler": 0,
"source": 0
},
{
"name": "Map #9",
"sampler": 0,
"source": 1
},
{
"name": "T_D",
"sampler": 0,
"source": 2
},
{
"name": "Map #6",
"sampler": 0,
"source": 3
},
{
"name": "Specular",
"sampler": 0,
"source": 4
}
],
"materials": [
{
"name": "Head",
"alphaMode": "OPAQUE",
"extras": {
"fromFBX": {
"shadingModel": "<unknown>",
"isTruePBR": false
}
},
"normalTexture": {
"index": 0,
"texCoord": 0
},
"emissiveTexture": {
"index": 1,
"texCoord": 0
},
"pbrMetallicRoughness": {
"baseColorTexture": {
"index": 2,
"texCoord": 0
},
"baseColorFactor": [
1.0,
1.0,
1.0,
1.0
],
"metallicFactor": 0.800000002980232,
"roughnessFactor": 0.600000011920929
}
},
{
"name": "Body",
"alphaMode": "BLEND",
"extras": {
"fromFBX": {
"shadingModel": "<unknown>",
"isTruePBR": true
}
},
"pbrMetallicRoughness": {
"baseColorTexture": {
"index": 3,
"texCoord": 0
},
"baseColorFactor": [
1.0,
1.0,
1.0,
1.0
],
"metallicFactor": 0.80000002980232,
"roughnessFactor": 0.600000011920929
},
"extensions": {
"KHR_materials_pbrSpecularGlossiness": {
"specularGlossinessTexture": {
"index": 4
}
}
}
}
],
"meshes": [
{
"name": "Head",
"primitives": [
{
"material": 0,
"mode": 4,
"attributes": {
"COLOR_0": 3,
"NORMAL": 2,
"POSITION": 1,
"TEXCOORD_0": 4
},
"indices": 0,
"extensions": {
"KHR_draco_mesh_compression": {
"bufferView": 0,
"attributes": {
"COLOR_0": 2,
"NORMAL": 1,
"POSITION": 0,
"TEXCOORD_0": 3
}
}
}
}
]
},
{
"name": "Body",
"primitives": [
{
"material": 1,
"mode": 4,
"attributes": {
"COLOR_0": 8,
"NORMAL": 7,
"POSITION": 6,
"TEXCOORD_0": 9
},
"indices": 5,
"extensions": {
"KHR_draco_mesh_compression": {
"bufferView": 1,
"attributes": {
"COLOR_0": 2,
"NORMAL": 1,
"POSITION": 0,
"TEXCOORD_0": 3
}
}
}
}
]
}
],
ERROR:
Here is the error I am currenlty getting with the above modified GLTF when trying to load the model:
{"message":"Cannot read property 'getMaterialType' of undefined","name":"TypeError"}
There are some good examples in the glTF-Sample-Models repository. Here is the same model using two different PBR workflows:
Your example JSON above is using metal/rough, so you'll have to "convert" it to spec/gloss by replacing the metallic and roughness factors with equivalent spec/gloss properties.
I'd suggest taking a look at the specification for more info:
You may also find it easier to do this in a tool like Substance Painter or Blender, which can import and export glTF.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With