[Unity]UGUI and special effects MeshRender rendering level issues

I believe that most of the friends who clicked here have also encountered the same problem as me:

The artist creates a special effect, which may be particles or a MeshRender. Then the planner wants this special effect to be displayed above Image A and below Image B.

It means various interspersions, so how to solve this interspersion level problem?

Without further ado, here is a solution from a big guy on Zhihu.

Let’s look at the renderings first:

Here RawImage is used to render special effects, which can perfectly utilize the hierarchical relationship of UGUI and display it above Image A and below Image B.

I won’t go into details about the principle. I mainly use Raw Image and Camera’s Target Texture. The approximate implementation process is as follows:

 

1.Camera and Render Texture

Create a new Camera and a Render Texture

Camera settings are as follows:

Focus on: Background color is set to (0,0,0,0)

Then drag the special effect that needs to be rendered far away on the map, and adjust the Camera so that the Camera can see the Effect.

Continue to draw the key points: If Alpha Blend is used for special effects, because the colors cannot achieve the transparency effect we want after mixing, we need to change the Alpha Blend Shader that comes with Unity. Unity’s default Shader can be downloaded from the official website.

Then the principle of modification is mentioned at the end of the article.

Render Texture settings are as follows:

If you feel the effect is not very good, you can adjust the Size.

2. Create a new RawImage and drag the above Render Texture to the Texture of RawImage.

The key point here is: the default Shader needs to be modified to achieve transparent mixing. The principle will be mentioned later.

3. Modify Shader

The two places mentioned above that need to modify the Shader are simply posted here.

UI Default:

Alpha Blend:

Summarize:

Use RawImage to render the special effects we need to display, and then use UGUI's own set of hierarchical relationship logic to easily make the special effects display the effects we want on the UI.

Because the Shader we use for special effects is Alpha Blend, and using RawImage+Render Texture directly will display abnormalities, so we modified the Shader that comes with Unity. The principles and implementation methods are all from the Internet. I’ll post the source here.

The principle (seems to be this): http://www.voidcn.com/article/p-tdufpuof-bsc.html

Solution: https://zhuanlan.zhihu.com/p/110517201

 

-------------------------------------------------- --------------------------Manual dividing line--------------------------- -------------------------------------------------- -

2021/4/25

Later, I learned about something that I may have used before but forgotten, which can be found on Baidu:

UIParticleSystem

The approximate implementation should be to draw the ParticleSystem into a 2D picture, and then sort it according to the UGUI level.

If you are interested, you can research it yourself.

The advantage is that there is no need to create a new RawImage, Camera, or Render Texture.

Guess you like

Origin blog.csdn.net/qq302756113/article/details/115552448