1 #ifdef GL_ES 2 precision lowp float; 3 #endif 4 5 uniform sampler2D u_sampler; 6 uniform vec3 u_projectorPos; 7 8 varying vec3 v_color; 9 varying vec4 v_texcoords; 10 varying vec3 v_normal; 11 varying vec3 v_position; 12 13 void main() { 14 // phong 15 vec3 lightDir = normalize(u_projectorPos - v_position); 16 vec3 normal = normalize(v_normal); 17 float dotProduct = dot(normal, lightDir); 18 19 dotProduct = max(dotProduct, 0.0); 20 21 vec3 texcoords = (v_texcoords.xyz / v_texcoords.w + 1.0) * 0.5; 22 vec4 color; 23 float factor = ceil(sign(texcoords.z)); 24 color = texture2D(u_sampler, texcoords.st) * factor * vec4(v_color, 1.0); 25 gl_FragColor = color * dotProduct; 26 }