Author Topic: UITexture doesn't handle texture offset/scale when in ScrollView with clipping  (Read 4593 times)

damthauer

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Hi, we're working on a project using NGUI version 3.0.8f7, and we stumbled upon this issue. A UITexture that's in a ScrollView with soft clipping won't show a texture properly if the material has non-zero offset and/or non-identity scale.

I've fixed the bug on my end, so if you'd like the patch you can tell me how to send it to you (I imagine you'd prefer I don't post the files here).

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
3.0.8 is very old. Clipping approach was recently redone in 3.5.6. It used to use texture matrices before. It doesn't anymore. Regardless, material should not be setting the UV. You can set UV rect on the UITexture itself.

damthauer

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Is it documented somewhere that materials for UITextures should not use UV offset or scale? I don't remember seeing that.
I know I can set the UV rect on the UITexture, but when I have several UITextures showing the same thing in different places it's much more convenient to keep such information in the material instead of each UITexture instance.
If the soft clipping shaders use a separate vector for clipping information instead of overloading the main texture offset and scale, there's no need to break that functionality.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
In most cases you would not be specifying a material on the UITexture. You'd reference the texture, and material would be created behind the scenes. The material offset has never been used by NGUI. Thinking back, I can't recall if this was ever brought up before.

damthauer

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
I don't really see a justification for breaking a feature intrinsic to Unity materials, which users would reasonably expect to just work. Especially since it still works in most cases, just not with clipping.

I assume this also doesn't work on 3.5.6, then?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
You can make it work if you want, but in 99.9% cases you wouldn't need this, so I chose to omit this matrix multiplication operation from the shader.

Currently the vertex shader is like this:
  1.                         v2f vert (appdata_t v)
  2.                         {
  3.                                 v2f o;
  4.                                 o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
  5.                                 o.texcoord = v.texcoord;
  6.                                 o.color = v.color;
  7.                                 return o;
  8.                         }
In your case you would need it to be:
  1.                         v2f vert (appdata_t v)
  2.                         {
  3.                                 v2f o;
  4.                                 o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
  5.                                 o.texcoord = TRANSFORM_TEX(v.texcoord, MainTex); // <-- this line changes
  6.                                 o.color = v.color;
  7.                                 return o;
  8.                         }
Just copy the Unlit/Transparent Colored shader and make your own version with that line in there.