Unity Shader - Creating and Using Materials - creation and use of materials

Contents: Unity Shader - knowledge catalog (first placeholder, follow continuously updated)
Original: Creating and the Using Materials
Version: 2019.1

Creating and Using Materials

Creation and use of materials

Create a new material, using the menu Assets-> Create-> material or Project view context menu.

By default, new material Standard specifies the Shader, all the texture properties are empty, the default is pure white map posted, such as:
Here Insert Picture Description
the material is created, you can be applied to an object, and you can adjust the Inspector properties on. Applied to a method on the object, you can drag the Project view of the material to Scene View or Hierarchy view of the object.

Setting Material Properties

Set the properties of materials

You can choose Shader you want to use the Material. In the Inspector click to expand Shader drop-down menu, and then select your Shader. When you replace Shader, the material properties can be used simultaneously measured parameters become replaced by the corresponding attribute Shader exposed. Attribute may be color, texture, value, or vector. If you use the Material in Scene on (scene) of the visible objects, you will be able to see the effects in real time by adjusting the property of Material.

Material are two ways to set the Texture property.

  1. Project Resource drag from the texture will view next to the texture attributes in a rectangular box Inspector
  2. Click Inspector in texture attributes box Select button, then the pop-up window, select the texture corresponding to the resource

Built-in Shaders

Built-in Shader

In addition to Standard Shader , Shader built there are many other classifications to be used for other needs:

  • FX : luminous efficiency and glass effect.
  • GUI and the UI : the graphical user interface interface.
  • Mobile : To simplify the use of high-performance mobile devices Shader.
  • Nature : trees and terrain terrain use.
  • ParticlesParticle system效果。
  • Skybox : act as rendered in all environmental background geometry.
  • Sprites : 2D sprite system.
  • Toon : cartoon rendering.
  • Unlit : bypassing all light and shadow rendering efficiency (without lighting effects).
  • Legacy : Standard substituted Shader Shader use a large number of older.

Shader technical details

Technical details Shader shader

Shader shader is a script, the script comprising a mathematical algorithm to calculate how the pixel or a model of the surface rendering and use. Standard shader implementation complexity and high fidelity light efficiency calculation. Other Shader or perhaps simply do not realize the effect of different computing. After specifying Shader, are listed some of the attributes of the corresponding material in the Material. Material properties of these, in view Inspector numerical attribute may be color, or texture. Bonding material is added to a target GameObject Renderer (renderer may be MeshRenderer, SkinnedMeshRenderer are inherited from the Renderer) component to render Mesh (mesh).

Generally it can be used for a texture in a plurality of different materials. According to the needs, the material is also possible to use different Shader.

The following example of a possible, provided the combination of a three texture shaders two materials.
Here Insert Picture Description
As shown, there are red and blue vehicle. Two vehicle models use different materials, "Red car material" and "Blue car material".

Use the same two body custom shader, "Carbody Shader". Use custom shaders generally adds additional features for automobiles, such as metal flashing rendering, or may have custom properties injury.

Each body materials are used in "Car Texture" texture, the texture contains all the details of the body, without the need to specify a different texture color.

Shader are used in the body of the vehicle using a property called tint color (hue), in order to set a different color to achieve the red and blue, while using only one texture you can achieve different color effects of the different vehicles.

Wheel model using other different material (a material different from the body), but at the same time the material used for the two wheels, the appearance of the two wheels look the same. Wheel material uses Standard Shader, and also uses "Car Texture" texture.

Note that "Car Texture" texture contains details of the wheel and the vehicle body, here called: texture atlas (texture atlas), different parts of the model means that the texture is mapped in different parts of FIG.

Although the material used in the body texture contains image content of a wheel, but the image does not display the contents of a wheel and the vehicle body, the vehicle body because the grid geometry, texture content not mapped wheel.

Similarly, the texture does not display the contents of the wheels of the vehicle body, the wheel geometry as the mesh body No mapping texture content.

This mapping is usually caused by other 3D software to complete, called "UV mapping" (UV mapping).

More definition Shader (shaders):

  • Rendering an object's method. Contains the code and mathematical calculations, comprising a light source angle, angle of view, there are other calculations. Shader also rely on different graphics hardware (different graphics) using different API.
  • Customizable Inspector Material of parameters, such as: texture, color, numerical.

Material definition:

  • Shader can specify shader for rendering.
  • Parameter values ​​can be specified on the Shader - such as: texture, color, numerical.

Custom Shader meant to write graphics programs. Use ShaderLab language will be done much easier. However, let Shader shaders work on a variety of graphics cards is a complex task that requires a fairly comprehensive knowledge of the graphics card works.

There are many Shader in Unity has been built, and many more from Standard Assets repository.

Guess you like

Origin blog.csdn.net/linjf520/article/details/91045000