Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Lose vertex animation on Iphone

Discussion in 'Shaders' started by zhutianlun810, Jan 9, 2020.

  1. zhutianlun810

    zhutianlun810

    Joined:
    Sep 17, 2017
    Posts:
    165
    Hello,

    I did some vertex animation job by using uv2 and uv3 (in shader). However, when I test my scene on Iphone8. I find that the vertex animation is wrong. Does iphone support uv2 and uv3?
     
  2. Dorodo

    Dorodo

    Joined:
    Mar 8, 2015
    Posts:
    44
    any iOS device will support up to 16 interpolators (texcoords, for example). As stated in the documentation:

    • Up to 8 interpolators: OpenGL ES 2.0 (iOS/Android), Direct3D 11 9.x level (Windows Phone) and Direct3 9 shader model 2.0 (old PCs). Since the interpolator count is limited, but each interpolator can be a 4-component vector, some shaders pack things together to stay within limits. For example, two texture coordinates can be passed in one float4 variable (.xy for one coordinate, .zw for the second coordinate).
    • Up to 10 interpolators: Direct3D 9 shader model 3.0 (#pragma target 3.0).
    • Up to 16 interpolators: OpenGL ES 3.0 (iOS/Android), Metal (iOS).
    • Up to 32 interpolators: Direct3D 10 shader model 4.0 (#pragma target 4.0).
    iPhone 8 uses the Metal API, so there should be no problem. Can you be more specific as to how it doesn't work? Does the shader not compile? Does it render without any vertex animation? Is the animation different than what you saw on the editor?
     
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    Interpolations are the values passed between the vertex and the fragment shader. It has nothing to do with how many values are passed to the vertex shader from the mesh.

    All platforms support uv2 & uv3, even old GLES 2.0 devices do that just fine.
     
  4. Dorodo

    Dorodo

    Joined:
    Mar 8, 2015
    Posts:
    44
    @bgolus Interesting. So getting extra Texcoords for Tex2D lod operations on the vertex shader (such as vertex displacement) would not increase the amount of interpolators used by the shader? My apologies for any confusion.
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    Interpolators refer to vertex shader outputs, because that data is interpolated using triangle barycentrics before the fragment shader gets it.

    The vertex shader inputs are the per vertex mesh data as is, without any interpolation. GPUs can actually support a lot more mesh data than Unity allows, even old GLES 2.0 devices.

    My guess is the issue @zhutianlun810 is having is more to do with what “uv2” is in the shader. If when you say “uv2” you’re referring to
    mesh.uv2
    , then in the shader that’s
    TEXCOORD1
    . This is because the c# mesh uv properties are 1 using based indexing, and the shader (and c# SetUVs) is using 0 based indexing.

    Additionally if the mesh is static then Unity may be overwriting that UV since it’s the one Unity uses for light maps. Same with “uv3” which is used for Enlighten’s dynamic GI. So if either of those are enabled,
    TEXCOORD1
    and
    TEXCOORD2
    may be getting modified.
     
    Dorodo likes this.
  6. zhutianlun810

    zhutianlun810

    Joined:
    Sep 17, 2017
    Posts:
    165
    I've solved the problem. The debug is caused by Vertex Compression Option in Player Setting. It will compress some data from float4 to half4. I have some data exceed the range of half. Therefore, they will be inf and I can't see any vertex drawn on the screen.