/extra/gpu/demos/bunny/bunny.f.glsl

http://github.com/abeaumont/factor · GLSL · 39 lines · 31 code · 8 blank · 0 comment · 0 complexity · 19c82ac438f918421182d9230efa3c00 MD5 · raw file

  1. #version 110
  2. uniform mat4 mv_matrix, p_matrix;
  3. uniform vec4 color, ambient, diffuse;
  4. uniform float shininess;
  5. varying vec3 frag_normal;
  6. varying vec3 frag_light_direction;
  7. varying vec3 frag_eye_direction;
  8. float
  9. cel(float d)
  10. {
  11. return smoothstep(0.25, 0.255, d) * 0.4 + smoothstep(0.695, 0.70, d) * 0.5;
  12. }
  13. vec4
  14. cel_light()
  15. {
  16. vec3 normal = normalize(frag_normal),
  17. light = normalize(frag_light_direction),
  18. eye = normalize(frag_eye_direction),
  19. reflection = reflect(light, normal);
  20. float d = dot(light, normal) * 0.5 + 0.5;
  21. float s = pow(max(dot(reflection, -eye), 0.0), shininess);
  22. vec4 amb_diff = ambient + diffuse * vec4(vec3(cel(d)), 1.0);
  23. vec4 spec = vec4(vec3(cel(s)), 0.0);
  24. return amb_diff * color + spec;
  25. }
  26. void
  27. main()
  28. {
  29. gl_FragData[0] = cel_light();
  30. gl_FragData[1] = vec4(frag_normal, 0.0);
  31. }