cesium icon indicating copy to clipboard operation
cesium copied to clipboard

Basic upgrade path for glTF 1.0

Open lilleyse opened this issue 3 years ago • 0 comments

Instead of outright dropping glTF 1.0 support we could try to do a best effort upgrade from glTF 1.0 to 2.0.

It's not possible to upgrade glTF 1.0 shaders to 2.0 PBR materials in a generic way, but we can look for certain parameter names that are commonly found in glTF 1.0 assets and create PBR materials out of those. This would only work for materials, anything custom in the shader would be ignored.

For example, below we can map "diffuse" to "baseColorFactor" and "emission" to "emissiveFactor"

    "techniques": {
        "technique0": {
            "attributes": {
                "a_normal": "normal",
                "a_position": "position"
            },
            "parameters": {
                "ambient": {
                    "type": 35666
                },
                "diffuse": {
                    "type": 35666
                },
                "emission": {
                    "type": 35666
                },
                "modelViewMatrix": {
                    "semantic": "MODELVIEW",
                    "type": 35676
                },
                "normal": {
                    "semantic": "NORMAL",
                    "type": 35665
                },
                "normalMatrix": {
                    "semantic": "MODELVIEWINVERSETRANSPOSE",
                    "type": 35675
                },
                "position": {
                    "semantic": "POSITION",
                    "type": 35665
                },
                "projectionMatrix": {
                    "semantic": "PROJECTION",
                    "type": 35676
                }
            },
            "program": "program_0",
            "states": {
                "enable": [
                    2929,
                    2884
                ]
            },
            "uniforms": {
                "u_diffuse": "diffuse",
                "u_emission": "emission",
                "u_modelViewMatrix": "modelViewMatrix",
                "u_normalMatrix": "normalMatrix",
                "u_projectionMatrix": "projectionMatrix"
            }
        }
    }

This could be implemented in gltf-pipeline. Instead of converting from glTF 1.0 to glTF 2.0 + KHR_techniques_webgl, it could convert from glTF 1.0 to glTF 2.0 PBR. We may also need conversion for KHR_materials_common.

There's a branch in 3d-tiles-tools that attempted this same thing because users were trying to upload their glTF 1.0 tilesets into Unreal. We could look there for reference. See https://github.com/CesiumGS/3d-tiles-validator/issues/220.

Many glTF 1.0 assets use the CESIUM_RTC extension so we should consider supporting that too. I think it would be easy to support similar to how RTC_CENTER is handled in B3dmLoader.

lilleyse avatar Aug 01 '22 15:08 lilleyse