pass_viewray.vert.glsl 696 B

1234567891011121314151617181920212223242526272829
  1. #version 450
  2. uniform mat4 invVP;
  3. uniform vec3 eye;
  4. in vec2 pos;
  5. out vec2 texCoord;
  6. out vec3 viewRay;
  7. void main() {
  8. // Scale vertex attribute to [0-1] range
  9. const vec2 madd = vec2(0.5, 0.5);
  10. texCoord = pos.xy * madd + madd;
  11. #if defined(HLSL) || defined(METAL) || defined(SPIRV)
  12. texCoord.y = 1.0 - texCoord.y;
  13. #endif
  14. gl_Position = vec4(pos.xy, 0.0, 1.0);
  15. // fullscreen triangle: http://de.slideshare.net/DevCentralAMD/vertex-shader-tricks-bill-bilodeau
  16. // gl_Position = vec4((gl_VertexID % 2) * 4.0 - 1.0, (gl_VertexID / 2) * 4.0 - 1.0, 0.0, 1.0);
  17. // NDC (at the back of cube)
  18. vec4 v = vec4(pos.x, pos.y, 1.0, 1.0);
  19. v = vec4(invVP * v);
  20. v.xyz /= v.w;
  21. viewRay = v.xyz - eye;
  22. }