在Unity中渲染使用材质,着色器和纹理。这三者的关系都很密切。
材质定义了一个表面应该如何被渲染,包括对它使用的纹理的引用、平铺信息、颜色色调等等。材质的可用选项取决于材质使用的着色器。
着色器是包含数学计算和算法的小脚本,用于计算每个被渲染像素的颜色,基于灯光输入和材质配置。
纹理是位图图像。材质可以包含对纹理的引用,这样材质的着色器就可以在计算游戏对象的表面颜色时使用纹理。除了游戏物体表面的基本颜色(反射率),纹理还可以代表材质表面的许多其他方面,如反射率或粗糙度。
材质指定要使用的特定着色器,使用的着色器确定材质中可用的选项。着色器指定一个或多个它期望使用的纹理变量,Unity中的材质检视器允许你为这些纹理变量分配你自己的纹理资源。
对于大多数普通渲染(例如渲染人物,风景,环境,实体和透明的游戏对象,硬的和软的表面)标准着色器通常是最好的选择。这是一个高度可定制的着色器,它能够以高度逼真的方式呈现多种类型的表面。
在其他情况下,可以使用不同的内置着色器,甚至定制着色器(例如液体、树叶、折射玻璃、粒子效果、卡通效果、插图或其他艺术效果,或其他特殊效果,如夜视、热视觉或x射线视觉)。
Rendering in Unity uses Materials, Shaders and Textures. All three have a close relationship.
Materials define how a surface should be rendered, by including references to the Textures it uses, tiling information, Color tints and more. The available options for a Material depend on which Shader the Material is using.
Shaders are small scripts that contain the mathematical calculations and algorithms for calculating the Color of each pixel
rendered, based on the lighting input and the Material configuration.
Textures are bitmap images. A Material can contain references to textures, so that the Material’s Shader can use the textures while calculating the surface color of a GameObject. In addition to basic Color (Albedo) of a GameObject’s surface, Textures can represent many other aspects of a Material’s surface such as its reflectivity or roughness.
A Material specifies one specific Shader to use, and the Shader used determines which options are available in the Material. A Shader specifies one or more Texture variables that it expects to use, and the Material Inspector in Unity allows you to assign your own Texture Assetsto these Texture variables.
For most normal rendering (such as rendering characters, scenery, environments, solid and transparent GameObjects, hard and soft surfaces) the Standard Shader is usually the best choice. This is a highly customisable shader which is capable of rendering many types of surface in a highly realistic way.
There are other situations where a different built-in Shader, or even a custom written shader might be appropriate (for example liquids, foliage, refractive glass, particle effects, cartoony, illustrative or other artistic effects, or other special effects like night vision, heat vision or x-ray vision).