Texturas 2D
Standard Shader

Creando y utilizando Materiales

Para crear un nuevo Material, utilice Assets->Create->Material del menú principal o el menú de contexto Project View.

Por defecto, los nuevos materiales son asignados al Standard Shader, con todas las propiedades del mapa vacías, así:

Una vez el Material haya sido creado, usted puede aplicarlo a un objeto y ajustar todas su propiedades en el Inspector. Para aplicarlo a un objeto, simplemente arrástrelo desde el Project View a cualquier objeto en la Scene o Hierarchy.

Ajustando las Propiedades de los Materiales

Usted puede seleccionar qué Shader utilizar para cualquier Material en particular que utilice. Simplemente expanda el despegable Inspector en el Inspector, y escoja su nuevo Shader. El Shader que usted escoja dicta las propiedades disponibles para cambiar. Las propiedades pueden ser colores, deslizadores(sliders), texturas, números, o vectores. Si usted ha aplicado el material a un objeto activo en la Scene, usted verá sus cambios de la propiedad aplicada al objeto en tiempo real.

Hay dos maneras para aplicar una Texture a una propiedad.

  1. Arrástrelo desde el Project View encima del cuadrado de Textura
  2. Haga click en el botón Select, y escoja a textura desde la lista despegable que aparece

Shaders Integrados

Además del Standard Shader,hay un número de otras categorías de shaders integrados para propósitos especializados:

  • FX: La iluminación y efectos de vidrio.
  • GUI y UI:: Para gráficos de la interfaz de usuario.
  • Mobile: Un shader simplificado de alto rendimiento para dispositivos móviles.
  • Nature: Para árboles y el terreno.
  • Particles: Los efectos del sistema de partículas.
  • Skybox: Para renderizar ambientes del fondo detrás de toda la geometría
  • Sprites: Para uso con el sistema de sprite 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.

Texturas 2D
Standard Shader