luminance_trunced.glslv 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #version GLSL_VERSION
  2. #include <std.glsl>
  3. uniform vec4 u_camera_quat;
  4. uniform vec3 u_sun_direction;
  5. uniform float u_bloom_key;
  6. /*==============================================================================
  7. SHADER INTERFACE
  8. ==============================================================================*/
  9. GLSL_IN vec2 a_position;
  10. //------------------------------------------------------------------------------
  11. GLSL_OUT vec2 v_texcoord;
  12. GLSL_OUT float v_bloom_factor;
  13. /*============================================================================*/
  14. void multiply_vec3 (in vec4 quat, in vec3 vec, out vec3 dest) {
  15. // calculate quat * vec
  16. float ix = quat.w * vec.x + quat.y * vec.z - quat.z * vec.y;
  17. float iy = quat.w * vec.y + quat.z * vec.x - quat.x * vec.z;
  18. float iz = quat.w * vec.z + quat.x * vec.y - quat.y * vec.x;
  19. float iw = -quat.x * vec.x - quat.y * vec.y - quat.z * vec.z;
  20. // calculate result * inverse quat
  21. dest.x = ix * quat.w - iw * quat.x - iy * quat.z + iz * quat.y;
  22. dest.y = iy * quat.w - iw * quat.y - iz * quat.x + ix * quat.z;
  23. dest.z = iz * quat.w - iw * quat.z - ix * quat.y + iy * quat.x;
  24. }
  25. /*==============================================================================
  26. MAIN
  27. ==============================================================================*/
  28. void main(void) {
  29. v_texcoord = 2.0 * a_position;
  30. // bloom is visible only when cam is facing towards the sun
  31. vec3 cam_y_dir;
  32. multiply_vec3(u_camera_quat, UP_VECTOR, cam_y_dir);
  33. v_bloom_factor = dot(-cam_y_dir, u_sun_direction) * u_bloom_key;
  34. // if sun is below the horizont turn off bloom
  35. v_bloom_factor *= max(sign(u_sun_direction.z), 0.0);
  36. gl_Position = vec4(4.0 * (a_position.xy-0.25), 0.0, 1.0);
  37. }