debug.shader 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. shader_type canvas_item;
  2. uniform sampler2D Front : hint_albedo;
  3. uniform sampler2D Right : hint_albedo;
  4. uniform sampler2D Left : hint_albedo;
  5. uniform sampler2D Back : hint_albedo;
  6. uniform sampler2D Up : hint_albedo;
  7. uniform sampler2D Down : hint_albedo;
  8. vec4 cubemap(in vec3 d)
  9. {
  10. vec3 a = abs(d);
  11. bvec3 ip =greaterThan(d,vec3(0.));
  12. vec2 uvc;
  13. if (ip.x && a.x >= a.y && a.x >= a.z) {uvc.x = -d.z;uvc.y = d.y;
  14. return texture(Front,0.5 * (uvc / a.x + 1.));
  15. }else
  16. if (!ip.x && a.x >= a.y && a.x >= a.z) {uvc.x = d.z;uvc.y = d.y;
  17. return texture(Back,0.5 * (uvc / a.x + 1.));
  18. }else
  19. if (ip.y && a.y >= a.x && a.y >= a.z) {uvc.x = d.x;uvc.y = -d.z;
  20. return texture(Up,0.5 * (uvc / a.y + 1.));
  21. }else
  22. if (!ip.y && a.y >= a.x && a.y >= a.z) {uvc.x = d.x;uvc.y = d.z;
  23. return texture(Down,0.5 * (uvc / a.y + 1.));
  24. }else
  25. if (ip.z && a.z >= a.x && a.z >= a.y) {uvc.x = d.x;uvc.y = d.y;
  26. return texture(Right,0.5 * (uvc / a.z + 1.));
  27. }else
  28. if (!ip.z && a.z >= a.x && a.z >= a.y) {uvc.x = -d.x;uvc.y = d.y;
  29. return texture(Left,0.5 * (uvc / a.z + 1.));
  30. }
  31. return vec4(0.);
  32. }
  33. vec3 rotate_y(vec3 v, float angle)
  34. {
  35. float ca = cos(angle); float sa = sin(angle);
  36. return v*mat3(
  37. vec3(+ca, +.0, -sa),
  38. vec3(+.0,+1.0, +.0),
  39. vec3(+sa, +.0, +ca));
  40. }
  41. vec3 rotate_x(vec3 v, float angle)
  42. {
  43. float ca = cos(angle); float sa = sin(angle);
  44. return v*mat3(
  45. vec3(+1.0, +.0, +.0),
  46. vec3(+.0, +ca, -sa),
  47. vec3(+.0, +sa, +ca));
  48. }
  49. void panorama_uv(vec2 fragCoord, out vec3 ro,out vec3 rd, in vec2 iResolution){
  50. float M_PI = 3.1415926535;
  51. float ymul = 2.0; float ydiff = -1.0;
  52. vec2 uv = fragCoord.xy / iResolution.xy;
  53. uv.y=1.-uv.y;
  54. uv.x = 2.0 * uv.x - 1.0;
  55. uv.y = ymul * uv.y + ydiff;
  56. ro = vec3(0., 5., 0.);
  57. rd = normalize(rotate_y(rotate_x(vec3(0.0, 0.0, 1.0),-uv.y*M_PI/2.0),-uv.x*M_PI));
  58. }
  59. void mainImage( out vec4 fragColor, in vec2 fragCoord, in vec2 iResolution)
  60. {
  61. vec3 ro = vec3 (0.,0.,0.);
  62. vec3 rd = vec3(0.);
  63. vec3 col=vec3(0.);
  64. panorama_uv(fragCoord,ro,rd,iResolution);
  65. col = cubemap(rd).rgb;
  66. fragColor = vec4(col,1.0);
  67. }
  68. void fragment(){
  69. vec2 iResolution=1./TEXTURE_PIXEL_SIZE;
  70. mainImage(COLOR,FRAGCOORD.xy,iResolution);
  71. }