Перейти к содержимому

Как сделать прозрачный материал в unity

  • автор:

How To Create Transparent Glass Materials In Unity

Adam Reed

To start, let’s create a material. You can do this by right-clicking within the project menu and selecting Create>Material. I’m gonna name the material for this example “Glass_mat”.

Once you have a material created, you can customize a number of things within it.

To create transparent objects such as glass, change the “Rendering Mode” option to “Transparent”.

Clicking on the “Albedo” option’s color box allows you to change the RGB color value, as well as the material’s “Alpha” which affects its transparency.

The higher the Alpha, the less transparent the material is. A zero alpha would leave something completely transparent.

Here is an example of a cube with a standard shader. The rendering mode is set to “Opaque” and a texture of marble stone is applied to the “Albedo”.

Here is an example of a cube with a standard shader once again, but this time the rendering mode is set to “Transparent”, the “Smoothness” to 1, and the “Alpha Channel” within the “Albedo Color Picker” is set to 0.

Создание окна в Unity

Цель: рассмотреть, как можно добиться эффекта прозрачного окна в Unity.

Создание материала

Создать стеклянный материал в Unity довольно просто. Для начала создайте новый материал и назовите его как хотите, и убедитесь, что у вас есть шейдер Стандартный в качестве шейдера для этого материала. В раскрывающемся списке «Режим рендеринга» выберите Прозрачный. После этого измените альфа-канал вашего альбедо на 0, и вы получите хороший эффект прозрачности. Ваш шейдер материала Glass должен выглядеть следующим образом:

Примените материал к выбранному вами объекту, и вы должны получить результат, как я показал ранее, а также здесь ниже.

Вывод

Спасибо, что заглянули и прочитали сегодняшнюю статью. В следующей статье я расскажу о пробниках света в Unity.

Albedo Color and Transparency

A Standard Shader material with default Properties and no values or textures assigned. The Albedo Color Property is highlighted.A Standard Shader material with default Properties and no values or textures assigned. The Albedo Color Property is highlighted.

The Albedo Property controls the base color of the surface.

A range of black to white albedo values

Specifying a single color for the Albedo value is sometimes useful, but it is far more common to assign a texture map for the Albedo Property. This should represent the colors of the surface of the object. It’s important to note that the Albedo texture should not contain any lighting, since the lighting will be added to it based on the context in which the object is seen.

Two examples of typical Albedo texture maps. On the left is a texture map for a character model, and on the right is a wooden crate. Notice there are no shadows or lighting highlights.Two examples of typical Albedo texture maps. On the left is a texture map for a character model, and on the right is a wooden crate. Notice there are no shadows or lighting highlights.

Transparency

The alpha value of the Albedo colour controls the transparency level for the material. This only has an effect if the Rendering Mode for the material is set to one of the transparent mode, and not Opaque. As mentioned above, picking the correct transparency mode is important because it determines whether or not you will still see reflections and specular highlights at full value, or whether they will be faded out according to the transparency values too.

A range of transparency values from 0 to 1, using the Transparent mode suitable for realistic transparent objectsA range of transparency values from 0 to 1, using the Transparent mode suitable for realistic transparent objects

When using a texture assigned for the Albedo Property, you can control the transparency of the material by ensuring your albedo texture image has an alpha channel. The alpha channel values are mapped to the transparency levels with white being fully opaque, and black being fully transparent. This will have the effect that your material can have areas of varying transparency.

An imported texture with RGB channels and an Alpha Channel. You can click the RGB/A button as shown to toggle which channels of the image you are previewing.An imported texture with RGB channels and an Alpha Channel. You can click the RGB/A button as shown to toggle which channels of the image you are previewing. The end result, peering through a broken window into a building. The gaps in the glass are totally transparent, while the glass shards are partially transparent and the frame is fully opaque.The end result, peering through a broken window into a building. The gaps in the glass are totally transparent, while the glass shards are partially transparent and the frame is fully opaque.

How to make TRANSPARENT MATERIAL in Unity

In this article we see how to create a transparent material in Unity that allows you to see what is behind, a material that can be applied to windows and other transparent objects such as glasses or bottles. We also see how to use an image with alpha to apply transparency according to the information in that texture.

In the following video we see how to create a transparent material in Unity

Unity package with textures

Below you can download a Unity package with all the Assets I use in an old video about this topic.

Elements to be used

To show how to make transparent objects in Unity, I will use a cube and a sphere that will have a material applied to each one. In figure 1 we see the objects in the hierarchy and in figure 2 the materials that I have created for both objects.

hierarchy in unity, two objects, one will become transparent

Fig. 1: The objects we are going to use as an example

red and blue materials in unity, the blue material we will make transparent

Fig. 2: The materials that are applied to the objects in the figure above.

I will place the sphere in front of the cube, this will allow to know if the material of the sphere is transparent.

a blue sphere in front of a red cube in unity, make transparent objects

Fig. 3: I place the sphere in front of the cube to show the transparency.

Steps to create a transparent material in Unity

1. We select the material we want to make transparent to visualize its parameters in the inspector. The material I am using is the Standard Shader that can be created in Unity, in figure 4 we see its parameters in the inspector.

inspector of a standard blue material in unity

Fig. 4: The inspector of the blue material in the figure above, a standard material.

2. We changed the rendering mode from opaque to transparent, as shown in figure 5.

shader to transparent mode in unity

Fig. 5: We change the rendering mode to transparent.

3. We modify the Albedo color of the material according to the color we want and decrease the alpha component until we achieve the desired level of transparency (figure 7).

color parameter of a material in unity

Fig. 6: We change the color of the material.

selection of the color of a material in unity

Fig. 7: We decrease the alpha of the color to achieve transparency.

Results

In figure 8 we see the result, the material of the blue object is transparent and allows to see what is behind.

blue transparent sphere in front of a red cube in unity

Fig. 8: The material now allows you to visualize what is behind it.

If you want to achieve a material similar to glass you can adjust the parameter “Smoothness”, this will make the material smoother and more similar to glass.

smoothness parameter of a transparent material in unity

Fig. 9: We increase the “Smoothness” parameter.

blue transparent sphere similar to a crystal in front of a red cube in unity

Fig. 10: The material now looks more like glass.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *

From $34/Day — Car Rental HPN With Zero Terminal Shuttle