Hi,
i’ve maneged to get a 3 texture shader to work by fethcing the vertex colors from a model and that works.
Now i want to add more textures to it like 6 , but you can only assign RGB to vertex colors so those are 3 textures max , now i wast hinking on using an external RGBA texture which will define the channels and textures for 3 more textures on the terrain but my problem is how to color that image i tried using a white background or black background or transparent but nothing works correctly.
This is the shader :
Shader "Exile/Terrain/6lyr_terrain" {
Properties
{
_Color ("Color", Color) = (0,0,0,1)
_Layer1 ("Layer1 tex", 2D) = "white" {}
_Layer2 ("Layer2 tex", 2D) = "white" {}
_Layer3 ("Layer3 tex", 2D) = "white" {}
_Layer4 ("Layer4 tex", 2D) = "white" {}
_Layer5 ("Layer5 tex", 2D) = "white" {}
_Layer6 ("Layer6 tex", 2D) = "white" {}
_AddColorMap ("Layer 3 to 6 colormap", 2D) = "white" {}
}
SubShader
{
Pass
{
Cull Back
Fog { Mode Off }
CGPROGRAM
// Upgrade NOTE: excluded shader from DX11 and Xbox360; has structs without semantics (struct v2f members normal)
#pragma exclude_renderers d3d11 xbox360
#include "UnityCG.cginc"
#pragma vertex vert
#pragma fragment frag
sampler2D _Layer1;
sampler2D _Layer2;
sampler2D _Layer3;
sampler2D _Layer4;
sampler2D _AddColorMap;
float4 _Color;
float4 _Layer1_ST;
float4 _Layer2_ST;
float4 _Layer3_ST;
float4 _Layer4_ST;
float4 _AddColorMap_ST;
struct appdata
{
float4 vertex : POSITION;
float4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
struct v2f
{
float4 pos : SV_POSITION;
float4 color : COLOR;
float2 uv_Layer1 : TEXCOORD0;
float2 uv_Layer2 : TEXCOORD1;
float2 uv_Layer3 : TEXCOORD2;
float2 uv_Layer4 : TEXCOORD5;
float2 uv_ADC : TEXCOORD3;
float3 normal;
float3 lightDir : TEXCOORD4;
};
v2f vert (appdata_full v)
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.color = v.color;
o.uv_Layer1 = TRANSFORM_TEX(v.texcoord, _Layer1);
o.uv_Layer2 = TRANSFORM_TEX(v.texcoord, _Layer2);
o.uv_Layer3 = TRANSFORM_TEX(v.texcoord, _Layer3);
o.uv_Layer4 = TRANSFORM_TEX(v.texcoord, _Layer4);
o.uv_ADC = TRANSFORM_TEX(v.texcoord, _AddColorMap);
o.normal = normalize(mul(_Object2World,float4(v.normal,0)));
o.lightDir = normalize(WorldSpaceLightDir(v.vertex));
return o;
}
float4 frag (v2f i) : COLOR
{
float4 l1 = tex2D (_Layer1, i.uv_Layer1);
float4 l2 = tex2D (_Layer2, i.uv_Layer2);
float4 l3 = tex2D (_Layer3, i.uv_Layer3);
float4 l4 = tex2D (_Layer3, i.uv_Layer4);
float4 adc = tex2D (_AddColorMap, i.uv_ADC);
float4 color = float4(1, 1, 1, 1);
float3 lambert = saturate (dot(i.lightDir,i.normal));
color.rgb = (((l1 * i.color.r) + (l2 * i.color.g) + (l3 * i.color.b)) * lambert) * _Color;
color.rgb *=(l4 * adc.b);
return color;
}
ENDCG
}
}
}
Some input on how to properly achieve this problem is nice !
Imagery on the problem:
The external colormap :
The problem