5

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"} 
TheProgrammer
  • 1,409
  • 4
  • 24
  • 53

1 Answers1

1

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.

Don McCurdy
  • 10,975
  • 2
  • 37
  • 75
  • I bet the following error: `{"message":"Cannot read property 'getMaterialType' of undefined","name":"TypeError"}` after adding the fields from :https://github.com/KhronosGroup/glTF-Sample-Models/blob/master/2.0/Corset/glTF-pbrSpecularGlossiness/Corset.gltf#L121-L147 – TheProgrammer Aug 15 '18 at 08:47
  • Updated my current GLTF file in the question with the changes and more lines. – TheProgrammer Aug 15 '18 at 08:52
  • Would you have any idea what might be causing the error ? – TheProgrammer Aug 18 '18 at 14:35
  • I think you’ll need to post the entire glTF file using Google Drive or Dropbox or something. There are glTF “validation” tools that can also help. – Don McCurdy Aug 18 '18 at 17:21
  • I validated the file, now I am getting the exact same error as here: https://stackoverflow.com/questions/51839039/getting-an-istrustedtrue-error-when-using-gltfloader I have no idea what might be causing this... – TheProgrammer Aug 19 '18 at 15:57
  • How is this supposed to be used if the spec gloss model specifies rough/metal parameters? – pailhead Aug 22 '18 at 04:18
  • Do you mean what will the user see if the model has both spec/gloss and metal/rough parameters? See [spec/gloss best practices](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness/README.md#best-practices), but tl;dr the engine can choose one of the two. – Don McCurdy Aug 22 '18 at 15:51
  • @DonMcCurdy We need separate textures for base, rough, metallic in Blender? It kinda adds up the file size. Is there a way to show glossiness with one texture? – June Wang May 29 '19 at 06:48
  • If you're using Blender, use Principled BSDF materials and base color, rough, and metal textures. The metal and rough textures will be merged automatically. See: https://docs.blender.org/manual/en/dev/addons/io_gltf2.html – Don McCurdy May 29 '19 at 19:04