In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to achieve Unity Shader double-sided materials and multi-Pass rendering". In daily operation, I believe many people have doubts about how to achieve Unity Shader double-sided materials and multi-Pass rendering. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "Unity Shader double-sided materials and multi-Pass rendering". Next, please follow the editor to study!
By default, the Shader we write only renders the front of the model, because most of the models are closed and we can't see the negative. In the actual development process, we often encounter times when we need to render both sides. For example, when developing mobile games, we often need to use a patch + transparent way to represent distant plants and walls. If we use the default one-sided rendering, it can't be seen from the other side, and can only be achieved by doubling the number of faces.
Realization of double-sided material through Cull statement
The easiest way to achieve double-sided rendering is to use Cull Off. "Cull" means "culling", which means to remove the invisible part (the default is to cull the back). Cull Off told Unity that the rendering doesn't need to be removed, so mind your own business. Here is a simple example:
Shader "Custom/DoubleTransparent" {Properties {_ MainTint ("Main Color", Color) = (1,1,1) 1)} SubShader {Tags {"Queue" = "Transparent"} LOD 200 Cull Off Pass {Blend SrcAlpha OneMinusSrcAlpha ZWrite Off CGPROGRAM # pragma vertex vert # pragma fragment frag # include "UnityCG.cginc" uniform float4 _ MainTint Float4 vert (float4 vertPos: POSITION): SV_POSITION {return mul (UNITY_MATRIX_MVP, vertPos);} float4 frag (float4 vertPos: SV_POSITION): COLOR {return _ MainTint;} ENDCG}} FallBack "Diffuse"}
The following is a rendering of both sides:
But it doesn't seem to tell which is positive and which is negative. If we describe symmetrical objects, we don't need to distinguish them. However, sometimes we need to distinguish, for example, the effect of a piece of cloth, the front of the cloth is some colorful patterns, the back is just a simple texture, this needs to render the front and back in different ways, you need to use multiple Pass to render.
Multi-Pass rendering
In order to render the front and back sides differently, we need two Pass to render. The first one uses the Cull Back statement to render only the front, and the second uses the Cull Front statement to render only the back. The code is also very simple:
Shader "Custom/DoubleTransparent" {Properties {_ FrontColor ("FrontColor", Color) = (1,1,1,1) _ BackColor ("BackColor", Color) = (1,1,1) 1)} SubShader {Tags {"Queue" = "Transparent"} LOD 200 Pass {Blend SrcAlpha OneMinusSrcAlpha ZWrite Off Cull Front CGPROGRAM # pragma vertex vert # pragma fragment frag # include "UnityCG.cginc" uniform float4 _ BackColor Float4 vert (float4 vertPos: POSITION): SV_POSITION {return mul (UNITY_MATRIX_MVP, vertPos);} float4 frag (float4 vertPos: SV_POSITION): COLOR {return _ BackColor } ENDCG} Pass {Blend SrcAlpha OneMinusSrcAlpha ZWrite Off Cull Back CGPROGRAM # pragma vertex vert # pragma fragment frag # include "UnityCG.cginc" uniform float4 _ FrontColor Float4 vert (float4 vertPos: POSITION): SV_POSITION {return mul (UNITY_MATRIX_MVP, vertPos);} float4 frag (float4 vertPos: SV_POSITION): COLOR {return _ FrontColor;} ENDCG}} FallBack "Diffuse"}
You can see that the two renderings use different colors and different Cull methods. The actual results are as follows:
At this point, the study on "Unity Shader double-sided materials and how to achieve multi-Pass rendering" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.