skybox.fs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*******************************************************************************************
  2. *
  3. * rPBR [shader] - Background skybox fragment shader
  4. *
  5. * Copyright (c) 2017 Victor Fisac
  6. *
  7. * 19-Jun-2020 - modified by Giuseppe Mastrangelo (@peppemas) - VFlip Support
  8. *
  9. **********************************************************************************************/
  10. #version 330
  11. // Input vertex attributes (from vertex shader)
  12. in vec3 fragPosition;
  13. // Input uniform values
  14. uniform samplerCube environmentMap;
  15. uniform bool vflipped;
  16. uniform bool doGamma;
  17. // Output fragment color
  18. out vec4 finalColor;
  19. void main()
  20. {
  21. // Fetch color from texture map
  22. vec3 color = vec3(0.0);
  23. if (vflipped) color = texture(environmentMap, vec3(fragPosition.x, -fragPosition.y, fragPosition.z)).rgb;
  24. else color = texture(environmentMap, fragPosition).rgb;
  25. if (doGamma)// Apply gamma correction
  26. {
  27. color = color/(color + vec3(1.0));
  28. color = pow(color, vec3(1.0/2.2));
  29. }
  30. // Calculate final fragment color
  31. finalColor = vec4(color, 1.0);
  32. }