alpha blend command doesn't work

I’m working in URP. I want two mesh: one is the plane ground, and another is an almost flat hill.
The hill is in the transparent render queue, because I use alpha to have a smoother edge.

7390505--902285--upload_2021-8-5_11-50-16.png

I’ve been trying to use the blend command in ShaderLab in RGB and Alpha separately.
I tried to use multiply for the RGB, and use source’s Alpha:

Blend DstColor Zero, One Zero

The RGB blend did work, it multiplied the SrcColor and DstColor, but the alpha blend doesn’t. It stopped blending and the whole mesh appeared.

What am I doing wrong?

Technically nothing. It’s working exactly as you’ve told it to.

Understand you’re telling the Alpha channel to blend differently than the RGB channels, and told the RGB blending to ignore the alpha entirely. And that’s what it’s doing. When you use a separate alpha blend, that will not affect the resulting color value you see, only the resulting alpha that gets stored in the render target.

To do a multiply blend like you’re attempting, the key to going it to look “right” is to understand the output alpha isn’t being used anymore. However you can still use it in the shader to prepare the output RGB values.

So the question is if you have two RGB color values, the one output by the shader and the one in the render target, and you want to multiply them together, how can you modify the shader output color to make it “invisible”?

Well, any value multiplied by 1 remains the original value. So the trick is to use the alpha in the shader to lerp() between the output color to 1.0 using the alpha value.

// blend mode, don't worry about the separate alpha
Blend DstColor Zero

// at the end of the shader
// fade from 1.0 to the RGB color using the "output" alpha
col.rgb = lerp(1.0, col.rgb, col.a);
return col;
2 Likes