|
@ -0,0 +1,39 @@ |
|
|
|
|
|
#ifdef GL_ES |
|
|
|
|
|
precision mediump float; |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
uniform vec4 U_AmbientMaterial; |
|
|
|
|
|
uniform vec4 U_AmbientLight; |
|
|
|
|
|
|
|
|
|
|
|
uniform vec4 U_LightPos; |
|
|
|
|
|
uniform vec4 U_DiffuseMaterial; |
|
|
|
|
|
uniform vec4 U_DiffuseLight; |
|
|
|
|
|
|
|
|
|
|
|
uniform vec4 U_CameraPos; |
|
|
|
|
|
uniform vec4 U_SpecularMaterial; |
|
|
|
|
|
uniform vec4 U_SpecularLight; |
|
|
|
|
|
|
|
|
|
|
|
varying vec4 V_Normal; |
|
|
|
|
|
varying vec4 V_WorldPos; |
|
|
|
|
|
void main() |
|
|
|
|
|
{ |
|
|
|
|
|
//ambient |
|
|
|
|
|
vec4 ambirntColor = U_AmbientMaterial*U_AmbientLight; |
|
|
|
|
|
|
|
|
|
|
|
//diffuse |
|
|
|
|
|
vec3 L = normalize(U_LightPos.xyz - vec3(0)); |
|
|
|
|
|
vec3 n = normalize(V_Normal.xyz); |
|
|
|
|
|
float diffuseIntensity = max(0.0, dot(L,n)); |
|
|
|
|
|
vec4 diffuseColor = U_DiffuseMaterial * U_DiffuseLight * diffuseIntensity; |
|
|
|
|
|
|
|
|
|
|
|
//specular blin |
|
|
|
|
|
vec4 specularColor = vec4(0); |
|
|
|
|
|
if(diffuseIntensity > 0.0) { |
|
|
|
|
|
vec3 vd = normalize((U_CameraPos - V_WorldPos).xyz); |
|
|
|
|
|
vec3 halfD = normalize(L+vd); |
|
|
|
|
|
float specularIntensity = pow(max(0.0, dot(n, halfD)),32.0); |
|
|
|
|
|
specularColor = U_SpecularMaterial * U_SpecularLight * specularIntensity; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
gl_FragColor=ambirntColor + diffuseColor + specularColor; |
|
|
|
|
|
} |