2014-12-18 16:09:29 +08:00
|
|
|
#ifdef GL_ES
|
2014-12-19 15:31:06 +08:00
|
|
|
varying mediump vec2 v_texture_coord;
|
2014-12-18 16:09:29 +08:00
|
|
|
#else
|
2014-12-19 15:31:06 +08:00
|
|
|
varying vec2 v_texture_coord;
|
2014-12-18 16:09:29 +08:00
|
|
|
#endif
|
|
|
|
uniform vec4 u_color;
|
2015-09-02 16:30:24 +08:00
|
|
|
uniform sampler2D u_sampler0;
|
2014-12-18 16:09:29 +08:00
|
|
|
varying vec3 v_normal;
|
|
|
|
void main(void)
|
|
|
|
{
|
2014-12-29 16:43:48 +08:00
|
|
|
vec3 light_direction = vec3(1,-1,-1);
|
2014-12-18 16:09:29 +08:00
|
|
|
light_direction = normalize(light_direction);
|
|
|
|
vec3 light_color = vec3(1,1,1);
|
|
|
|
vec3 normal = normalize(v_normal);
|
|
|
|
float diffuse_factor = dot(normal,-light_direction);
|
2015-09-02 16:30:24 +08:00
|
|
|
vec4 diffuse_color = texture2D(u_sampler0,v_texture_coord);
|
2014-12-18 16:09:29 +08:00
|
|
|
|
|
|
|
if (diffuse_factor > 0.95) diffuse_factor=1.0;
|
|
|
|
else if (diffuse_factor > 0.75) diffuse_factor = 0.8;
|
|
|
|
else if (diffuse_factor > 0.50) diffuse_factor = 0.6;
|
|
|
|
else diffuse_factor = 0.4;
|
|
|
|
|
|
|
|
light_color = light_color * diffuse_factor;
|
|
|
|
gl_FragColor = vec4(light_color,1.0) * diffuse_color * u_color;
|
|
|
|
}
|