I have a cubic world (like Minecraft) where I'm generating chunks. In those chunks, only visible vertices and faces are generated.
Currently, it means that if I have a 2x2x1 chunk, it will generate 8 triangles for the top part (2 for each block). I'm trying to generate only two following this greedy meshing method:
If I combine adjacent faces together, I'd still like to be able to draw transitions in materials between adjacent blocks, something like this:
As you can see it has 3 different tiles: grass, dirt-grass transition, and dirt.
Currently, my shader looks like this:
Shader "MultiTexture_Diffuse_Worldspace"
{
Properties
{
_Color ("Main Color", Color) = (1,1,1,1)
_TexAbove ("Above texture", 2D) = "surface" {}
_TexSide ("Side texture", 2D) = "surface" {}
_TexBelow ("Below texture", 2D) = "surface" {}
_TexTopSide ("Top side texture", 2D) = "surface" {}
_Scale ("Texture Scale", Float) = 1.0
}
SubShader
{
Tags
{
"RenderType"="Opaque"
}
CGPROGRAM
#pragma surface surf Lambert
struct Input
{
float3 worldNormal;
float3 worldPos;
};
sampler2D _TexAbove;
sampler2D _TexSide;
sampler2D _TexBelow;
sampler2D _TexTopSide;
float4 _Color;
float _Scale;
void surf (Input IN, inout SurfaceOutput o)
{
float2 UV;
fixed4 c;
if(abs(IN.worldNormal.y > 0.5))
{
UV = IN.worldPos.xz;
c = tex2D(_TexAbove, UV* _Scale);
}
else if(abs(IN.worldNormal.x) > 0.5)
{
UV = IN.worldPos.yz;
c = tex2D(_TexSide, UV* _Scale);
}
else if(abs(IN.worldNormal.z) > 0.5)
{
UV = IN.worldPos.xy;
c = tex2D(_TexSide, UV* _Scale);
}
else
{
UV = IN.worldPos.xz;
c = tex2D(_TexBelow, UV* _Scale);
}
o.Albedo = c.rgb * _Color;
}
ENDCG
}
}
How would I modify this shader to work with faces that have been merged together? Or would I have to keep separate faces per block and handle them individually?