fixed4 frag (v2f i) : SV_Target
{
// use absolute value of normal as texture weights
half3 blend = abs(i.objNormal);
// make sure the weights sum up to 1 (divide by sum of x+y+z)
blend /= dot(blend,1.0);
// read the three texture projections, for x,y,z axes
fixed4 cx = tex2D(_MainTex, i.coords.yz);
fixed4 cy = tex2D(_MainTex, i.coords.xz);
fixed4 cz = tex2D(_MainTex, i.coords.xy);
// blend the textures based on weights
fixed4 c = cx * blend.x + cy * blend.y + cz * blend.z;
// modulate by regular occlusion map
c *= tex2D(_OcclusionMap, i.uv);
return c;
}
The dot product is defined as:
dot(a,b)
{
return a.x*b.x + a.y*b.y + a.z*b.z;
}
Of course your second parameter is not a vector, but HLSL just turns it into the vector (1,1,1). Specifically a vector of the same size as the other vector
Therefore the dot product calculates
(a.x*1 + a.y*1 + a.z*1)
The rest should be obvious. The a /= b
operator is a short hand for a = a / b
So the total expansion of that line is
blend = blend / (a.x*1 + a.y*1 + a.z*1);
Which makes the sum of x, y and z to sum up to 1.0
Example:
blend = (6,2,8)
blend = blend / (6*1 + 2*1 + 8*1);
blend = blend / (16);
blend = (6/16, 2/16, 8/16)
blend = (0.375, 0.125, 0.5)
0.375 + 0.125 + 0.5 == 1.0