Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

A solution to the problem of transparent surface overlap when the model fades in and out in big data

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Big data in a model fade in and out of the transparent surface overlap solution, many beginners are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

A fading effect is required when a character dies, and the most common idea is to switch to a transparent object to set alpha desalination, and then this will happen.

Because the model is layered, it will expose the parts under the clothes, and those parts are often missing, even if it is only displayed for 1 second. To solve this problem, it is also easy to add a PASS in front of you to filter out the internal model only by drawing depth. This is also the way games such as World of Warcraft deal with stealth and ghost characters.

Pass {Tags {"RenderType" = "Transparent"Queue" = "Transparent"} ColorMask 0}

Is this plan perfect? Actually, it's not. First of all, doing so will cause the model to be drawn transparently, unable to obscure the ground, resulting in overdraw, but this is also a small matter. The problem is that this method can only be used for a single Renderer object, and it will still overlap when there is more than one Renderer. If you want not to overlap, you can set the RenderQueue of the PASS of the write depth forward, but if you do so, all the transparent objects obscured by this object will not be displayed (this is the case with glass in my world), so it is troublesome to have the best of both worlds. Merging models can solve the problem, but how can different materials fit together? How is it possible to change parts with only one piece of sticker?

What's more, after all, it turns an opaque object into a transparent object, and there is a huge difference in rendering between the two, which does not always guarantee that the conversion is natural (the transparency setting to 1 should be consistent with the previous opacity). When it comes to the delayed rendering pipeline, because the transparent object is difficult to accept light, it can only be dealt with alone, or the cost is huge, so it can not be used completely.

So many of the current generation of games are used in the following way.

A certain frame

There are actually no transparent pixels, just alternating the front pixel and the rear pixel through clip to create a "seemingly translucent" effect. In this way, it is essentially an opaque object rendering, and none of the problems mentioned above exist.

The following is Shader

Shader "Unlit/AlphaGrid" {Properties {_ MainTex ("Texture", 2D) = "white" {} _ Alpha ("Alpha", Range (0Magne1)) = 0.1 _ AlphaGridTex ("AlphaGrid Texture") 2D) = "white" {} SubShader {Tags {"RenderType" = "Opaque"} Pass {CGPROGRAM # pragma vertex vert # pragma fragment frag / / make fog work # pragma multi_compile_fog # include "UnityCG.cginc" struct appdata {float4 vertex: POSITION Float2 uv: TEXCOORD0;}; struct v2f {float4 vertex: SV_POSITION; float2 uv: TEXCOORD0; float4 screenUv: TEXCOORD1 UNITY_FOG_COORDS (1)}; sampler2D _ MainTex; float4 _ MainTex_ST; sampler2D _ AlphaGridTex; / / float4 _ AlphaGridTex_ST Float _ Alpha; V2f vert (appdata v) {v2f o; o.vertex = UnityObjectToClipPos (v.vertex); float4 screenPos = ComputeScreenPos (o.vertex) ScreenPos.xy * = _ ScreenParams.xy / 8ramp / w cannot be divided first here, which leads to insufficient interpolation accuracy o.screenUv = screenPos; o.uv = TRANSFORM_TEX (v.uv, _ MainTex); UNITY_TRANSFER_FOG (o _ .vertex) Return o;} fixed4 frag (v2f I): SV_Target {/ / sample the texture fixed4 col = tex2D (_ MainTex, i.uv) Float gridAlpha = tex2Dproj (_ AlphaGridTex, i.screenUv) .a; / / apply fog UNITY_APPLY_FOG (i.fogCoord, col); clip (_ Alpha-gridAlpha); return col } ENDCG}

Note that _ AlphaGridTex should be set to a global texture. I write this only so that I don't write cs code.

The texture itself is an alpha8 image of 8x8 that records the filtering order of each 8x8 screen pixel.

Zoom in:

I originally wanted to use the algorithm to generate it, but in the end, it was convenient to draw by hand. It's just 64 points.

Of course, this does not require extra PASS, but after all, it is AlphaTest, which is slower than the rendering of opaque objects, and there is a little more computational pressure on the vertices, but that's it.

(currently, in mobile games, using discard on non-PowerPR chips will cause Early-Z to fail, and objects in AlphaTest will be drawn even if they are obscured by other objects, resulting in a waste of OverDraw, but that is what happens when it is obscured. I'm afraid this situation is not common, and even if it is worse, it is still better than alphablend.

The PowerPR chip is another case, although it will not lead to OverDraw waste, but the drawing itself becomes slower, if the character frag stage is more complex than the ground, and the semi-transparent degree is also relatively high, there will indeed be some performance problems. So this is not optimization, but a way to solve the problem, whether it is faster or slower depends on the specific situation.

Of course, this method can not be used to make normal characters semi-transparent, it can not be fooled for a long time, it can only be used to gradually disappear. (although some games do do this, such as FF14, they have no other choice.)

The effect is really not good, it is only a special choice for special circumstances.

But it's always good to have multiple choices.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report