1. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  2. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  3. We’re giving 2017.1 beta testers a chance to win t-shirts and a Nintendo Switch. Read more on the blog.
    Dismiss Notice
  4. Unity 2017.1 beta is now available for download.
    Dismiss Notice
  5. Unity 5.6 is now released.
    Dismiss Notice
  6. Get further faster with the Unity Plus Accelerator Pack, free for new Unity Plus subscribers for a limited time. Click here for more details.
    Dismiss Notice
  7. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  8. Learn how you'll soon be able to publish your games to China in four simple steps with Xiaomi. Sign up now for early access.
    Dismiss Notice

Normal values on iOS

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

  1. HappyDumpling

    HappyDumpling

    Joined:
    Apr 13, 2012
    Posts:
    1
    Hi!

    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

    Lamont

    Joined:
    Dec 1, 2010
    Posts:
    114
    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

    Alesk

    Joined:
    Jul 15, 2010
    Posts:
    260
    Hi,

    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 }
    5. CGPROGRAM
    6. #pragma vertex vert
    7. #pragma fragment frag
    8.  
    9. // vertex input: position, normal
    10. struct appdata {
    11.     float4 vertex : POSITION;
    12.     float3 normal : NORMAL;
    13. };
    14.  
    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

    Alesk

    Joined:
    Jul 15, 2010
    Posts:
    260