Guest User

Untitled

a guest
May 4th, 2025
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. function draw_earthbound(_sprite, _subimage, _x, _y, _palette, _scroll, _oscillateX, _oscillateY, _oscillateSplit) {
  2. draw_earthbound_ext(_sprite, _subimage, _x, _y, 1, 1, 0, c_white, 1, _palette, _scroll, _oscillateX, _oscillateY, _oscillateSplit);
  3. }
  4.  
  5. function draw_earthbound_ext(_sprite, _subimage, _x, _y, _xscale, _yscale, _angle, _blend, _alpha, _palette, _scroll, _oscillateX, _oscillateY, _oscillateSplit) {
  6. // Uniforms
  7. static u_time = shader_get_uniform(sh_earthbound, "time");
  8.  
  9. static u_paletteTexture = shader_get_sampler_index(sh_earthbound, "paletteTexture");
  10. static u_paletteTexel = shader_get_uniform(sh_earthbound, "paletteTexel");
  11.  
  12. static u_textureTexel = shader_get_uniform(sh_earthbound, "textureTexel");
  13. static u_uvs = shader_get_uniform(sh_earthbound, "uv");
  14.  
  15. static u_index = shader_get_uniform(sh_earthbound, "index");
  16. static u_colors = shader_get_uniform(sh_earthbound, "colors");
  17. static u_cycle = shader_get_uniform(sh_earthbound, "cycle");
  18.  
  19. static u_scroll = shader_get_uniform(sh_earthbound, "scroll");
  20. static u_scale = shader_get_uniform(sh_earthbound, "scale");
  21.  
  22. static u_oscillateX = shader_get_uniform(sh_earthbound, "oscillateX");
  23. static u_oscillateY = shader_get_uniform(sh_earthbound, "oscillateY");
  24. static u_oscillateSplit = shader_get_uniform(sh_earthbound, "oscillateSplit");
  25.  
  26. // Defaults
  27. static defaultPalette = new Palette();
  28. static defaultScroll = new Scroll();
  29. static defaultOscillate = new Oscillate();
  30. if (is_undefined(_palette)) _palette = defaultPalette;
  31. if (is_undefined(_scroll)) _scroll = defaultScroll;
  32. if (is_undefined(_oscillateX)) _oscillateX = defaultOscillate;
  33. if (is_undefined(_oscillateY)) _oscillateY = defaultOscillate;
  34. if (is_undefined(_oscillateSplit)) _oscillateSplit = defaultOscillate;
  35.  
  36. // Begin
  37. shader_set(sh_earthbound);
  38. var texture;
  39.  
  40. shader_set_uniform_f(u_time, current_time / 1000);
  41.  
  42. // Palette Texture
  43. texture = sprite_get_texture(spr_palettes, 0);
  44. texture_set_stage(
  45. u_paletteTexture,
  46. texture
  47. );
  48.  
  49. // Palette Texel
  50. shader_set_uniform_f(
  51. u_paletteTexel,
  52. texture_get_texel_width(texture),
  53. texture_get_texel_height(texture)
  54. );
  55.  
  56. // UVs
  57. var uvs = sprite_get_uvs(_sprite, _subimage);
  58. shader_set_uniform_f(
  59. u_uvs,
  60. uvs[0],
  61. uvs[1],
  62. uvs[2],
  63. uvs[3]
  64. );
  65.  
  66. // Texture Texel
  67. texture = sprite_get_texture(_sprite, _subimage);
  68. shader_set_uniform_f(
  69. u_textureTexel,
  70. texture_get_texel_width(texture),
  71. texture_get_texel_height(texture)
  72. );
  73.  
  74. // Palette Cycling
  75. shader_set_uniform_f(u_index, _palette.index);
  76. shader_set_uniform_f(u_colors, _palette.colors);
  77. shader_set_uniform_f(u_cycle, _palette.cycle);
  78.  
  79. // Scrolling
  80. shader_set_uniform_f(u_scroll, _scroll.x, _scroll.y);
  81. shader_set_uniform_f(u_scale, _scroll.xscale, _scroll.yscale);
  82.  
  83. // Oscillation
  84. shader_set_uniform_f(u_oscillateX, _oscillateX.amplitude, _oscillateX.period, _oscillateX.timescale);
  85. shader_set_uniform_f(u_oscillateY, _oscillateY.amplitude, _oscillateY.period, _oscillateY.timescale);
  86. shader_set_uniform_f(u_oscillateSplit, _oscillateSplit.amplitude, _oscillateSplit.period, _oscillateSplit.timescale);
  87.  
  88. // Render
  89. draw_sprite_ext(_sprite, _subimage, _x, _y, _xscale, _yscale, _angle, _blend, _alpha);
  90.  
  91. // End
  92. shader_reset();
  93. }
  94.  
  95. function Palette(_index = 0, _colors = 16, _cycle = 0) constructor {
  96. index = _index;
  97. colors = _colors;
  98. cycle = _cycle;
  99. }
  100.  
  101. function Scroll(_x = 0, _y = 0, _xscale = 1, _yscale = 1) constructor {
  102. x = _x;
  103. y = _y;
  104. xscale = _xscale;
  105. yscale = _yscale;
  106. }
  107.  
  108. function Oscillate(_amplitude = 0, _period = 1, _timescale = 1) constructor {
  109. amplitude = _amplitude;
  110. period = _period;
  111. timescale = _timescale;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment