I’m trying to make a mesh that represents a world map that smoothly blends between terrain types.
I know WHY the vertex shader isn’t rendering the texture properly: it’s just taking one point on the UV map and applying just that color to just that vertex, and calculating the blend inbetween the vertices. I think that you’re SUPPOSED to render this kind of thing with a fragment shader, but considering that I have no idea how to pass any kind of information about where on the mesh the shader is, I’m not sure how I’d use a fragment shader. The shader would need to know this information since it’s supposed to render a different texture based on the position on the mesh. (e.g. This part is a desert, so render the desert texture here, this part is a grassland, so render the grassland here, then blend between them where they meet)
Pic A what this shader is doing, pic B is what I want it to look like.
Here’s my shader code:
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "Custom/ExampleVertexColorShader" {
Properties {
_Tex1 ("Albedo (RGB)", 2D) = "white" {}
_Tex2 ("Albedo (RGB)", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque"}
pass
{
CGPROGRAM
#pragma vertex wfiVertCol
#pragma fragment passThrough
#include "UnityCG.cginc"
sampler2D _Tex1;
sampler2D _Tex2;
struct VertOut
{
float4 position : POSITION;
float4 color : COLOR;
float2 uv : TEXCOORD0;
};
struct VertIn
{
float4 vertex : POSITION;
float4 color : COLOR;
float2 uv : TEXCOORD0;
};
VertOut wfiVertCol(VertIn input, float3 normal : NORMAL)
{
VertOut output;
output.position = UnityObjectToClipPos(input.vertex);
float y = input.vertex.y;
y = y % 0.0001;
y *= 1000000;
y = round(y);
if (y == 12.0) {
output.color = tex2Dlod(_Tex1, float4(input.uv.xy,0,0));
} else if (y == 11.0) {
output.color = tex2Dlod(_Tex2, float4(input.uv.xy,0,0));
} else {
output.color = float4(0,0,0,1);
}
output.uv = input.uv;
//output.color = float4(y,y,y,1);
return output;
}
struct FragOut
{
float4 color : COLOR;
};
FragOut passThrough(float4 color : COLOR)
{
FragOut output;
output.color = color;
return output;
}
ENDCG
}
}
FallBack "Diffuse"
}