Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function draw_earthbound(_sprite, _subimage, _x, _y, _palette, _scroll, _oscillateX, _oscillateY, _oscillateSplit) {
- draw_earthbound_ext(_sprite, _subimage, _x, _y, 1, 1, 0, c_white, 1, _palette, _scroll, _oscillateX, _oscillateY, _oscillateSplit);
- }
- function draw_earthbound_ext(_sprite, _subimage, _x, _y, _xscale, _yscale, _angle, _blend, _alpha, _palette, _scroll, _oscillateX, _oscillateY, _oscillateSplit) {
- // Uniforms
- static u_time = shader_get_uniform(sh_earthbound, "time");
- static u_paletteTexture = shader_get_sampler_index(sh_earthbound, "paletteTexture");
- static u_paletteTexel = shader_get_uniform(sh_earthbound, "paletteTexel");
- static u_textureTexel = shader_get_uniform(sh_earthbound, "textureTexel");
- static u_uvs = shader_get_uniform(sh_earthbound, "uv");
- static u_index = shader_get_uniform(sh_earthbound, "index");
- static u_colors = shader_get_uniform(sh_earthbound, "colors");
- static u_cycle = shader_get_uniform(sh_earthbound, "cycle");
- static u_scroll = shader_get_uniform(sh_earthbound, "scroll");
- static u_scale = shader_get_uniform(sh_earthbound, "scale");
- static u_oscillateX = shader_get_uniform(sh_earthbound, "oscillateX");
- static u_oscillateY = shader_get_uniform(sh_earthbound, "oscillateY");
- static u_oscillateSplit = shader_get_uniform(sh_earthbound, "oscillateSplit");
- // Defaults
- static defaultPalette = new Palette();
- static defaultScroll = new Scroll();
- static defaultOscillate = new Oscillate();
- if (is_undefined(_palette)) _palette = defaultPalette;
- if (is_undefined(_scroll)) _scroll = defaultScroll;
- if (is_undefined(_oscillateX)) _oscillateX = defaultOscillate;
- if (is_undefined(_oscillateY)) _oscillateY = defaultOscillate;
- if (is_undefined(_oscillateSplit)) _oscillateSplit = defaultOscillate;
- // Begin
- shader_set(sh_earthbound);
- var texture;
- shader_set_uniform_f(u_time, current_time / 1000);
- // Palette Texture
- texture = sprite_get_texture(spr_palettes, 0);
- texture_set_stage(
- u_paletteTexture,
- texture
- );
- // Palette Texel
- shader_set_uniform_f(
- u_paletteTexel,
- texture_get_texel_width(texture),
- texture_get_texel_height(texture)
- );
- // UVs
- var uvs = sprite_get_uvs(_sprite, _subimage);
- shader_set_uniform_f(
- u_uvs,
- uvs[0],
- uvs[1],
- uvs[2],
- uvs[3]
- );
- // Texture Texel
- texture = sprite_get_texture(_sprite, _subimage);
- shader_set_uniform_f(
- u_textureTexel,
- texture_get_texel_width(texture),
- texture_get_texel_height(texture)
- );
- // Palette Cycling
- shader_set_uniform_f(u_index, _palette.index);
- shader_set_uniform_f(u_colors, _palette.colors);
- shader_set_uniform_f(u_cycle, _palette.cycle);
- // Scrolling
- shader_set_uniform_f(u_scroll, _scroll.x, _scroll.y);
- shader_set_uniform_f(u_scale, _scroll.xscale, _scroll.yscale);
- // Oscillation
- shader_set_uniform_f(u_oscillateX, _oscillateX.amplitude, _oscillateX.period, _oscillateX.timescale);
- shader_set_uniform_f(u_oscillateY, _oscillateY.amplitude, _oscillateY.period, _oscillateY.timescale);
- shader_set_uniform_f(u_oscillateSplit, _oscillateSplit.amplitude, _oscillateSplit.period, _oscillateSplit.timescale);
- // Render
- draw_sprite_ext(_sprite, _subimage, _x, _y, _xscale, _yscale, _angle, _blend, _alpha);
- // End
- shader_reset();
- }
- function Palette(_index = 0, _colors = 16, _cycle = 0) constructor {
- index = _index;
- colors = _colors;
- cycle = _cycle;
- }
- function Scroll(_x = 0, _y = 0, _xscale = 1, _yscale = 1) constructor {
- x = _x;
- y = _y;
- xscale = _xscale;
- yscale = _yscale;
- }
- function Oscillate(_amplitude = 0, _period = 1, _timescale = 1) constructor {
- amplitude = _amplitude;
- period = _period;
- timescale = _timescale;
- }
Advertisement
Add Comment
Please, Sign In to add comment