Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

Curve shader works fine on Windows, Android, macOS (Metal) but doesn't work properly for iOS (Metal)

Discussion in 'Shaders' started by zero_null, Sep 26, 2018.

  1. zero_null

    zero_null

    Joined:
    Mar 11, 2014
    Posts:
    159
    Hey Guys,
    I am using a curve shader from open source that works just fine on all the platforms, even with Metal API for macOS. It just doesn't seem to work properly for iOS devices using Metal API. I am using gamma color space so it's kind of necessary for me to use Metal and also the latest iOS and macOS has deprecated OpenGL API.
    Can anyone tell if that really has to do something with the shader?
    Here is my shader code.

    Code (CSharp):
    1. Shader "Custom/CurvedWorld" {
    2.     Properties {
    3.         // Diffuse texture
    4.         _MainTex ("Base (RGB)", 2D) = "white" {}
    5.         // Degree of curvature
    6.         _Curvature ("Curvature", Float) = 0.001
    7.     }
    8.     SubShader {
    9.         Tags { "RenderType"="Opaque" }
    10.         LOD 200
    11.         CGPROGRAM
    12.         // Surface shader function is called surf, and vertex preprocessor function is called vert
    13.         // addshadow used to add shadow collector and caster passes following vertex modification
    14.         #pragma surface surf Lambert vertex:vert addshadow
    15.         // Access the shaderlab properties
    16.         uniform sampler2D _MainTex;
    17.         uniform float _Curvature;
    18.         // Basic input structure to the shader function
    19.         // requires only a single set of UV texture mapping coordinates
    20.         struct Input {
    21.             float2 uv_MainTex;
    22.         };
    23.         // This is where the curvature is applied
    24.         void vert( inout appdata_full v)
    25.         {
    26.             // Transform the vertex coordinates from model space into world space
    27.             float4 vv = mul( _Object2World, v.vertex );
    28.             // Now adjust the coordinates to be relative to the camera position
    29.             vv.xyz -= _WorldSpaceCameraPos.xyz;
    30.             // Reduce the y coordinate (i.e. lower the "height") of each vertex based
    31.             // on the square of the distance from the camera in the z axis, multiplied
    32.             // by the chosen curvature factor
    33.             vv = float4( 0.0f, (vv.z * vv.z) * - _Curvature, 0.0f, 0.0f );
    34.             // Now apply the offset back to the vertices in model space
    35.             v.vertex += mul(_World2Object, vv);
    36.         }
    37.         // This is just a default surface shader
    38.         void surf (Input IN, inout SurfaceOutput o) {
    39.             half4 c = tex2D (_MainTex, IN.uv_MainTex);
    40.             o.Albedo = c.rgb;
    41.             o.Alpha = c.a;
    42.         }
    43.         ENDCG
    44.     }
    45.     // FallBack "Diffuse"
    46. }
     
  2. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,448
    That's not really enough information to offer any help. In which way does it not work?
     
unityunity