2020-01-11 08:27:10 +07:00
|
|
|
attribute vec4 a_position;
|
|
|
|
attribute vec3 a_normal;
|
|
|
|
attribute vec4 a_color;
|
2020-02-29 01:18:06 +07:00
|
|
|
|
2020-02-29 23:58:10 +07:00
|
|
|
uniform mat4 u_proj;
|
|
|
|
uniform mat4 u_trans;
|
2020-02-29 01:18:06 +07:00
|
|
|
uniform vec3 u_lightdir;
|
2020-04-02 23:32:55 +07:00
|
|
|
uniform vec3 u_camdir;
|
2020-02-29 23:58:10 +07:00
|
|
|
uniform vec3 u_ambientColor;
|
2020-02-29 01:18:06 +07:00
|
|
|
|
2020-01-11 08:27:10 +07:00
|
|
|
varying vec4 v_col;
|
|
|
|
|
2020-10-22 07:32:35 +07:00
|
|
|
const vec3 diffuse = vec3(0.01);
|
2020-04-03 01:56:53 +07:00
|
|
|
const float shinefalloff = 4.0;
|
|
|
|
const float shinelen = 0.2;
|
2020-01-11 08:27:10 +07:00
|
|
|
|
|
|
|
void main(){
|
2021-09-16 21:20:32 +07:00
|
|
|
vec3 specular = vec3(0, 0, 0);
|
2020-01-11 08:27:10 +07:00
|
|
|
|
2021-09-16 21:20:32 +07:00
|
|
|
vec3 lightReflect = normalize(reflect(a_normal, u_lightdir));
|
|
|
|
float specularFactor = dot(u_camdir, lightReflect);
|
|
|
|
if(specularFactor > 0){
|
|
|
|
specular = vec3(1.0f * pow(specularFactor, 32f)) * (1f-a_color.a); //specular power = 32
|
|
|
|
}
|
|
|
|
|
|
|
|
vec3 norc = (u_ambientColor + specular) * (diffuse + vec3(clamp((dot(a_normal, u_lightdir) + 1.0) / 2.0, 0.0, 1.0)));
|
|
|
|
|
|
|
|
v_col = vec4(a_color.rgb, 1.0) * vec4(norc, 1.0);
|
2020-02-29 23:58:10 +07:00
|
|
|
gl_Position = u_proj * u_trans * a_position;
|
2020-01-11 08:27:10 +07:00
|
|
|
}
|