Transparency and translucency effects

Alpha channel

        Transparency can be controlled through the alpha channel of the base map. If the alpha value is low, the mesh becomes more transparent, and if the alpha value is high, the mesh becomes less transparent and becomes easier to see. When the alpha value is 0, the mesh is completely invisible, and when the alpha value is in the middle, it will show a translucent effect.

Create a glass material

        How to create a glass-like material in Unity? An ideal plane of very clean glass would have no diffuse reflection (all light goes straight through it with no reflections), but it would have specular reflection. But in the real world, you can't find this kind of glass, and the glass in reality will have a little bit of diffuse reflection.

        Next, create a glass-like material under Unity, first create a new material GlassMaterial, add a cylinder to the scene, and then apply this material to the cylinder:


        In the Inspetor of the material, change the Surface Type property in Surface Options from Opaque to Transparent. Then set the Render Face to Both, which means that both the front and the back will be rendered.


        At this point the cylinder looks very strange, that's because we gave contradictory instructions: Surface Type is transparent, but alpha is usually still the default value (255, opaque). By modifying the A value in the Base Map, we can adjust the transparency of the surface.


        It looks a bit like glass now, but it's still almost interesting. What do you mean by worse? It is the specular reflection mentioned earlier. Here we adjust the Smoothness and Metallic properties to make this material look more like glass.


        Finally, we can also change the color of the "glass" itself, by modifying the values ​​of the R, G, and B channels of the Base Map to make it greener.


Use alpha clipping to add details

        Look at the object in the picture below, it is a leaf. This object is achieved by creating a mesh (more vertices) of leaves and veins.


        We can of course use this mesh directly. But in a scene, leaves may be reused many times, for example, for a tree, there may be a lot of leaves. If you use mesh directly, this means that there will be considerable rendering pressure.

        In actual use, this method is usually not used. For leaves, it can be a very simple mesh with very few vertices, and details on the surface such as veins can be achieved using alpha clipping in the texture. Doing so simplifies both the modeling process and the actual runtime processing.

        Generally, we implement this function by setting the texture file of the Base Map property as a texture with alpha clipping (first select Surface Type as Transparent). As shown below:


        The pattern of these leaves is really just a simple plane with a few vertices:


        Under the Surface Options property, select the Sureface Type as Opague, and then check Alpha Clipping, a Threshold slider will appear, and this threshold will adjust the influence weight of alpha clipping. Just drag and observe according to the actual desired effect.

Guess you like

Origin blog.csdn.net/vivo01/article/details/129034673