static const GLchar *plug_vertex_lighting_ADSLightModel = "\n\ /* use ADSLightModel here the ADS colour is returned from the function. */ \n\ void PLUG_add_light_contribution2 (inout vec3 vertexcolor, inout vec3 specularcolor, in vec4 myPosition, in vec3 myNormal, \n\ in float mat_shininess, in float mat_ambient, in vec3 mat_diffuse, in vec3 mat_specular){ \n\ //working in eye space: eye is at 0,0,0 looking generally in direction 0,0,-1 \n\ //myPosition, myNormal - of surface vertex, in eyespace \n\ //vertexcolor - diffuse+ambient -will be replaced or modulated by texture color \n\ //specularcolor - specular+emissive or non-diffuse (emissive added outside this function) \n\ //algo: uses Blinn-Phong specular reflection: half-vector pow(N*H,shininess) \n\ // https://www.web3d.org/documents/specifications/19775-1/V3.3/Part01/components/lighting.html#Lightingequations \n\ // fog and emissive are done elsewhere, this function does: \n\ // SUM(on[i] x attenuation[i] x spot[i] x ILrgb[i] x (ambient[i] + diffuse[i] + specular[i])) \n\ int i; \n\ vec3 N = normalize (myNormal); \n\ \n\ vec3 E = -normalize(myPosition.xyz); \n \ \n\ // apply the lights to this material \n\ // weird but ANGLE needs constant loop \n\ vec3 sum_vertex = vec3(0.,0.,0.); \n\ vec3 sum_specular = vec3(0.,0.,0.); \n\ for (i=0; i light.lightRadius) on = 0.0; \n\ attenuation = 1.0/max(1.0,(light.Attenuations.x + (light.Attenuations.y * D) + (light.Attenuations.z *D*D))); \n\ } \n\ float NdotL = max(dot(N, L), 0.0); //Lambertian diffuse term \n\ //specular reflection models, phong or blinn-phong \n\ //#define PHONG 1 \n\ #ifdef PHONG \n\ //Phong \n\ vec3 R = normalize(-reflect(L,N)); \n\ float RdotE = max(dot(R,E),0.0); \n\ float specbase = RdotE; \n\ // assume shader gets shininess in 0 to 1 range, and scales it to 0 to 128 range here \n\ float specpow = mat_shininess*128.0; \n\ #else //PHONG \n\ //Blinn-Phong \n\ vec3 H = normalize(L + E); //halfvector x3d specs this is L+v/|L+v|\n\ float NdotH = max(dot(N,H),0.0); \n\ float specbase = NdotH; \n\ float specpow = mat_shininess*128.0; \n\ #endif //PHONG \n\ float powerFactor = 0.0; // for light dropoff \n\ if (specbase > 0.0) { \n\ powerFactor = pow(specbase,specpow); \n\ // tone down the power factor if mat_shininess borders 0 \n\ } \n\ \n\ ambient += light.ambient * mat_diffuse * mat_ambient; \n\ specular += light.intensity * mat_specular *powerFactor; \n\ diffuse += light.intensity * mat_diffuse * NdotL; \n\ if (myLightType==1) { \n\ // SpotLight \n\ spot = 0.0; \n\ float spotDot = dot (-L,light.direction); \n\ // check against spotCosCutoff \n\ if (spotDot > light.spotCutoff) { \n\ if(spotDot > light.spotBeamWidth) { \n\ spot = 1.0; \n\ } else { \n\ spot = (spotDot - light.spotCutoff)/(light.spotBeamWidth - light.spotCutoff); \n\ } \n\ } \n\ } \n\ sum_vertex += on * attenuation * spot * light.color * (ambient + diffuse); \n\ sum_specular += on * attenuation * spot * light.color * (specular); \n\ } \n\ vertexcolor = clamp(sum_vertex + vertexcolor, 0.0, 1.0); \n\ specularcolor = clamp(sum_specular + specularcolor, 0.0, 1.0); \n\ } \n\ ";