SHARE
TWEET

Untitled

a guest Apr 20th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. uniform vec4 u_f4ViewportSize;
  2. uniform float u_fClippingNearDis;
  3. uniform float u_fClippingFarDis;
  4.  
  5. /// Converts OpenGL fragment coordinates to normalized device coordinates (NDC).
  6. vec3 fragCoordsToNDC(in vec3 _f3FragPos_Ss)
  7. {
  8.     vec3 f3FragPos_Ns  = vec3(_f3FragPos_Ss.xy * u_f4ViewportSize.zw, _f3FragPos_Ss.z);
  9.     f3FragPos_Ns = (f3FragPos_Ns - 0.5) * 2.0;
  10.     return f3FragPos_Ns;
  11. }
  12.  
  13. /// Converts OpenGL normalized device coordinates (NDC) to  fragment coordinates.
  14. vec3 ndcToFragCoord(in vec3 _f3FragPos_Ns)
  15. {
  16.     vec3 f3FragPos_Ss  = (_f3FragPos_Ns + 1.0) * 0.5;
  17.     return vec3(f3FragPos_Ss.xy * u_f4ViewportSize.xy, f3FragPos_Ss.z);
  18. }
  19.  
  20. /// Converts a position in OpenGL's normalized device coordinates (NDC) to the specified space.
  21. vec4 ndcToSpecificSpacePosition(in vec3 _f3FragPos_Ns, in mat4 _m4Inverse)
  22. {
  23.     vec4 f4ClipPos;
  24.     f4ClipPos.w   = (2.0 * u_fClippingNearDis * u_fClippingFarDis)  / (u_fClippingNearDis + u_fClippingFarDis + _f3FragPos_Ns.z * (u_fClippingNearDis - u_fClippingFarDis));
  25.     f4ClipPos.xyz = _f3FragPos_Ns * f4ClipPos.w;
  26.  
  27.     return _m4Inverse * f4ClipPos;
  28. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top