《Unity着色器圣经》3.0.7 | 自定义材质属性绘制器

目录索引

译文

在 ShaderLab 中还有一种叫做“绘制器”的属性类型,这个基类允许我们在 Unity 检查器中创建自定义属性,从而方便用户在着色器中进行条件编程。

通常情况下,除非我们需要声明它们,否则绘制器不会出现在我们的着色器中。目前一共有七种不同的绘制器:

  • 开关
  • 枚举
  • 关键词枚举
  • 指数滑条
  • 整数范围
  • 空间
  • 标题

每一种绘制器都有特定的功能,需要独立声明。

感谢这些绘制器属性,我们可以在运行时不更换材质的前提下通过为着色器选择不同的状态来得到不同的效果。我们通常将这些绘制器与两种着色器变体一起使用(#pragma multi_compile 与 #pragma shader_feature

图片[1]-《Unity着色器圣经》3.0.7 | 自定义材质属性绘制器-软件开发学习笔记
Fig. 3.0.7a

原文对照

Another type of property that we can find in ShaderLab are “drawers”. This class allows us to generate custom properties in the Unity Inspector, thus facilitating the programming of conditionals in the shader.

By default, this type of property is not included in our shader, instead, we have to declare them according to our needs. To date, there are seven different drawers:

  • Toggle.
  • Enum.
  • KeywordEnum.
  • PowerSlider.
  • IntRange.
  • Space.
  • Header.

Each one of them has a specific function and is declared independently.

Thanks to these properties, we can generate multiple states within our program, allowing the creation of dynamic effects without the need to change materials at execution time. We generally use these drawers together with two types of shader variants, these refer to #pragma multi_compile and #pragma shader_feature.

图片[1]-《Unity着色器圣经》3.0.7 | 自定义材质属性绘制器-软件开发学习笔记
Fig. 3.0.7a
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容