PBREnvBaking.vs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. THE_SHADER_OUT vec3 ViewDirection; //!< direction of fetching from environment cubemap
  2. uniform int uCurrentSide; //!< current side of cubemap
  3. uniform int uYCoeff; //!< coefficient of Y controlling horizontal flip of cubemap
  4. uniform int uZCoeff; //!< coefficient of Z controlling vertical flip of cubemap
  5. void main()
  6. {
  7. vec3 aDir;
  8. vec2 aCoord;
  9. if (uCurrentSide == 0)
  10. {
  11. aCoord = mat2( 0,-1,-1, 0) * occVertex.xy;
  12. aDir.x = 1.0;
  13. aDir.y = aCoord.x;
  14. aDir.z = aCoord.y;
  15. }
  16. else if (uCurrentSide == 1)
  17. {
  18. aCoord = mat2( 0, 1,-1, 0) * occVertex.xy;
  19. aDir.x = -1.0;
  20. aDir.y = aCoord.x;
  21. aDir.z = aCoord.y;
  22. }
  23. else if (uCurrentSide == 2)
  24. {
  25. aCoord = mat2( 0, 1, 1, 0) * occVertex.xy;
  26. aDir.x = aCoord.y;
  27. aDir.y = 1.0;
  28. aDir.z = aCoord.x;
  29. }
  30. else if (uCurrentSide == 3)
  31. {
  32. aCoord = mat2( 0, 1,-1, 0) * occVertex.xy;
  33. aDir.x = aCoord.y;
  34. aDir.y = -1.0;
  35. aDir.z = aCoord.x;
  36. }
  37. else if (uCurrentSide == 4)
  38. {
  39. aCoord = mat2( 1, 0, 0,-1) * occVertex.xy;
  40. aDir.x = aCoord.x;
  41. aDir.y = aCoord.y;
  42. aDir.z = 1.0;
  43. }
  44. else //if (uCurrentSide == 5)
  45. {
  46. aCoord = mat2(-1, 0, 0,-1) * occVertex.xy;
  47. aDir.x = aCoord.x;
  48. aDir.y = aCoord.y;
  49. aDir.z = -1.0;
  50. }
  51. ViewDirection = cubemapVectorTransform (aDir, uYCoeff, uZCoeff);
  52. gl_Position = vec4 (occVertex.xy, 0.0, 1.0);
  53. }