Blend Textures (Multitexturing)

http://untitledgam.es/2017/01/height-blending-shader/

A common way to blend textures is the alpha blending.

$$C_{result} = C_{source} \cdot F_{source} + C_{destination} \cdot F_{destination} \ F_{source} + F_{destination} = 1$$

Another way is to do linear interpolation. We can linearly interpolate the result color between two textures.

$$\frac{y-h_{0}}{x - x_{0}} = \frac{y_{1} - y_{0}}{x_{1} - x_{0}}$$

$$y = \frac{ y_0(x_1 - x) +y_1({x - x_{0})} }{x_1 - x_0}$$

The third way is to use the height map to determine the blend of two textures.

Blend Mode

Unity shader’s Blend Mode is defined by the blend command:Blend SrcFactor DstFactor The default operation is Add when BlendOp is not defined. The generated color is multiplied by the SrcFactor. The color in the buffer is multiplied by DstFactor. The two are added together.

The blend works in this equation:

result = src * srcFactor blendop dst * dstFactor.

For example, the traditional transparency is:

result = srcColor * (srcAlpha) + dstColor * (1 - srcAlpha)

It use alpha as factor to blend the color, if the srcAlpha is 0, then the srcColor becomes 0 too and dstColor is drawn.

Shadow Receiver

There are multiple ways to implement a plane only renders shadow.

The first one is to draw shadow only. After all, shadow is part of the shading model. If we ignore all the color, shadow is left. In URP, shadow attenuation is accessible by the Light.

VertexPositionInputs vertexInput = (VertexPositionInputs)0;
vertexInput.positionWS = input.positionWS;
float4 shadowCoord = GetShadowCoord(vertexInput);
Light mainLight = GetMainLight(shadowCoord);
half shadowAttenutation = mainLight.shadowAttenuation;

We can simply use the attenuation to draw the shadow.

Another way is Planar Shadow. We calculate the projected image of the model looked at a certain point.