vshader71.glsl 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #version 150
  2. in vec4 vPosition;
  3. in vec2 vTexCoord;
  4. in vec3 vNormal;
  5. out vec2 texCoord;
  6. out float fog_factor;
  7. // output values that will be interpretated per-fragment
  8. out vec3 fN0;
  9. out vec3 fE0;
  10. out vec3 fL0;
  11. out vec3 fN1;
  12. out vec3 fE1;
  13. out vec3 fL1;
  14. uniform int foggy;
  15. uniform float fog_fac;
  16. uniform vec3 eye_pos;
  17. uniform mat4 model_view;
  18. uniform mat4 projection;
  19. void main() {
  20. texCoord = vTexCoord;
  21. gl_Position = projection * model_view * vPosition / vPosition.w;
  22. // light0
  23. vec4 LightPosition0 = vec4(eye_pos.x, eye_pos.y, eye_pos.z, 1.0);
  24. fN0 = vNormal;
  25. fE0 = -(model_view * vPosition).xyz;
  26. fL0 = LightPosition0.xyz - (model_view * vPosition).xyz;
  27. // light1
  28. vec4 LightPosition1 = vec4(0.5, 0.25, 10, 0.0);
  29. fN1 = vNormal;
  30. fE1 = -(model_view * vPosition).xyz;
  31. fL1 = LightPosition1.xyz;
  32. // fog
  33. if (foggy > 0) {
  34. // distance
  35. float dis = (vPosition.x - eye_pos.x) * (vPosition.x - eye_pos.x) +
  36. (vPosition.y - eye_pos.y) * (vPosition.y - eye_pos.y) +
  37. (vPosition.z - eye_pos.z) * (vPosition.z - eye_pos.z);
  38. fog_factor = exp(-dis * fog_fac);
  39. } else { // not foggy
  40. fog_factor = 1.0;
  41. }
  42. }