【问题标题】:How to use PBR materials as image maps in Sceneform and ARCore?如何在 Sceneform 和 ARCore 中使用 PBR 材质作为图像贴图?
【发布时间】:2019-06-21 11:58:41
【问题描述】:

参考文章:Custom Material Reference,我们可以传递NormalDiffuseRoughnessMetalness的值。

我想在 Sceneform 和 ARCore 中使用自定义 PBR 材质作为图像映射(不是值)。

示例地图:

【问题讨论】:

    标签: augmented-reality arcore sceneform pbr


    【解决方案1】:

    更新:查看底部的 Mars.sfa 内容,了解如何将 .png 纹理分配给 3D 模型。

    Sceneform 提供默认材质定义(.sfm 文件),让开发人员可以轻松获得漂亮的结果。想要深度自定义资产外观方式的开发人员可以创建自己的材质定义(.mat 文件),并通过在资产定义中指定源属性将它们应用到资产。

    材质定义格式是一种松散的基于JSON的格式。在顶层,材质定义由 3 个使用 JSON 对象表示法的不同块组成。

    material {
        // material properties
    }
    vertex {
        // vertex shader, THIS BLOCK CAN BE OPTIONAL
    }
    fragment {
        // fragment shader
    }
    

    以下代码清单显示了有效材料定义的示例:

    material {
        name : "Textured material",
        parameters : [
            {
               type : sampler2d,
               name : texture
            },
            {
               type : float,
               name : metallic
            },
            {
                type : float,
                name : roughness
            }
        ],
        requires : [
            uv0
        ],
        shadingModel : lit,
        blending : opaque
    }
    
    fragment {
        void material(inout MaterialInputs material) {
    
            prepareMaterial(material);
            material.baseColor = texture(materialParams_texture, getUV0());
            material.metallic = materialParams.metallic;
            material.roughness = materialParams.roughness;
        }
    }
    

    或者片段部分可能是这样的:

    fragment {
        void material(inout MaterialInputs material) {
    
            // fetch the normal in tangent space
            vec3 normal = texture(materialParams_normalMap, getUV0()).xyz;
            material.normal = normal * 2.0 - 1.0;
    
            // prepare the material
            prepareMaterial(material);
    
            // from now on, shading_normal, etc. can be accessed
            material.baseColor.rgb = vec3(1.0, 0.0, 0.0);
            material.metallic = 0.0;
            material.roughness = 1.0;
        }
    }
    

    或者,例如,看看这个名为 Mars.sfa 的示例文件:

    {
      materials: [
        {
          name: 'Mars_Atmosphere_Mat',
          parameters: [
            {
              baseColorFactor: [1,1,1,1,],
            },
            {
              baseColor: 'Mars_Atmosphere_Mat_baseColor',
            },
            {
              diffuseColorFactor: null,
            },
            {
              diffuseColor: null,
            },
            {
              normal: null,
            },
            {
              metallicFactor: 1,
            },
            {
              roughnessFactor: 1,
            },
            {
              specularFactor: null,
            },
            {
              glossinessFactor: null,
            },
            {
              specularGlossiness: null,
            },
            {
              specularGlossinessCalculation: null,
            },
            {
              metallicRoughness: null,
            },
            {
              occlusion: null,
            },
            {
              emissiveFactor: [0,0,0,1,],
            },
            {
              emissive: null,
            },
            {
              opacity: null,
            },
          ],
          source: 'build/sceneform_sdk/default_materials/gltf_material.sfm',
        },
        {
          name: 'Mars_mat',
          parameters: [
            {
              baseColorFactor: [1,1,1,1,],
            },
            {
              baseColor: 'Mars_mat_baseColor',
            },
            {
              diffuseColorFactor: null,
            },
            {
              diffuseColor: null,
            },
            {
              normal: 'Mars_mat_normal',
            },
            {
              metallicFactor: 0.33000000000000002,
            },
            {
              roughnessFactor: 0.85999999999999999,
            },
            {
              specularFactor: null,
            },
            {
              glossinessFactor: null,
            },
            {
              specularGlossiness: null,
            },
            {
              specularGlossinessCalculation: null,
            },
            {
              metallicRoughness: null,
            },
            {
              occlusion: null,
            },
            {
              emissiveFactor: [0,0,0,1,],
            },
            {
              emissive: null,
            },
            {
              opacity: null,
            },
          ],
          source: 'build/sceneform_sdk/default_materials/gltf_material.sfm',
        },
      ],
      model: {
        attributes: [
          'Position',
          'TexCoord',
          'Orientation',
        ],
        collision: {
          skin_width: 0.75,
        },
        file: 'sampledata/models/Mars/Mars.gltf',
        name: 'Mars',
        recenter: true,
        scale: 0.5,
      },
      samplers: [
        {
          file: 'sampledata/models/Mars/Mars_mat_baseColor.png',
          name: 'Mars_mat_baseColor',
          pipeline_name: 'Mars_mat_baseColor.png',
        },
        {
          file: 'sampledata/models/Mars/Mars_mat_normal.png',
          name: 'Mars_mat_normal',
          params: {
            usage_type: 'Normal',
          },
          pipeline_name: 'Mars_mat_normal.png',
        },
        {
          file: 'sampledata/models/Mars/Mars_Atmosphere_Mat_baseColor.png',
          name: 'Mars_Atmosphere_Mat_baseColor',
          pipeline_name: 'Mars_Atmosphere_Mat_baseColor.png',
        },
      ],
      version: '0.54:1',
    }
    

    【讨论】:

      【解决方案2】:

      OBJ Attributes

      如果您使用的是obj 文件,则需要制作自定义材质。 Here is an example custom material 拥有您需要的一切。

      FBX Attributes

      如果您使用的是fbx 文件,则默认提供这些文件:

      • baseColorMap
      • metallicMap
      • normalMap
      • roughnessMap

      GLTF Attributes

      如果您使用的是gltf 文件,则需要将金属和粗糙度贴图合二为一。遮挡也可以打包到同一个纹理贴图中。红色是遮挡,绿色是粗糙度,蓝色是金属色。 sfa 文件中的参数是:

      metallicRoughness

      【讨论】:

        猜你喜欢
        • 2019-11-25
        • 2019-07-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-03-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多