Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
Shader "Custom/Demo" {
Properties {
_Tex1 ("Texture 1 (RGB) Depth (A)", 2D) = "white" {}
_Tex2 ("Texture 2 (RGB) Depth (A)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert
sampler2D _Tex1;
sampler2D _Tex2;
struct Input {
float2 uv_Tex1;
float2 uv_Tex2;
};
float3 blend(float4 texture1, float a1, float4 texture2, float a2)
{
float depth = 0.2;
float ma = max(texture1.a + a1, texture2.a + a2) - depth;
float b1 = max(texture1.a + a1 - ma, 0);
float b2 = max(texture2.a + a2 - ma, 0);
return (texture1.rgb * b1 + texture2.rgb * b2) / (b1 + b2);
}
void surf (Input IN, inout SurfaceOutput o) {
half4 c1 = tex2D (_Tex1, IN.uv_Tex1);
half4 c2 = tex2D (_Tex2, IN.uv_Tex2);
o.Albedo = blend(c1, IN.uv_Tex2.x, c2, 1 - IN.uv_Tex2.x);
}
ENDCG
}
FallBack "Diffuse"
}
Как это разширяется на >2 леера?Последовательно расширяется. Смешали 2 компоненты — результат смешиваем с третьей. Поскольку максимум — ассоциативная и коммутативная функция, порядок не важен.


float3 blend(float4 texture1, float a1, float4 texture2, float a2,float4 texture3, float a3)
{
float depth = 0.2;
float ma = max(max(texture1.a + a1, texture2.a + a2),texture3.a + a3) - depth;
float b1 = max(texture1.a + a1 - ma, 0);
float b2 = max(texture2.a + a2 - ma, 0);
float b3 = max(texture3.a + a3 - ma, 0);
return (texture1.rgb * b1 + texture2.rgb * b2+texture3.rgb * b3) / (b1 + b2+b3);
}
float3 blend(float4 texture1, float a1, float4 texture2, float a2)
{
return texture1.a > texture2.a ? texture1.rgb : texture2.rgb;
}
// второй шейдер
mix(texture1.rgb, texture2.rgb, step(texture1.a, texture2.a));
// третий шейдер
mix(texture1.rgb, texture2.rgb, step(texture1.a + a1, texture2.a + a2));


Смешивание текстур ландшафта