Unity 地形shader atlas纹理接缝问题

头上长西瓜 2017-12-26 10:47:48

这是魔兽争霸用的地形纹理图集
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"
}
...全文
880 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
tianmao111 2020-04-17
  • 打赏
  • 举报
回复
https://blog.csdn.net/tianmao111/article/details/54691290
头上长西瓜 2019-11-25
  • 打赏
  • 举报
回复
引用 2 楼 helloazhuo的回复:
楼主求回复~感激不尽!
已经交给别人处理了,自己解决不了
helloazhuo 2019-09-06
  • 打赏
  • 举报
回复
楼主求回复~感激不尽!
helloazhuo 2019-09-06
  • 打赏
  • 举报
回复
请问现在解决了嘛

2,538

社区成员

发帖
与我相关
我的任务
社区描述
Unity3D相关内容讨论专区
游戏unity 技术论坛(原bbs)
社区管理员
  • Unity3D
  • 芝麻粒儿
  • 「已注销」
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

Unity3D社区公告:

  1. 社区致力于解决各种Unity3D相关的“疑难杂症”。
  2. 社区不允许发布与Unity3D或相关技术无关内容。
  3. 社区版主邀请各位一道为打造优秀社区不懈努力。

试试用AI创作助手写篇文章吧