材质
1 2 3 4 5 6 7 8 9
| #version 330 core struct Material { vec3 ambient; vec3 diffuse; vec3 specular; float shininess; };
uniform Material material;
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| void main() { vec3 ambient = lightColor * material.ambient;
vec3 norm = normalize(Normal); vec3 lightDir = normalize(lightPos - FragPos); float diff = max(dot(norm, lightDir), 0.0); vec3 diffuse = lightColor * (diff * material.diffuse);
vec3 viewDir = normalize(viewPos - FragPos); vec3 reflectDir = reflect(-lightDir, norm); float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess); vec3 specular = lightColor * (spec * material.specular);
vec3 result = ambient + diffuse + specular; FragColor = vec4(result, 1.0); }
|
code
https://gist.github.com/Flandre923/e7f5b2f673d37c8bb0cb5f9b9e12876a
练习