1. Some Unity services have been affected by the DDoS of large DNS provider today. Click here for more information.
  2. Become a closed-alpha partner on the new Facebook games platform. Read more about it here.
  3. Enter the Samsung TIZEN App Challenge for a chance to win prizes. Read more about it here.
  4. The 5.5 Beta is now available. Click here for more details!
  5. Get early access to our Google Daydream Technical preview. Click here for more details!

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.     o.color.xyz = 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