Byphenil Blue Marble planet and atmospheric shaders

Hi guys, I wonder if anybody tried his marvelous tutorial shaders on iOS

On iPad2, the planet shaders is working fine (very similar to other planet shaders posted on the forum),
but the Clouds atmospheric shader, is hanging the device in a brutal crash.

I’m using the second varied version, the one with the RGB Ramp to make the scattering look better.
Is working great on Mac / Editor !

This is the shader source:

// Planet Clouds Surface Shader by Matt Mechtley
// Licensed Under a Creative Commons Attribution license
// http://creativecommons.org/licenses/by/3.0/
Shader "Custom/Clouds" {
	Properties {
		_MainTex ("Alpha (A)", 2D) = "white" {}
		_AtmosRamp ("Atmosphere Ramp (RG or B)", 2D) = "black" {}
		_RimColor ("Rim Color", Color) = (0.26,0.19,0.16,0.0)
	}
	SubShader {
		Tags { "RenderType"="Transparent" }
		
		CGPROGRAM
		#pragma surface surf WrapLambert alpha
		
		struct Input {
			float2 uv_MainTex;
			float3 viewDir;
		};
		sampler2D _MainTex;
		sampler2D _AtmosRamp;
	
		void surf (Input IN, inout SurfaceOutput o) {
			float2 uv_Ramp = 1.0 - saturate(dot (normalize(IN.viewDir), o.Normal));
			o.Specular = tex2D (_AtmosRamp, uv_Ramp).r;
			o.Alpha = tex2D (_MainTex, IN.uv_MainTex).a + o.Specular;
		}
		
		half4 _RimColor;
		
		half4 LightingWrapLambert (SurfaceOutput s, half3 lightDir, half atten) {
			half NdotL = dot (s.Normal, lightDir);
			half diffuse = max(0, NdotL* 0.9 + 0.1);
			half4 c;
			c.rgb = (atten * 2) * _LightColor0.rgb * diffuse * (1.0 - s.Specular)
				+ (diffuse * s.Specular * _RimColor);
			c.a = s.Alpha;
			return c;
		}
		ENDCG
	} 
	FallBack "Diffuse"
}

What can be the not-supported-by-iPad instruction here ?
It seems all great, infact works great in the editor, but sadly, on iPad crashes.

The planet shader with bumps/emissive night texture etcetera is working great also on device.

I debugged a little this issue.
It seems to be something with this line in the WrapLamber light calculation:

 c.rgb = (atten * 2) * _LightColor0.rgb * diffuse * (1.0 - s.Specular)  + (diffuse * s.Specular * _RimColor);

If I change that line to something like:

 c.rgb = (atten * 2) * s.Albedo * _LightColor0.rgb * diffuse * _RimColor;

It is not crashing anymore the iPad2 in the GLSL compilation (debugged on XCode, follows some debug info)
Of course is not looking anymore anything like it is supposed to.

So it seems s.Specular is not digested somehow, but we have other shaders that uses this instruction working fine on iPad(s) 2 and 3, what can be to crash PowerVR compiler ???

It’s difficult for me to understand from this debug information I got switching back to GDB (from Apple LLDB)

0xc1b920 <_ZNSt8_Rb_treeIN12ShaderErrors11ShaderErrorES1_St9_IdentityIS1_ESt4lessIS1_ESaIS1_EE13_Rb_tree_implIS5_Lb0EEC2ERKSaISt13_Rb_tree_nodeIS1_EERKS5_>
0x00dc7cc8  <+0120>  mov	r6, #0	; 0x0
0x00dc7ccc  <+0124>  str	r6, [sp, #292]
0x00dc7cd0  <+0128>  bl	0xd24974 <_Z12GetGfxDevicev>
0x00dc7cd4  <+0132>  movw	r3, #4852	; 0x12f4
0x00dc7cd8  <+0136>  mov	r1, r10
0x00dc7cdc  <+0140>  add	r2, sp, #292	; 0x124
0x00dc7ce0  <+0144>  ldr	r3, [r0, r3]
0x00dc7ce4  <+0148>  mov	r0, r8
0x00dc7ce8  <+0152>  str	r3, [sp]
0x00dc7cec  <+0156>  add	r3, sp, #268	; 0x10c
0x00dc7cf0  <+0160>  bl	0xdf7b18 <_Z11ParseShaderPKcmPPN9ShaderLab12ParserShaderER12ShaderErrors17GfxDeviceRenderer>
0x00dc7cf4  <+0164>  ldr	r4, [sp, #292]
0x00dc7cf8  <+0168>  cmp	r4, r6



0x00df7b84  <+0008>  bl	0xdf78ac <_ZN9ShaderLab9IntShader22CreateFromParsedShaderERKNS_12ParserShaderER12ShaderErrors>
0x00df7b88  <+0012>  subs	r5, r0, #0	; 0x0
0x00df7b8c  <+0016>  beq	0xdf7bf8 <_Z11ParseShaderPKcmPPN9ShaderLab12ParserShaderER12ShaderErrors17GfxDeviceRenderer+224>


0x00df7a7c  <+0464>  bl	0xdf7608 <_ZN9ShaderLab9SubShader25CreateFromParsedSubShaderERKNS_15ParserSubShaderERSt6vectorIlSaIlEER12ShaderErrors>
0x00df7a80  <+0468>  cmp	r0, #0	; 0x0
0x00df7a84  <+0472>  str	r0, [sp, #36]


0x00df768c  <+0132>  bl	0xdf73ec <_ZN9ShaderLab4Pass20CreateFromParsedPassERKNS_10ParserPassER12ShaderErrorsR13dynamic_arrayIiE>
0x00df7690  <+0136>  add	r1, sp, #300	; 0x12c
0x00df7694  <+0140>  str	r0, [sp, #300]


0x00df749c  <+0176>  mov	r1, r11
0x00df74a0  <+0180>  bl	0xdf7310 <_ZN9ShaderLab7Program23CreateFromParsedProgramERKNS_13ParserProgramER12ShaderErrors>
0x00df74a4  <+0184>  ldr	r3, [sp, #12]

0x00c1b81c  <+0192>  bl	0xc1b4a0 <_ZN20GlslGpuProgramGLES206CreateERKSsRN9ShaderLab14ChannelAssignsE>
0x00c1b820  <+0196>  cmp	r0, #0	; 0x0
0x00c1b824  <+0200>  beq	0xc1b854 <_ZN20GlslGpuProgramGLES20C2ERN9ShaderLab10SubProgramERKSs+248>

Any words on this ?
Has anybody falled into this or similar problem ?

Thank you in advance,

You have no link saying what “Byphenil Blue Marble planet and atmospheric shaders” is. I believe this is the appropriate link, which seems very interesting.

http://biphenyl.org/blog/2012/04/24/unity3d-surface-shader-tutorial/

Yes that is it.
Do you have idea of the reason why it makes explode the iPad2 PowerVR card ??