Refl_rt.shader 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. shader_type spatial;
  2. render_mode blend_mix,depth_draw_always,cull_back,unshaded;
  3. uniform bool minif;
  4. uniform bool disable_refl;
  5. uniform bool disable_panorama;
  6. uniform sampler2D Front : hint_albedo;
  7. uniform sampler2D Right : hint_albedo;
  8. uniform sampler2D Left : hint_albedo;
  9. uniform sampler2D Back : hint_albedo;
  10. uniform sampler2D Up : hint_albedo;
  11. uniform sampler2D Down : hint_albedo;
  12. uniform sampler2D tex_panorama : hint_albedo;
  13. vec4 cubemap(in vec3 d)
  14. {
  15. vec3 a = abs(d);
  16. bvec3 ip =greaterThan(d,vec3(0.));
  17. vec2 uvc;
  18. if (ip.x && a.x >= a.y && a.x >= a.z) {uvc.x = -d.z;uvc.y = d.y;
  19. return texture(Front,0.5 * (uvc / a.x + 1.));
  20. }else
  21. if (!ip.x && a.x >= a.y && a.x >= a.z) {uvc.x = d.z;uvc.y = d.y;
  22. return texture(Back,0.5 * (uvc / a.x + 1.));
  23. }else
  24. if (ip.y && a.y >= a.x && a.y >= a.z) {uvc.x = d.x;uvc.y = -d.z;
  25. return texture(Up,0.5 * (uvc / a.y + 1.));
  26. }else
  27. if (!ip.y && a.y >= a.x && a.y >= a.z) {uvc.x = d.x;uvc.y = d.z;
  28. return texture(Down,0.5 * (uvc / a.y + 1.));
  29. }else
  30. if (ip.z && a.z >= a.x && a.z >= a.y) {uvc.x = d.x;uvc.y = d.y;
  31. return texture(Right,0.5 * (uvc / a.z + 1.));
  32. }else
  33. if (!ip.z && a.z >= a.x && a.z >= a.y) {uvc.x = -d.x;uvc.y = d.y;
  34. return texture(Left,0.5 * (uvc / a.z + 1.));
  35. }
  36. return vec4(0.);
  37. }
  38. vec2 uv_sphere(vec3 v)
  39. {
  40. float pi = 3.1415926536;
  41. vec2 uv=vec2(0.5 + atan(v.z, v.x) / (2.0 * pi), acos(v.y) / pi);
  42. uv.y=1.-uv.y;
  43. uv.x=-0.75+uv.x;
  44. uv=fract(uv);
  45. return uv;
  46. }
  47. vec3 ref_panorama(vec3 ref) {
  48. vec2 tuv=uv_sphere(normalize(ref));
  49. vec4 albedo_tex = texture(tex_panorama,tuv,1.);
  50. return albedo_tex.rgb;
  51. }
  52. void fragment(){
  53. vec3 selfpos=((WORLD_MATRIX*vec4(1.0)).xyz);
  54. vec3 cam=((CAMERA_MATRIX*vec4(1.0)).xyz);
  55. vec3 rd=normalize(((CAMERA_MATRIX*vec4(normalize(-VERTEX),0.0)).xyz));
  56. vec3 nor=normalize((CAMERA_MATRIX * vec4(NORMAL, 0.0)).xyz);
  57. vec3 ref = reflect(rd,nor);
  58. if(!disable_refl){
  59. vec4 albedo_tex=cubemap(normalize(-ref)*vec3(-1.,1.,1.));
  60. ALPHA=1.;
  61. ALBEDO = albedo_tex.rgb;
  62. ALBEDO*=ALBEDO;
  63. ALPHA=1.;
  64. }
  65. else{
  66. if(!disable_panorama){
  67. ALBEDO = ref_panorama(ref);
  68. ALPHA=1.;
  69. }
  70. else{
  71. ALBEDO = vec3(0.1);
  72. ALPHA=1.;
  73. }
  74. }
  75. if(minif)ALBEDO=vec3(0.);
  76. }