Artifacts when sampling heightmap in vertex-shader
Hi,
I have a surface shader that performs a vertex texture fetch as such:
void vert (inout appdata_full v) {
float4 tex = tex2Dlod (_MainTex, float4(v.texcoord.xy, 0, 0));
v.vertex.y += tex.r * _Height;
}
The weird artifacts occur at the edges of the mesh, sometimes only when x = 0 but sometimes when x is on the far edge. It does this even using different heightmaps.
I tried using different texture formats like RGBA32 and lower precision ones, different resolutions like 128, 129 and double that etc - nothing seems to work.
I even tried recreating the problem on the CPU by using the exact same heightmap but sampling the red channel on the CPU instead and displacing the actual vertices of the mesh - this resulted in a perfectly good mesh so I conclude that it probably isn't the heightmaps (they're procedural).
I'm going nuts, what am I missing here?
Vertex shader displacement:
CPU displacement:
Answer by swedishfisk · May 03, 2017 at 01:10 AM
I had completely missed the TextureWrapMode. If anyone encounters this problem it's solved by:
texture.wrapMode = TextureWrapMode.Clamp;
Your answer
Follow this Question
Related Questions
What's the best practices to modify a Texture2D efficiently by CPU? 0 Answers
Unable to save generated/rendered Texture2D to use for billboard 3 Answers
iOS gives error "No texture data available to upload" 0 Answers
Help Textures ?? inserting texture @ como inserir texturas 1 Answer
How to create texture at runtime (Without using TextureImporter)? 1 Answer