Wiggling texture on procedural mesh

Hi,

I’m procedurally generating a mesh which is a long tri strip. As part of this I am generating UV’s for a texture that is applied. The UVs run from 0.0 to 1.0 in both directions. The applied texture has a straight line along the centre of it. The results however have a clearly defined ‘wiggle’.

This is on PC and (I believe) I am setting the Shader Model to 3.0. I’m using a really simple shader to render the texture :-

Shader "Custom/Diffuse Texture" {
    Properties {
      _MainTex ("Texture", 2D) = "white" {}
    }
    SubShader {
      Tags { "RenderType" = "Opaque" }
      CGPROGRAM
      #pragma surface surf Lambert
      #pragma target 3.0
      struct Input {
          float2 uv_MainTex;
      };
      sampler2D _MainTex;
      void surf (Input IN, inout SurfaceOutput o) {
          o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
      }
      ENDCG
    } 
    Fallback "Diffuse"
  }

Does anyone know how I can change the texture interpolation to avoid the wiggle.:face_with_spiral_eyes: I don’t really want to subdivide the mesh any further. Grateful for any thoughts!

Cheers!

I dont think its a shader issue, check your uv mapping code again for funny float numbers.

Thanks for the feedback aubergine. Unfortunately the UV’s look solid.

In the x axis, they are either 0.0 or 1.0. Along the y axis they linearly scale perfectly from 0.0 to 1.0. being exactly the same value either side of the strip.

I.e.
0: 0.0, 0.0
1: 1.0, 0.0
2: 0.0, 0.0625
3: 1.0, 0.0625
4: 0.0, 0.125
5: 1.0, 0.125

and so on…

It’s hard to tell from your screen shot, but does each pair of vertices share the same Y value? It doesn’t look like it, in which case they shouldn’t be sharing V values.

Yes, each pair of vertices does share the same Y value and hence does share the same V value. In the screen shot, you’re correct, they do vary a little as the mesh is tracing the line of a spline but the issue is still present when everything is lined up and Y values are the same:(

I’m pretty sure it’s a texture interpolation issue which is exaggerated by the thin triangles:( If you look at a single “quad” then the centre of the texture is not at the centre of the “quad”. There must be a way of correcting for it. This is a similar issue to non perspective correct texturing isn’t it?:expressionless:

Thanks again!

Here’s another picture that might show the problem a little better:-

Thanks!

You’re right. I think the fix here is actually to offset your vertices so they aren’t in pairs, but instead alternate along each edge. Then your triangles will be symmetrical, and everything should match up.

Yeah, that would probably avoid it and may indeed be the short term solution that I need to go for, so thanks for the idea.

There must be a way to correct it in the shader though otherwise all meshes would exhibit this effect unless carefully constructed. It’d be like PlayStation 1 graphics all over again :smile:

I’m really rusty on my graphics programming side :frowning: Could it be due to the w component being written out incorrectly in the vertex shader (note, I’m not providing a vertex shader myself, I assuming a simple pass through one with correct w will be supplied) ?

test it with a different shader, test it with the different texture to see how the extremities lineup, all the zeros should be on the left and all the ones should be on the right.

I have the exact same problem and would be interested in a real solution to this as a generic case, probably involving tex2Dproj I imagine. I’m actually pretty amazed a simple obvious case like this fails on modern rasterizers.

Might this not just be a driver or hardware issue? Never had such an issue, except for complex meshes which is normal. Looks like affine texture mapping but I have no much experience with this type of stuff.

I don’t think it’s related to hardware or driver. IMO, the perspective correction is active and does its job - what we’re seeing here makes sense if you consider each triangle individually. The problem here I think, is that the GPU is unaware that it’s actually a quad, not just two triangles, which would result in a different (and correct in that case) UV interpolation. So we should make it aware of it, since there’s no real quad nor polygon primitive.

I would agree with @g013 here. This looks like what happens with any strip of non-uniform geometry with “straight” UVs. I suggest you look into affine texture correction. Perspective texture correction works as it should to correct these kinds of artifacts when it comes to perspective warped geometry, but there’s no easy way to handle this case generically for arbitrarily warped geometry.

You guys are right, I assumed that the shape was a perfect line but it doesn’t seem to be.