Search Unity

  1. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice
  2. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  3. Unity 2017.2 is now released.
    Dismiss Notice
  4. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  5. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  7. Unity 2017.3 beta is now available for download.
    Dismiss Notice

Normal values on iOS

Discussion in 'Shaders' started by HappyDumpling, Apr 13, 2012.

  1. HappyDumpling


    Apr 13, 2012

    I wrote shader in CG, which is working on PC and MAC, but i have problem with iPhone and iPad. My shader receive some global variables and use some vertex variables. My vertex input struct is:
    Code (csharp):
    1. struct Input
    2. {      
    3.     float4 vertex : POSITION;  
    4.     float4 color : COLOR;
    5.     float3 normal : NORMAL;
    6.     float2 texcoord : TEXCOORD0;
    7.     float2 texcoord1 : TEXCOORD1;
    8. };
    I'm using normal, texcoords in my way, avoiding typical usage. Normals are used to set custom offset/resize of model (when its grow or disapear), texcoords to set graphics effects. Everything working without (i think) normal, because i think on iOS its clamped to -1;1 range. Someone have similar problem? Its possible iOS clamps normals? Other functionalities of shader works without part bounded up with normals.
    Maybe exists special flags for shader compiler?

    Sorry for my english.

    I will be glad for help.
  2. Lamont


    Dec 1, 2010
    I think it should be like the following-

    float4 _POSITION;
    float4 _COLOR;
    float3 _NORMAL;
    float2 uv_MyTexCoordName;//prefix of uv_ is UV Channel 1
    float2 uv2_MyTexCoordName; //prefix of uv2_ is UV Channel 2
  3. Alesk


    Jul 15, 2010

    I've got a similar problem (and Lamont's explanation wasn't clear enough to help), and don't understand what's happening.
    I'm generating a mesh for a particles system, and I use normal (x component) to store the particle age in each vertex
    (and the y component is used to store particle luminosity.)

    Using this shader to see the normals
    Code (csharp):
    1. Shader "!Debug/Normals" {
    2. SubShader {
    3.     Pass {
    4.         Fog { Mode Off }
    6. #pragma vertex vert
    7. #pragma fragment frag
    9. // vertex input: position, normal
    10. struct appdata {
    11.     float4 vertex : POSITION;
    12.     float3 normal : NORMAL;
    13. };
    15. struct v2f {
    16.     float4 pos : SV_POSITION;
    17.     fixed4 color : COLOR;
    18. };
    19. v2f vert (appdata v) {
    20.     v2f o;
    21.     o.pos = mul( UNITY_MATRIX_MVP, v.vertex );
    22. = v.normal * 0.5 + 0.5;
    23.     o.color.w = 1.0;
    24.     return o;
    25. }
    26. fixed4 frag (v2f i) : COLOR0 { return i.color; }
    27. ENDCG
    28.     }
    29. }
    30. }
    young particle (smallest ones) are luminous, so they are displayed as green, and become pink (and bigger) while aging.

    the editor shows the expected result :
    $Bildschirmfoto 2014-01-28 um 15.15.45.png

    while the iOS devices shows this : $2014-01-28 15.15.24.png

    The normal values seems to be clamped or rounded.
    What am I missing ?
    Last edited: Jan 29, 2014
  4. Alesk


    Jul 15, 2010