You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
899 B

  1. /*******************************************************************************************
  2. *
  3. * rPBR [shader] - Equirectangular to cubemap fragment shader
  4. *
  5. * Copyright (c) 2017 Victor Fisac
  6. *
  7. **********************************************************************************************/
  8. #version 330
  9. // Input vertex attributes (from vertex shader)
  10. in vec3 fragPos;
  11. // Input uniform values
  12. uniform sampler2D equirectangularMap;
  13. // Output fragment color
  14. out vec4 finalColor;
  15. vec2 SampleSphericalMap(vec3 v)
  16. {
  17. vec2 uv = vec2(atan(v.z, v.x), asin(v.y));
  18. uv *= vec2(0.1591, 0.3183);
  19. uv += 0.5;
  20. return uv;
  21. }
  22. void main()
  23. {
  24. // Normalize local position
  25. vec2 uv = SampleSphericalMap(normalize(fragPos));
  26. // Fetch color from texture map
  27. vec3 color = texture(equirectangularMap, uv).rgb;
  28. // Calculate final fragment color
  29. finalColor = vec4(color, 1.0);
  30. }