Uniform effect of the unity shader

I use unity to do a shader, the accident effect, the ball inside the characters still, but I can not see him, and can see the ball behind the scene, I would like to know this principle, some people know?

3 Likes

Following.

Even I had this doubt.

I would output the alpha texture of the sphere shader to a Render Target and use this Render Target in character shader to hide him in those areas.

Could also be done with a stencil or destination alpha, or just ZWrite.

For the ZWrite approach, render the sphere before the character with ZWrite On and use alpha test on the sphere. Then render the character sprite inside the sphere and it’ll be hidden.

Stencil approach is similar, but instead of relying on the depth which could cause issues with other effects you render the sphere with a stencil only shader (again, using alpha test), then render the character with a shader that won’t render anywhere the stencil has been written to by the sphere, then render the sphere again with the “real” shader.

Destination alpha is basically the same thing, but you use a shader with ColorMask A for the first pass of the sphere, and the character uses a special blend mode that uses the DstAlpha, this one is fun but requires the rest of your scene uses shaders that are careful how they render to the alpha channel. We did this for Cosmic Chef on the Daydream since it didn’t support stencils to do the intro / outro “videos” to confine them to the in-game world screen. Everything rendered 1 to the alpha, then I render the “screen” background with a 0 for the alpha, then render all of the on-screen objects just floating in space in front of the screen using Blend OneMinusDstAlpha DstAlpha

You could also use a grabpass, or a render texture, multiple camera passes.