vshader71.glsl 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 vec3 eye_pos;
  16. uniform mat4 model_view;
  17. uniform mat4 projection;
  18. void main() {
  19. texCoord = vTexCoord;
  20. gl_Position = projection * model_view * vPosition / vPosition.w;
  21. // light0
  22. vec4 LightPosition0 = vec4(eye_pos.x, eye_pos.y, eye_pos.z, 1.0);
  23. fN0 = vNormal;
  24. fE0 = -(model_view * vPosition).xyz;
  25. fL0 = LightPosition0.xyz - (model_view * vPosition).xyz;
  26. // light1
  27. vec4 LightPosition1 = vec4(0.5, 0.25, 10, 0.0);
  28. fN1 = vNormal;
  29. fE1 = -(model_view * vPosition).xyz;
  30. fL1 = LightPosition1.xyz;
  31. // fog
  32. if (foggy > 0) {
  33. // distance
  34. float dis = (vPosition.x - eye_pos.x) * (vPosition.x - eye_pos.x) +
  35. (vPosition.y - eye_pos.y) * (vPosition.y - eye_pos.y) +
  36. (vPosition.z - eye_pos.z) * (vPosition.z - eye_pos.z);
  37. fog_factor = exp(-dis);
  38. } else { // not foggy
  39. fog_factor = 1.0;
  40. }
  41. }