새 머티리얼을 생성하려면 메인 메뉴의 Assets->Create->Material 또는 Project View 컨텍스트 메뉴를 사용해야 합니다.
기본 설정의 새 머티리얼에는 스탠다드 셰이더가 할당되며, 다음과 같이 모든 맵 프로퍼티가 비어있는 상태입니다.
새 머티리얼이 생성되면 오브젝트에 적용할 수 있으며 인스펙터 의 모든 프로퍼티를 조정할 수 있습니다. 오브젝트에 적용하려면 프로젝트 뷰 에서 씬 또는 계층 구조 의 오브젝트로 드래그해야 합니다.
특정 머티리얼에 사용하고 싶은 셰이더를 선택할 수 있습니다. 인스펙터에서 Shader 드롭다운을 확장하고 새로운 셰이더를 선택합니다. 선택한 셰이더로 변경할 수 있는 프로퍼티가 표시됩니다. 프로퍼티에는 컬러, 슬라이더, 텍스처, 숫자, 벡터가 있습니다. 씬 의 활성 오브젝트에 머티리얼을 적용하면 프로퍼티를 변경하는 즉시 실시간으로 오브젝트에 반영되는 것을 화면에서 확인할 수 있습니다.
텍스처 를 프로퍼티에 적용하는 방법에는 두 가지가 있습니다.
스탠다드 셰이더 외에도 특수 목적의 다양한 빌트인 셰이더 카테고리가 있습니다.
A Shader is a script which contains mathematical calculations and algorithms for how the pixels on the surface of a model should look. The standard shader performs complex and realistic lighting calculations. Other shaders may use simpler or different calculations to show different results. Within any given Shader are a number of properties which can be given values by a Material using that shader. These properties can be numbers, colours definitions or textures, which appear in the inspector when viewing a Material. Materials are then used by Renderer components attached to Game Objects, to render each Game Object’s mesh.
It is possible and often desirable to have several different Materials which may reference the same textures. These materials may also use the same or different shaders, depending on the requirements.
Below is an example of a possible set-up combination using three materials, two shaders and one texture.
In the diagram we have a red car and a blue car. Both models use a separate material for the bodywork, “Red car material” and “Blue car material” respectively.
Both these bodywork materials use the same custom shader, “Carbody Shader”. A custom shader may be used because the shader adds extra features specifically for the cars, such as metallic sparkly rendering, or perhaps has a custom damage masking feature.
Each car body material has a reference to the “Car Texture”, which is a texture map containing all the details of the bodywork, without a specific paint colour.
The Carbody shader also accepts a tint colour, which is set to a different colour for the red and blue cars, giving each car a different look while using a single texture for both of them.
The car wheel models use a separate material again, but this time both cars share the same material for their wheels, as the wheels do not differ on each car. The wheel material uses the Standard Shader, and has a reference again to the Car Texture.
Notice how the car texture contains details for the bodywork and wheels - this is a texture atlas, meaning different parts of the texture image are explicitly mapped to different parts of the model.
Even though the bodywork materials are using a texture that also contains the wheel image, the wheel does not appear on the body because that part of the texture is not mapped to the bodywork geometry.
Similarly, the wheel material is using the same texture, which has bodywork detail in it. The bodywork detail does not appear on the wheel, because only the portion of the texture showing the wheel detail is mapped to the wheel geometry.
This mapping is done by the 3D artist in an external 3d application, and is called “UV mapping”.
To be more specific, a Shader defines:
A Material defines:
Custom Shaders are meant to be written by graphics programmers. They are created using the ShaderLab language, which is quite simple. However, getting a shader to work well on a variety graphics cards is an involved job and requires a fairly comprehensive knowledge of how graphics cards work.
A number of shaders are built into Unity directly, and some more come in the Standard Assets Library.