텍스처
스탠다드 셰이더

머티리얼 생성과 사용

새 머티리얼을 생성하려면 메인 메뉴의 Assets->Create->Material 또는 Project View 컨텍스트 메뉴를 사용해야 합니다.

기본 설정의 새 머티리얼에는 스탠다드 셰이더가 할당되며, 다음과 같이 모든 맵 프로퍼티가 비어있는 상태입니다.

새 머티리얼이 생성되면 오브젝트에 적용할 수 있으며 인스펙터 의 모든 프로퍼티를 조정할 수 있습니다. 오브젝트에 적용하려면 프로젝트 뷰 에서 또는 계층 구조 의 오브젝트로 드래그해야 합니다.

머티리얼 프로퍼티 설정

특정 머티리얼에 사용하고 싶은 셰이더를 선택할 수 있습니다. 인스펙터에서 Shader 드롭다운을 확장하고 새로운 셰이더를 선택합니다. 선택한 셰이더로 변경할 수 있는 프로퍼티가 표시됩니다. 프로퍼티에는 컬러, 슬라이더, 텍스처, 숫자, 벡터가 있습니다. 의 활성 오브젝트에 머티리얼을 적용하면 프로퍼티를 변경하는 즉시 실시간으로 오브젝트에 반영되는 것을 화면에서 확인할 수 있습니다.

텍스처 를 프로퍼티에 적용하는 방법에는 두 가지가 있습니다.

  1. 프로젝트 뷰에서 텍스처 스퀘어 상단으로 드래그합니다.
  2. Select 버튼을 클릭하여 나타나는 드롭다운 리스트에서 텍스처를 선택합니다.

빌트인 셰이더

스탠다드 셰이더 외에도 특수 목적의 다양한 빌트인 셰이더 카테고리가 있습니다.

  • FX: 조명과 글래스 효과 셰이더입니다.
  • GUIUI: 사용자 인터페이스 그래픽스를 위한 셰이더입니다.
  • Mobile: 모바일 디바이스를 위한 간편화된 고성능 셰이더입니다.
  • Nature: 나무 및 터레인을 위한 셰이더입니다.
  • Particles: 파티클 시스템 효과 셰이더입니다.
  • Skybox: 모든 지오메트리 뒤에 있는 배경 환경을 렌더링하기 위한 셰이더입니다.
  • Sprites: 2D 스프라이트 시스템과 사용하기 위한 셰이더입니다.
  • Unlit: For rendering that entirely bypasses all light & shadowing
  • Legacy: The large collection of older shaders which were superseded by the Standard Shader

Shader technical details

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:

  • The method to render an object. This includes code and mathematical calculations that may include the angles of light sources, the viewing angle, and any other relevant calculations. Shaders can also specify different methods depending on the graphics hardware of the end user.
  • The parameters that can be customised in the material inspector, such as texture maps, colours and numeric values.

A Material defines:

  • Which shader to use for rendering this material.
  • The specific values for the shader’s parameters - such as which texture maps, the colour and numeric values to use.

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.

텍스처
스탠다드 셰이더