Страница 1 из 1

DiffuseMix

СообщениеДобавлено: 26 ноя 2010, 02:03
gnoblin
Дифузный шейдер, который смешивает две текстурки по чернобелой маске.
Например песок+трава.

Скриншот не дам - надеюсь и так понятно).

Синтаксис:
Используется glsl
//mix 2 textures by mask
Shader "DiffuseMix" {
Properties {
        _Color ("Main Color", Color) = (1,1,1,1)
        _MainTex ("Base (RGB)", 2D) = "white" {}
        _SecondTex ("Second (RGB)", 2D) = "white" {}
        _MixMask ("Mask (R)", 2D) = "black" {}
}
SubShader {
        Tags { "RenderType"="Opaque" }
        LOD 200

CGPROGRAM
#pragma surface surf Lambert

sampler2D _MainTex;
sampler2D _SecondTex;
sampler2D _MixMask;
float4 _Color;

struct Input {
        float2 uv_MainTex;
        float2 uv_MixMask;
};

void surf (Input IN, inout SurfaceOutput o) {
        half4 tex = tex2D(_MainTex, IN.uv_MainTex);
        half4 second = tex2D(_SecondTex, IN.uv_MainTex);
        half4 mask = tex2D(_MixMask, IN.uv_MixMask);
       
    half4 c = lerp(tex, second, mask.r) * _Color;
        o.Albedo = c.rgb;
        o.Alpha = c.a;
}
ENDCG
}

Fallback "VertexLit"
}

Re: DiffuseMix

СообщениеДобавлено: 18 фев 2011, 17:37
gnoblin
По просьбам трудящихся, вариант шейдера в котором маска\вторая текстура работает с вторым uv-каналом.

Синтаксис:
Используется glsl
//mix 2 textures by mask
Shader "DiffuseMix_uv2" {
Properties {
        _Color ("Main Color", Color) = (1,1,1,1)
        _MainTex ("Base (RGB)", 2D) = "white" {}
        _SecondTex ("Second (RGB)", 2D) = "white" {}
        _MixMask ("Mask (R)", 2D) = "black" {}
}
SubShader {
        Tags { "RenderType"="Opaque" }
        LOD 200

CGPROGRAM
#pragma surface surf Lambert

sampler2D _MainTex;
sampler2D _SecondTex;
sampler2D _MixMask;
float4 _Color;

struct Input {
        float2 uv_MainTex;
        float2 uv2_MixMask;
};

void surf (Input IN, inout SurfaceOutput o) {
        half4 tex = tex2D(_MainTex, IN.uv_MainTex);
        half4 second = tex2D(_SecondTex, IN.uv2_MixMask); //IN.uv_MainTex);
        half4 mask = tex2D(_MixMask, IN.uv2_MixMask);
       
    half4 c = lerp(tex, second, mask.r) * _Color;
        o.Albedo = c.rgb;
        o.Alpha = c.a;
}
ENDCG
}

Fallback "VertexLit"
}

Re: DiffuseMix

СообщениеДобавлено: 18 фев 2011, 19:22
gnoblin
Вариант шейдера со "своим лайтмапом".

Синтаксис:
Используется glsl
//mix 2 textures by mask
Shader "DiffuseMix_uv2" {
Properties {
        _Color ("Main Color", Color) = (1,1,1,1)
        _MainTex ("Base (RGB)", 2D) = "white" {}
        _SecondTex ("Second (RGB)", 2D) = "white" {}
        _MixMask ("Mask (R)", 2D) = "black" {}
        _Illum ("Illumin (A)", 2D) = "white" {}
        _EmissionLM ("Emission (Lightmapper)", Float) = 0
}
SubShader {
        Tags { "RenderType"="Opaque" }
        LOD 250

CGPROGRAM
#pragma surface surf Lambert

sampler2D _MainTex;
sampler2D _SecondTex;
sampler2D _MixMask;
sampler2D _Illum;
float4 _Color;

struct Input {
        float2 uv_MainTex;
        float2 uv2_MixMask;
        float2 uv2_Illum;
};

void surf (Input IN, inout SurfaceOutput o) {
        half4 tex = tex2D(_MainTex, IN.uv_MainTex);
        half4 second = tex2D(_SecondTex, IN.uv2_MixMask); //IN.uv_MainTex);
        half4 mask = tex2D(_MixMask, IN.uv2_MixMask);
       
    half4 c = lerp(tex, second, mask.r) * _Color;
        o.Albedo = c.rgb;
        o.Emission = c.rgb * tex2D(_Illum, IN.uv2_Illum).a;
        o.Alpha = c.a;
}
ENDCG
}

Fallback "VertexLit"
}

Re: DiffuseMix

СообщениеДобавлено: 10 май 2012, 22:17
WebWolf
А как добавить теперь определение по зеленому и синему цвету к примеру?

Re: DiffuseMix

СообщениеДобавлено: 12 дек 2012, 18:10
yura415
А можно сделать такой на основе Specular шейдера?