- Unity 2018 Cookbook(Third Edition)
- Matt Smith
- 345字
- 2025-02-23 18:56:40
Introduction
There is a close relationship between Textures, Materials, and Shaders, and their relationships are important:
- Textures are two-dimensional images. The surface of 2D and 3D objects in Unity games are defined by meshes. The Texture images are mapped onto meshes by Materials – each point (vertex) on a mesh has to be mapped to some value in the Texture. A Texture may indicate colors, but may indicate bumps/wrinkles or transparency – all of which can contribute to determining what is finally rendered for the user to see.
- Materials specify which Shader should be used to render the images onto the meshes, plus values for the Shader's parameters (such as which textures/parts of a texture map, colors, other values). Learn more at the Unity documentation page about Materials: https://docs.unity3d.com/Manual/Materials.html.
- Shaders define the method to render an object. Shaders can use multiple textures for more sophisticated results, and specify which parameters may be customized in the Material Inspector. At the end of the day, Shaders are code and mathematics, but Unity provides a set of Shaders for us. We can also use the new Shader Graph package, which allows the creation of sophisticated Shaders using a visual, drag-and-drop graphing interface. In addition, custom shaders can be written in the ShaderLab language.
Unity offers physically-based Shaders. Physically-Based Rendering (PBR) is a technique that simulates the appearance of Materials based on how the light reacts with that Material (more specifically, the matter from which that material is made) in the real world. Such a technique allows for more realistic and consistent materials. So, your creations in Unity should look better than ever. Creating Materials in Unity has also become more efficient now. Once you have chosen between the available workflows (Metallic or Specular setup; we'll get back to that later), there is no longer a need to browse the drop-down menus in search of specific features, as Unity optimizes the shader for the created Material, removing unnecessary code for unused properties once the material has been set up and the texture maps have been assigned.