Hey guys,
I have a working vertex displacement shader for Unity 3.5, but for some annoying reason the mesh gets split apart at the UV seams as shown here:
Shader "Bio/VertDisp" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Color Map", 2D) = "white" {}
_NoiseTex("Noise Map", 2D) = "white" {}
_TimeScale ("Motion Time Scaling", Float) = 1.0
_Displacement("Motion Displacement", Float) = 0.02
}
SubShader {
Tags{ "RenderType" = "Opaque"
}
CGPROGRAM
#pragma target 3.0
#pragma surface surf Lambert vertex:vert
#include "UnityCG.cginc"
sampler2D _MainTex;
sampler2D _NoiseTex;
float4 _Color;
float _Displacement;
float _TimeScale;
struct Input {
float2 uv_MainTex;
INTERNAL_DATA
};
void vert(inout appdata_full v)
{
#if !defined(SHADER_API_OPENGL)
float timeFrac = frac(_Time*_TimeScale);
float2 texCoord = float2(v.texcoord.x + timeFrac, v.texcoord.y + timeFrac);
// average the noise out. This essetially allows any texture to be used as noise.
float3 noise = tex2Dlod(_NoiseTex, float4(texCoord,0,0)).rgb;
float displacement = ((noise.x + noise.y + noise.z)/3 - 0.5) * _Displacement;
v.vertex.xyz = v.vertex.xyz + (normalize(v.normal.xyz) * displacement);
#endif
}
void surf(Input IN, inout SurfaceOutput o)
{
half4 tex = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = tex.rgb * _Color.rgb;
}
ENDCG
}
Fallback "Bio/Diffuse"
}
Any ideas on how to solve this?
Replies
Now because there are two vertices at two different locations in the UV map sampling two different values in the noise map....
Perhaps use something else that's guaranteed contiguous as the UV coords (world or object space position?).