[Unity3D] Record the process of solving the problem that particles in ScrollView cannot be blocked by Mask

Foreword:

Shader link used by the project to solve problem 1: https://www.codenong.com/cs107033982/

Question 1: Taking the lobby as an example, there are multiple icons in the ScrollView of the lobby, and the Mask in the ScrollView cannot block the particle effects.

Solutions:

1. The Mobile/Particles/Additive (Shader) shader used for particle effects does not include template testing. After adding template testing, it can be blocked by Mask like a normal Image, so we add template testing to the particle shader. .
2. Ordinary images use the default shader. To pass the shader template test, Stencil ID = 1 is required. So the Stencil ID = 1 in the material ball added to the Mask and particles.

Simulate the process of setting up content
Viewport初始状态
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0

3. Add template test Stencil ID = 1, Stencil Comparision = 8, Stencil Operation = 2 for the image in Mask.

Viewport添加材质球后
0 0 0 0 0 0 0 0 0 0 0
0 0 1 1 1 1 1 0 0 0 0
0 0 1 1 1 1 1 0 0 0 0
0 0 1 1 1 1 1 0 0 0 0
0 0 1 1 1 1 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0

4. Add a template test for the particles: Stencil ID = 1, Stencil Comparision = 3, so that the particles or pictures will only be displayed when the background number is equal to 1.

Place a 4*4 particle with a material in the upper left corner

4 * 4的粒子添加材质球后
1 1 1 1 0 0 0 0 0 0 0
1 1 1 1 0 0 0 0 0 0 0
1 1 1 1 0 0 0 0 0 0 0
1 1 1 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
与Mask合并后,只有√的区域才显示
0 0 0 0 0 0 0 0 0 0 0
0 0 √ √ 1 1 1 0 0 0 0
0 0 √ √ 1 1 1 0 0 0 0
0 0 1 1 1 1 1 0 0 0 0
0 0 1 1 1 1 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0

Solution:

1. Refer to the method on the Internet, use the MaskDefault shader for the Mask image in the Viewport, and use the MaskAdditive shader for the particle effects.

Question 2: After using the above solution to solve the problem that the Mask cannot block the particle effects, if the Scro of the two interfaces

Guess you like

Origin blog.csdn.net/beerbar3/article/details/129280821