#version 300 es // Metal translation was producing a wrong typecast // on o.backContrib[j] = (backContrib * 2.0) expression; // was thinking LHS is a float3 #define gl_Vertex _glesVertex in vec4 _glesVertex; #define gl_Normal _glesNormal in vec3 _glesNormal; float xll_saturate_f( float x) { return clamp( x, 0.0, 1.0); } struct appdata_full { highp vec4 vertex; highp vec3 normal; }; struct v2f { highp vec4 pos; highp vec3 backContrib; }; uniform highp vec3 _WorldSpaceCameraPos; uniform highp mat4 glstate_matrix_mvp; uniform highp mat4 _World2Object; uniform highp vec3 _TerrainTreeLightDirections[4]; highp vec3 ObjSpaceViewDir( in highp vec4 v ) { highp vec3 objSpaceCameraPos = (_World2Object * vec4( _WorldSpaceCameraPos.xyz, 1.0)).xyz; return (objSpaceCameraPos - v.xyz); } v2f vert( in appdata_full v ) { v2f o; o.pos = (glstate_matrix_mvp * v.vertex); highp vec3 viewDir = normalize(ObjSpaceViewDir( v.vertex)); highp int j = 0; for ( ; (j < 3); (j++)) { highp vec3 lightDir = _TerrainTreeLightDirections[j]; mediump float nl = dot( v.normal, lightDir); mediump float backContrib = xll_saturate_f(dot( viewDir, (-lightDir))); o.backContrib[j] = (backContrib * 2.0); } return o; } out highp vec3 xlv_TEXCOORD2; void main() { v2f xl_retval; appdata_full xlt_v; xlt_v.vertex = vec4(gl_Vertex); xlt_v.normal = vec3(gl_Normal); xl_retval = vert( xlt_v); gl_Position = vec4(xl_retval.pos); xlv_TEXCOORD2 = vec3(xl_retval.backContrib); }