Unity Community


Results 1 to 4 of 4

  1. Posts
    1

    Normal values on iOS

    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:  
    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. Location
    Osaka Japan
    Posts
    102
    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
    Lamont G
    Well-fed Hobo
    CGBYLG.com


  3. Location
    Bordeaux - France
    Posts
    178
    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:  
    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 :
    Name:  Bildschirmfoto 2014-01-28 um 15.15.45.png
Views: 51
Size:  53.5 KB

    while the iOS devices shows this : Name:  2014-01-28 15.15.24.png
Views: 52
Size:  57.3 KB

    The normal values seems to be clamped or rounded.
    What am I missing ?
    Last edited by Alesk; 01-29-2014 at 12:26 AM.


  4. Location
    Bordeaux - France
    Posts
    178
    Yay !

    Solution found here : http://forum.unity3d.com/threads/140...ize-to-normals

    Quote Originally Posted by Aras View Post
    In CGPROGRAM block:
    Code:  
    1. #pragma glsl_no_auto_normalization
    This will stop normalizing normals and tangents.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •