Unity 地形shader atlas纹理接缝问题

头上长西瓜 头上长西瓜 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

这是魔兽争霸用的地形纹理图集
http://www.cnblogs.com/sifenkesi/archive/2011/03/03/1970051.html
这个帖子介绍了纹理的拼接方式
最近想用unity仿照着写一个shader,大体基本实现了,但是在子纹理的连接处出现了接缝的问题,如下图

附上shader,请大侠们帮忙分析一下原因
// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)

Shader "Nature/Terrain/Standard" {
Properties {
// set by terrain engine
[HideInInspector] _Control ("Control (RGBA)", 2D) = "red" {}
[HideInInspector] _Splat3 ("Layer 3 (A)", 2D) = "white" {}
[HideInInspector] _Splat2 ("Layer 2 (B)", 2D) = "white" {}
[HideInInspector] _Splat1 ("Layer 1 (G)", 2D) = "white" {}
[HideInInspector] _Splat0 ("Layer 0 (R)", 2D) = "white" {}
[HideInInspector] _Normal3 ("Normal 3 (A)", 2D) = "bump" {}
[HideInInspector] _Normal2 ("Normal 2 (B)", 2D) = "bump" {}
[HideInInspector] _Normal1 ("Normal 1 (G)", 2D) = "bump" {}
[HideInInspector] _Normal0 ("Normal 0 (R)", 2D) = "bump" {}
[HideInInspector] [Gamma] _Metallic0 ("Metallic 0", Range(0.0, 1.0)) = 0.0
[HideInInspector] [Gamma] _Metallic1 ("Metallic 1", Range(0.0, 1.0)) = 0.0
[HideInInspector] [Gamma] _Metallic2 ("Metallic 2", Range(0.0, 1.0)) = 0.0
[HideInInspector] [Gamma] _Metallic3 ("Metallic 3", Range(0.0, 1.0)) = 0.0
[HideInInspector] _Smoothness0 ("Smoothness 0", Range(0.0, 1.0)) = 1.0
[HideInInspector] _Smoothness1 ("Smoothness 1", Range(0.0, 1.0)) = 1.0
[HideInInspector] _Smoothness2 ("Smoothness 2", Range(0.0, 1.0)) = 1.0
[HideInInspector] _Smoothness3 ("Smoothness 3", Range(0.0, 1.0)) = 1.0

// used in fallback on old cards & base map
[HideInInspector] _MainTex ("BaseMap (RGB)", 2D) = "white" {}
[HideInInspector] _Color ("Main Color", Color) = (1,1,1,1)
}

SubShader {
Tags {
"Queue" = "Geometry-100"
"RenderType" = "Opaque"
}

CGPROGRAM
#pragma surface surf Lambert
#pragma target 3.0

struct Input
{
float2 uv_Splat0 : TEXCOORD0;
float2 uv_Control : TEXCOORD4;
};
sampler2D _Control,_Splat0,_Splat1,_Splat2,_Splat3;
half _Metallic0;
half _Metallic1;
half _Metallic2;
half _Metallic3;

void surf (Input IN, inout SurfaceOutput o) {
half4 BlendTex = tex2D(_Control, IN.uv_Control);
half4 lay0={0.0,0.0,0.0,0.0},lay1={0.0,0.0,0.0,0.0},lay2={0.0,0.0,0.0,0.0},lay3={0.0,0.0,0.0,0.0};
float2 xy;half k;

k = round(BlendTex.r * 256.0);
if(k>0&&k<33){
xy.x = floor(k / 4)/8;
xy.y = (3-fmod(k, 4))/4;
lay0 = tex2D(_Splat0,frac(IN.uv_Splat0)/float2(8,4)+xy,ddx(IN.uv_Splat0/float2(8,4)),ddy(IN.uv_Splat0/float2(8,4)));
}
k = round(BlendTex.g * 256.0);
if(k>0&&k<33){
xy.x = floor(k / 4)/8;
xy.y = (3-fmod(k, 4))/4;
lay1 = tex2D(_Splat1,frac(IN.uv_Splat0)/float2(8,4)+xy,ddx(IN.uv_Splat0/float2(8,4)),ddy(IN.uv_Splat0/float2(8,4)));
}
k = round(BlendTex.b * 256.0);
if(k>0&&k<33){
xy.x = floor(k / 4)/8;
xy.y = (3-fmod(k, 4))/4;
lay2 = tex2D(_Splat2,frac(IN.uv_Splat0)/float2(8,4)+xy,ddx(IN.uv_Splat0/float2(8,4)),ddy(IN.uv_Splat0/float2(8,4)));
}
k = round(BlendTex.a * 256.0);
if(k>0&&k<33){
xy.x = floor(k / 4)/8;
xy.y = (3-fmod(k, 4))/4;
lay3 = tex2D(_Splat3,frac(IN.uv_Splat0)/float2(8,4)+xy,ddx(IN.uv_Splat0/float2(8,4)),ddy(IN.uv_Splat0/float2(8,4)));
}
float4 finalColor;
finalColor=lerp(lay0,lay1,lay1.a);
finalColor=lerp(finalColor,lay2,lay2.a);
finalColor=lerp(finalColor,lay3,lay3.a);
o.Albedo.rgb=finalColor;
}
ENDCG
}

Dependency "AddPassShader" = "Hidden/TerrainEngine/Splatmap/Standard-AddPass"
Dependency "BaseMapShader" = "Hidden/TerrainEngine/Splatmap/Standard-Base"

Fallback "Nature/Terrain/Diffuse"
}
...全文

相关推荐

评论 4
收藏 已收藏
分享
返回顶部
头上长西瓜
Unity3D 2,592 成员 2,147 内容