Now that you know the game platform that can be created in a Unity, we will introduce to Materials, Shaders & Textures in unity. Unity is a powerful game engine that enables developers to create immersive 3D and 2D experiences. Central to this visual experience are Materials, Shaders, and Textures, which define the appearance of objects in your scene. In this article, we will break down these components, how they work together, and how to use them effectively in Unity.
A Material in Unity is an asset that defines how an object’s surface should look when rendered. It serves as a bridge between an object’s geometry and the Shader that controls its visual appearance.
- Shader Assignment: Each material uses a shader to determine how it interacts with light and other rendering properties.
- Color: Basic color tinting or modulation.
- Textures: Images or maps applied to the material to add detail.
- Rendering Modes: Defines transparency (Opaque, Transparent, Cutout, etc.).
- Right-click in the Project window.
- Select Create > Material.
- Assign the material to a GameObject by dragging it onto the object in the Scene or Hierarchy view.
A Shader is a script that tells the GPU how to render the surface of an object. It dictates the appearance of the material by describing how light interacts with the surface. Unity provides various built-in shaders and allows the creation of custom shaders for advanced use cases.
- Standard Shader: A versatile shader suitable for most materials. It supports PBR (Physically Based Rendering), ensuring realistic lighting and reflections.
- Unlit Shader: Ignores lighting; ideal for objects like UI elements or emissive materials.
- Custom Shaders: Written in ShaderLab, Unity's shader language, for unique visual effects.
Shader Features:
- Lighting Models: Controls how the surface reacts to light (e.g., Diffuse, Specular).
- Transparency: Supports different transparency levels and blending modes.
- Effects: Includes features like normal mapping, parallax, and emissive properties.
A Texture is a 2D image applied to a 3D surface to add detail, such as colors, patterns, or simulated physical properties.
Types of Textures:
- Albedo Map: The base color or diffuse map of the material.
- Normal Map: Adds surface detail by simulating small bumps and dents.
- Metallic Map: Defines which parts of the material are metallic.
- Roughness/Glossiness Map: Controls the smoothness or roughness of the surface.
- Height Map: Used for parallax effects to create depth.
- Emission Map: Makes parts of the material emit light.
Applying a Texture:
- Import the texture into Unity by dragging it into the Project window.
- Assign the texture to the desired property of a material (e.g., Albedo).
- Adjust tiling and offset settings to control the texture’s appearance on the object.