shader.lua 710 B

123456789101112131415161718192021222324
  1. return [[
  2. in vec3 lightDirection;
  3. in vec3 normalDirection;
  4. vec3 cAmbient = vec3(.25);
  5. vec3 cDiffuse = vec3(1);
  6. vec3 cSpecular = vec3(.35);
  7. vec4 color(vec4 graphicsColor, sampler2D image, vec2 uv) {
  8. float diffuse = max(dot(normalDirection, lightDirection), 0.);
  9. float specular = 0.;
  10. if (diffuse > 0.) {
  11. vec3 r = reflect(lightDirection, normalDirection);
  12. vec3 viewDirection = normalize(-vec3(gl_FragCoord));
  13. float specularAngle = max(dot(r, viewDirection), 0.);
  14. specular = pow(specularAngle, 5.);
  15. }
  16. vec3 cFinal = pow(clamp(vec3(diffuse) * cDiffuse + vec3(specular) * cSpecular, cAmbient, vec3(1.)), vec3(.4545));
  17. return vec4(cFinal, 1.) * graphicsColor * texture(image, uv);
  18. }
  19. ]]