编译材质(一)

本文介绍如何将材质源代码转换为二进制的*.filamat文件,使用Filament的matc工具进行编译,并在Android平台上加载这些文件。通过了解材质文件的数据类型、数学方法和变量,我们可以自定义材质来实现更复杂的渲染效果。
摘要由CSDN通过智能技术生成

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

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,
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

后知后觉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值