编译材质(一)

    前文我们在绘制三角形的时候用到了如下材质:

material {
    name : baked_color,
 
    // Lists the required vertex attributes
    // Here we only need a color (RGBA)
    requires : [
        color
    ],
 
    // This material disables all lighting
    shadingModel : unlit,
}
 
fragment {
    void material(inout MaterialInputs material) {
        // You must always call the prepareMaterial() function
        prepareMaterial(material);
 
        // We set the material's color to the color interpolated from
        // the model's vertices
        material.baseColor = getColor();
    }
}

    但是我们在程序中加载的并不是这个源文件,而是 baked_color.filamat ,该文件是二进制

文件,它是由上面的代码生成的。那么我们该如何将上面的材质源代码转变为 *.filamat文件呢?

    编译材质用到 Filament 提供的 matc 工具,将入我们将上面的代码村委 baked_color.mat 文件

然后使用下面的命令生成 baked_color.filamat,该文件就可以直接在程序中加载了:

matc -p mobile -o baked_color.filamat baked_color.mat

关于 matc 的说明我们简单看一下, matc --help:

matc is a command-line tool to compile material definition.
Usages:
    matc [options] <input-file>

Supported input formats:
    Filament material definition (.mat)

Options:
   --help, -h
       Print this message

   --license
       Print copyright and license information

   --output, -o
       Specify path to output file

   --platform, -p
       Shader family to generate: desktop, mobile or all (default)

   --optimize-size, -S
       Optimize generated shader code for size instead of just performance

   --api, -a
       Specify the target API: opengl (default), vulkan, metal, or all
       This flag can be repeated to individually select APIs for inclusion:
           matc --api opengl --api metal ...

   --define, -D
       Add a preprocessor define macro via <macro>=<value>. <value> defaults to 1 if omitted.
       Can be repeated to specify multiple definitions:
           matc -Dfoo=1 -Dbar -Dbuzz=100 ...

   --template <macro>=<string>, -T<macro>=<string>
       Replaces ${MACRO} with specified string before parsing
       Unlike --define, this applies to the material specification, not GLSL.
       Can be repeated to specify multiple macros:
           matc -TBLENDING=fade -TDOUBLESIDED=false ...

   --reflect, -r
       Reflect the specified metadata as JSON: parameters

   --variant-filter=<filter>, -V <filter>
       Filter out specified comma-separated variants:
           directionalLighting, dynamicLighting, shadowReceiver, skinning,

猜你喜欢

转载自blog.csdn.net/jake9602/article/details/129190725