Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

shinymvtexture.lolfx 2.1 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. [vert.glsl]
  2. #version 130
  3. in vec3 in_position;
  4. in vec3 in_Normal;
  5. in vec4 in_color;
  6. in vec2 in_texcoord;
  7. uniform mat4 u_modelview;
  8. uniform mat4 u_view;
  9. uniform mat4 u_projection;
  10. uniform mat3 u_normalmat;
  11. out vec4 pass_vertex; /* View space */
  12. out vec3 pass_tnormal;
  13. out vec4 pass_color;
  14. out vec2 pass_texcoord;
  15. void main(void)
  16. {
  17. vec4 vertex = u_modelview * vec4(in_position, 1.0);
  18. vec3 tnorm = normalize(u_normalmat * in_Normal);
  19. pass_vertex = vertex;
  20. pass_tnormal = tnorm;
  21. pass_color = in_color;
  22. pass_texcoord = in_texcoord;
  23. gl_Position = u_projection * vertex;
  24. }
  25. [frag.glsl]
  26. #version 130
  27. #if defined GL_ES
  28. precision highp float;
  29. #endif
  30. in vec4 pass_vertex; /* View space */
  31. in vec3 pass_tnormal;
  32. in vec4 pass_color;
  33. in vec2 pass_texcoord;
  34. uniform mat4 u_view;
  35. uniform mat4 u_inv_view;
  36. uniform mat4 u_inv_modelview;
  37. uniform sampler2D u_Texture;
  38. //Light list
  39. uniform vec4 u_lights[8 * 2];
  40. void main(void)
  41. {
  42. /* Material properties */
  43. vec3 specular_reflect = vec3(0.8, 0.75, 0.4);
  44. float specular_power = 60.0;
  45. /* World properties */
  46. vec3 ambient = vec3(0.7, 0.7, 0.7);
  47. vec3 specular = vec3(0.0, 0.0, 0.0);
  48. vec3 diffuse = vec3(0.0, 0.0, 0.0);
  49. /* Light precalculations */
  50. vec3 v = normalize(-pass_vertex.xyz);
  51. /* Apply lighting */
  52. for (int i = 0; i < 8; i++)
  53. {
  54. vec4 pos = u_lights[i * 2];
  55. vec4 color = u_lights[i * 2 + 1];
  56. vec3 s, r;
  57. if (pos.w > 0.0)
  58. {
  59. /* Point light -- no attenuation yet */
  60. s = normalize((u_view * pos).xyz - pass_vertex.xyz);
  61. r = reflect(-s, pass_tnormal);
  62. }
  63. else
  64. {
  65. /* Directional light */
  66. s = normalize(-pos.xyz);
  67. r = reflect(s, pass_tnormal);
  68. }
  69. float sdotn = max(dot(s, pass_tnormal), 0.0);
  70. diffuse += color.xyz * sdotn;
  71. if (sdotn > 0.0)
  72. specular += color.xyz * specular_reflect
  73. * pow(max(dot(r, v), 0.0), specular_power);
  74. }
  75. vec3 light = ambient + diffuse + specular;
  76. gl_FragColor = texture2D(u_Texture, pass_texcoord.xy) * pass_color * vec4(light, 1.0f);
  77. }