Search Unity

Custom shader not rendering in iOS

Discussion in 'Shaders' started by Deadshot1994, Dec 9, 2020.

  1. Deadshot1994

    Deadshot1994

    Joined:
    Sep 6, 2015
    Posts:
    25
    I have a custom shader that is not rendering in iOS, but it works in the editor/game view and on Android as intended.

    I will post its code in hopes of getting some help. I added it as an always-included shader, but it still won't render in iOS.

    I will post the code for the shader in hopes of getting some help.

    Code (CSharp):
    1. Shader "_FP48/Unlit_Outline"
    2. {
    3.     Properties
    4.     {
    5.         _EdgeLength ( "Edge length", Range( 2, 50 ) ) = 15
    6.         _Texture("Texture", 2D) = "white" {}
    7.         [Header(Shadow)]_ShadowClipValue("Shadow Clip Value", Float) = -0.05
    8.         _ShadowColor("Shadow Color", Color) = (0.1926397,0.314921,0.3679245,0)
    9.         _ShadowOpacity("Shadow Opacity", Range( 0 , 1)) = 0.43
    10.         [Header(Outline)]_OutlineColor("Outline Color", Color) = (0,0,0,0)
    11.         _OutlineWidth("Outline Width", Range( 0 , 0.02)) = 0
    12.         [Header(Inner Outline)][Toggle(_USEINNEROUTLINE_ON)] _UseInnerOutline("Use Inner Outline ? ", Float) = 0
    13.         _InnerOutlineWidth("Inner Outline Width", Range( 0 , 0.2)) = 0
    14.         _AmbiantOcclusion("Ambiant Occlusion", 2D) = "white" {}
    15.         [Normal]_NormalMap("Normal Map", 2D) = "bump" {}
    16.         [HideInInspector] _texcoord( "", 2D ) = "white" {}
    17.         [HideInInspector] __dirty( "", Int ) = 1
    18.     }
    19.  
    20.     SubShader
    21.     {
    22.         Tags{ }
    23.         Cull Front
    24.         CGPROGRAM
    25.         #include "Tessellation.cginc"
    26.         #pragma target 4.6
    27.         #pragma surface outlineSurf Outline nofog  keepalpha noshadow noambient novertexlights nolightmap nodynlightmap nodirlightmap nometa noforwardadd vertex:outlineVertexDataFunc tessellate:tessFunction
    28.         void outlineVertexDataFunc( inout appdata_full v )
    29.         {
    30.             float outlineVar = _OutlineWidth;
    31.             v.vertex.xyz += ( v.normal * outlineVar );
    32.         }
    33.         inline half4 LightingOutline( SurfaceOutput s, half3 lightDir, half atten ) { return half4 ( 0,0,0, s.Alpha); }
    34.         void outlineSurf( Input i, inout SurfaceOutput o )
    35.         {
    36.             o.Emission = _OutlineColor.rgb;
    37.         }
    38.         ENDCG
    39.    
    40.  
    41.         Tags{ "RenderType" = "Opaque"  "Queue" = "Geometry+0" }
    42.         Cull Back
    43.         CGINCLUDE
    44.         #include "UnityPBSLighting.cginc"
    45.         #include "UnityCG.cginc"
    46.         #include "Tessellation.cginc"
    47.         #include "Lighting.cginc"
    48.         #pragma target 4.6
    49.         #pragma shader_feature _USEINNEROUTLINE_ON
    50.         #ifdef UNITY_PASS_SHADOWCASTER
    51.             #undef INTERNAL_DATA
    52.             #undef WorldReflectionVector
    53.             #undef WorldNormalVector
    54.             #define INTERNAL_DATA half3 internalSurfaceTtoW0; half3 internalSurfaceTtoW1; half3 internalSurfaceTtoW2;
    55.             #define WorldReflectionVector(data,normal) reflect (data.worldRefl, half3(dot(data.internalSurfaceTtoW0,normal), dot(data.internalSurfaceTtoW1,normal), dot(data.internalSurfaceTtoW2,normal)))
    56.             #define WorldNormalVector(data,normal) half3(dot(data.internalSurfaceTtoW0,normal), dot(data.internalSurfaceTtoW1,normal), dot(data.internalSurfaceTtoW2,normal))
    57.         #endif
    58.         struct Input
    59.         {
    60.             float3 worldNormal;
    61.             INTERNAL_DATA
    62.             float2 uv_texcoord;
    63.             float3 worldPos;
    64.         };
    65.  
    66.         struct SurfaceOutputCustomLightingCustom
    67.         {
    68.             half3 Albedo;
    69.             half3 Normal;
    70.             half3 Emission;
    71.             half Metallic;
    72.             half Smoothness;
    73.             half Occlusion;
    74.             half Alpha;
    75.             Input SurfInput;
    76.             UnityGIInput GIData;
    77.         };
    78.  
    79.         uniform sampler2D _NormalMap;
    80.         uniform float4 _NormalMap_ST;
    81.         uniform sampler2D _Texture;
    82.         uniform float4 _Texture_ST;
    83.         uniform float4 _ShadowColor;
    84.         uniform float _ShadowOpacity;
    85.         uniform float _ShadowClipValue;
    86.         uniform float4 _OutlineColor;
    87.         uniform float _InnerOutlineWidth;
    88.         uniform sampler2D _AmbiantOcclusion;
    89.         uniform float4 _AmbiantOcclusion_ST;
    90.         uniform float _EdgeLength;
    91.         uniform float _OutlineWidth;
    92.  
    93.         float4 tessFunction( appdata_full v0, appdata_full v1, appdata_full v2 )
    94.         {
    95.             return UnityEdgeLengthBasedTess (v0.vertex, v1.vertex, v2.vertex, _EdgeLength);
    96.         }
    97.  
    98.         void vertexDataFunc( inout appdata_full v )
    99.         {
    100.             v.vertex.xyz += 0;
    101.         }
    102.  
    103.         inline half4 LightingStandardCustomLighting( inout SurfaceOutputCustomLightingCustom s, half3 viewDir, UnityGI gi )
    104.         {
    105.             UnityGIInput data = s.GIData;
    106.             Input i = s.SurfInput;
    107.             half4 c = 0;
    108.             SurfaceOutputStandard s34 = (SurfaceOutputStandard ) 0;
    109.             s34.Albedo = float3( 0,0,0 );
    110.             float2 uv_NormalMap = i.uv_texcoord * _NormalMap_ST.xy + _NormalMap_ST.zw;
    111.             s34.Normal = WorldNormalVector( i , UnpackNormal( tex2D( _NormalMap, uv_NormalMap ) ) );
    112.             float2 uv_Texture = i.uv_texcoord * _Texture_ST.xy + _Texture_ST.zw;
    113.             float4 tex2DNode1 = tex2D( _Texture, uv_Texture );
    114.             float4 lerpResult13 = lerp( float4( 1,1,1,0 ) , _ShadowColor , _ShadowOpacity);
    115.             float3 ase_worldPos = i.worldPos;
    116.             #if defined(LIGHTMAP_ON) && UNITY_VERSION < 560 //aseld
    117.             float3 ase_worldlightDir = 0;
    118.             #else //aseld
    119.             float3 ase_worldlightDir = normalize( UnityWorldSpaceLightDir( ase_worldPos ) );
    120.             #endif //aseld
    121.             float3 ase_worldNormal = WorldNormalVector( i, float3( 0, 0, 1 ) );
    122.             float dotResult4 = dot( ase_worldlightDir , ase_worldNormal );
    123.             float temp_output_6_0 = step( dotResult4 , _ShadowClipValue );
    124.             float4 lerpResult9 = lerp( ( tex2DNode1 * lerpResult13 ) , tex2DNode1 , ( 1.0 - temp_output_6_0 ));
    125.             float temp_output_19_0 = ( _ShadowClipValue + _InnerOutlineWidth );
    126.             float temp_output_3_0_g1 = ( temp_output_19_0 - dotResult4 );
    127.             float4 lerpResult25 = lerp( lerpResult9 , _OutlineColor , saturate( ( saturate( ( temp_output_3_0_g1 / fwidth( temp_output_3_0_g1 ) ) ) - temp_output_6_0 ) ));
    128.             #ifdef _USEINNEROUTLINE_ON
    129.                 float4 staticSwitch29 = lerpResult25;
    130.             #else
    131.                 float4 staticSwitch29 = lerpResult9;
    132.             #endif
    133.             s34.Emission = staticSwitch29.rgb;
    134.             s34.Metallic = 0.0;
    135.             s34.Smoothness = 0.0;
    136.             float2 uv_AmbiantOcclusion = i.uv_texcoord * _AmbiantOcclusion_ST.xy + _AmbiantOcclusion_ST.zw;
    137.             s34.Occlusion = tex2D( _AmbiantOcclusion, uv_AmbiantOcclusion ).r;
    138.  
    139.             data.light = gi.light;
    140.  
    141.             UnityGI gi34 = gi;
    142.             #ifdef UNITY_PASS_FORWARDBASE
    143.             Unity_GlossyEnvironmentData g34 = UnityGlossyEnvironmentSetup( s34.Smoothness, data.worldViewDir, s34.Normal, float3(0,0,0));
    144.             gi34 = UnityGlobalIllumination( data, s34.Occlusion, s34.Normal, g34 );
    145.             #endif
    146.  
    147.             float3 surfResult34 = LightingStandard ( s34, viewDir, gi34 ).rgb;
    148.             surfResult34 += s34.Emission;
    149.  
    150.             #ifdef UNITY_PASS_FORWARDADD//34
    151.             surfResult34 -= s34.Emission;
    152.             #endif//34
    153.             c.rgb = surfResult34;
    154.             c.a = 1;
    155.             return c;
    156.         }
    157.  
    158.         inline void LightingStandardCustomLighting_GI( inout SurfaceOutputCustomLightingCustom s, UnityGIInput data, inout UnityGI gi )
    159.         {
    160.             s.GIData = data;
    161.         }
    162.  
    163.         void surf( Input i , inout SurfaceOutputCustomLightingCustom o )
    164.         {
    165.             o.SurfInput = i;
    166.             o.Normal = float3(0,0,1);
    167.         }
    168.  
    169.         ENDCG
    170.         CGPROGRAM
    171.         #pragma surface surf StandardCustomLighting keepalpha fullforwardshadows exclude_path:deferred nolightmap  nodirlightmap vertex:vertexDataFunc tessellate:tessFunction
    172.  
    173.         ENDCG
    174.         Pass
    175.         {
    176.             Name "ShadowCaster"
    177.             Tags{ "LightMode" = "ShadowCaster" }
    178.             ZWrite On
    179.             CGPROGRAM
    180.             #pragma vertex vert
    181.             #pragma fragment frag
    182.             #pragma target 4.6
    183.             #pragma multi_compile_shadowcaster
    184.             #pragma multi_compile UNITY_PASS_SHADOWCASTER
    185.             #pragma skip_variants FOG_LINEAR FOG_EXP FOG_EXP2
    186.             #include "HLSLSupport.cginc"
    187.             #if ( SHADER_API_D3D11 || SHADER_API_GLCORE || SHADER_API_GLES || SHADER_API_GLES3 || SHADER_API_METAL || SHADER_API_VULKAN )
    188.                 #define CAN_SKIP_VPOS
    189.             #endif
    190.             #include "UnityCG.cginc"
    191.             #include "Lighting.cginc"
    192.             #include "UnityPBSLighting.cginc"
    193.             struct v2f
    194.             {
    195.                 V2F_SHADOW_CASTER;
    196.                 float2 customPack1 : TEXCOORD1;
    197.                 float4 tSpace0 : TEXCOORD2;
    198.                 float4 tSpace1 : TEXCOORD3;
    199.                 float4 tSpace2 : TEXCOORD4;
    200.                 UNITY_VERTEX_INPUT_INSTANCE_ID
    201.                 UNITY_VERTEX_OUTPUT_STEREO
    202.             };
    203.             v2f vert( appdata_full v )
    204.             {
    205.                 v2f o;
    206.                 UNITY_SETUP_INSTANCE_ID( v );
    207.                 UNITY_INITIALIZE_OUTPUT( v2f, o );
    208.                 UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO( o );
    209.                 UNITY_TRANSFER_INSTANCE_ID( v, o );
    210.                 Input customInputData;
    211.                 vertexDataFunc( v );
    212.                 float3 worldPos = mul( unity_ObjectToWorld, v.vertex ).xyz;
    213.                 half3 worldNormal = UnityObjectToWorldNormal( v.normal );
    214.                 half3 worldTangent = UnityObjectToWorldDir( v.tangent.xyz );
    215.                 half tangentSign = v.tangent.w * unity_WorldTransformParams.w;
    216.                 half3 worldBinormal = cross( worldNormal, worldTangent ) * tangentSign;
    217.                 o.tSpace0 = float4( worldTangent.x, worldBinormal.x, worldNormal.x, worldPos.x );
    218.                 o.tSpace1 = float4( worldTangent.y, worldBinormal.y, worldNormal.y, worldPos.y );
    219.                 o.tSpace2 = float4( worldTangent.z, worldBinormal.z, worldNormal.z, worldPos.z );
    220.                 o.customPack1.xy = customInputData.uv_texcoord;
    221.                 o.customPack1.xy = v.texcoord;
    222.                 TRANSFER_SHADOW_CASTER_NORMALOFFSET( o )
    223.                 return o;
    224.             }
    225.             half4 frag( v2f IN
    226.             #if !defined( CAN_SKIP_VPOS )
    227.             , UNITY_VPOS_TYPE vpos : VPOS
    228.             #endif
    229.             ) : SV_Target
    230.             {
    231.                 UNITY_SETUP_INSTANCE_ID( IN );
    232.                 Input surfIN;
    233.                 UNITY_INITIALIZE_OUTPUT( Input, surfIN );
    234.                 surfIN.uv_texcoord = IN.customPack1.xy;
    235.                 float3 worldPos = float3( IN.tSpace0.w, IN.tSpace1.w, IN.tSpace2.w );
    236.                 half3 worldViewDir = normalize( UnityWorldSpaceViewDir( worldPos ) );
    237.                 surfIN.worldPos = worldPos;
    238.                 surfIN.worldNormal = float3( IN.tSpace0.z, IN.tSpace1.z, IN.tSpace2.z );
    239.                 surfIN.internalSurfaceTtoW0 = IN.tSpace0.xyz;
    240.                 surfIN.internalSurfaceTtoW1 = IN.tSpace1.xyz;
    241.                 surfIN.internalSurfaceTtoW2 = IN.tSpace2.xyz;
    242.                 SurfaceOutputCustomLightingCustom o;
    243.                 UNITY_INITIALIZE_OUTPUT( SurfaceOutputCustomLightingCustom, o )
    244.                 surf( surfIN, o );
    245.                 #if defined( CAN_SKIP_VPOS )
    246.                 float2 vpos = IN.pos;
    247.                 #endif
    248.                 SHADOW_CASTER_FRAGMENT( IN )
    249.             }
    250.             ENDCG
    251.         }
    252.     }
    253.     Fallback "Diffuse"
    254.     CustomEditor "ASEMaterialInspector"
    255. }
    EDIT:
    Whenever I choose this shader for the GameObject I get this warning

    Could not create a custom UI for the shader '_FP48/Unlit_Outline'. The shader has the following: 'CustomEditor = ASEMaterialInspector'. Does the custom editor specified include its namespace? And does the class either derive from ShaderGUI or MaterialEditor?
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr) (at /Users/builduser/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:197)
     
    Last edited: Dec 9, 2020
  2. CosmoM

    CosmoM

    Joined:
    Oct 31, 2015
    Posts:
    204