shader.lua 779 B

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