shader phong_shader( point v_position = vector(0,0,0), vector v_normal = vector(0,1,0), vector v_toCamera = vector(0,0,0), vector v_toLight = vector(0,0,0), output color resultRGB = 0 ) { vector vL = normalize(v_toLight); vector vV = normalize(v_toCamera); vector vN = normalize(v_normal); vector vR = 2 * dot(vL, vN)*vN - vL; vector vH = normalize(vL + vV); color u_ambientColor; getattribute("env:ambient_color", u_ambientColor); color u_matColor; getattribute("self:mat_color", u_matColor); color u_lightColor; getattribute("light0:color", u_lightColor); color colAmbient = u_ambientColor*u_matColor; float ndotl = max(dot(vN, vL), 0); color colDiff = ndotl * u_matColor * u_lightColor; float spec = max(dot(vN, vH), 0); color colSpec = step(0, ndotl) * pow(spec, 64) * u_matColor * u_lightColor; color final = colAmbient + colDiff + colSpec; //gamma resultRGB = pow(final, vector(1.0/2.2)); }