Hello, it’s me again…
i thought that today i can solve my uv atlas problem, but it seems that im not the best coder in the GLSL/HLSL languages… so my question… can somebody help/show me or give me an example for texture altases.
A full shader example would be nice… as i said im not the best shader coder…
Here are my greedy voxel chunks:
As u can see the uvs r correct… but i can only display one texture and i don’t want to use submeshes because of performance issues…
I’ve found a solution for texture atlases with greedy meshing:
Visit the post for more.
Thanks to everyone who can help me solving this problem
MR Michael
ok i found a solution… but i works not perfectly…
here is the uv error:
can somebody explain why the textures r stretched?
this is my shader:
Shader "BioGen/Block" {
Properties{
_MainTex("Atlas", 2D) = "gray" {}
}
SubShader{
Tags{ "RenderType" = "Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Standard fullforwardshadows
#pragma target 3.0
sampler2D _MainTex;
struct Input {
float4 color : COLOR;
float3 worldNormal;
float3 worldPos;
};
void surf(Input i, inout SurfaceOutputStandard o)
{
const float gridSize = 8;
const float margin = (1 / gridSize) / 4; //For 16x16 textures, margin of 1px, 32x32 => 2px etc.
const float cellSize = (1 / gridSize) - (margin * 2);
float blockId = int(i.color.a * gridSize * gridSize) / gridSize;
float2 uv = float2(
i.worldPos.x * (1 - i.worldNormal.x) + i.worldPos.z * i.worldNormal.x,
i.worldPos.y * (1 - i.worldNormal.y) + i.worldPos.z * i.worldNormal.y);
fixed4 c = tex2Dgrad(_MainTex, frac(uv) * cellSize + float2(blockId + margin, floor(blockId) / gridSize + margin), ddx(uv * cellSize), ddy(uv * cellSize));
o.Albedo = c.rgb;
}
ENDCG
}
FallBack "Diffuse"
}
and here is my texture atlas, it is 32x32px and i supports 8 textures for now…