#Shader Issues with my Palette Swapping
1 messages · Page 1 of 1 (latest)
this is the next frame of animation
here's what I've found so far....
-first frame is bugged
-deleting first frame in game maker fixes the issue
-deleting the first frame in gimp and exporting to game maker does not fix the issue, simply moves the buggy frame up 1.
-replacing the darkest shade of the sword slash with the player's darkest green shade does nothing
-there any no new colors in the animation that are not in the palette sprite
and here's the palette swapping shader, and my draw event function for the palette swapping shader
// Simple passthrough fragment shader
//
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
//palette swapping var's
uniform sampler2D palette; //the texture for the palette sprite "spr_toxicpalette"
uniform float palette_index; //current palette index being used
uniform float pw; //width of texel
uniform float ph; //height of texel
uniform float tw; //width of texture page
uniform float th; //height of texture page
uniform float uv_l;
uniform float uv_r;
uniform float uv_t;
uniform float uv_b;
uniform vec4 uvs;
/////////////////////////////////////////////////BTW YOU CANNOT USE "&&" IN SHADERS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
void main()
{
//texels
vec4 current_texel = texture2D( gm_BaseTexture, v_vTexcoord ); //get texel of current pixel, from the original sprite's texture
vec4 palette_texel = texture2D( gm_BaseTexture, v_vTexcoord );
//checks every single texel inside texture - 13 pixels tall palette sprite
for (float j = 0.0; j < 1.0; j += ph + (ph * 0.1))
{
//gets palette texel, specified by y = j
palette_texel = texture2D( palette, vec2( 0.0, j));
//if color values from sprite texture and palette sprite texture match
if (palette_texel.rgb == current_texel.rgb)
{
current_texel = texture2D( palette, vec2( palette_index, j)); //changed pixel
}
}
//output final color
gl_FragColor = v_vColour * current_texel;
}
^ the palette swapping shader, vertex shader is unchanged.
and here's the draw event function I'm using
//texture debug switch- ON
texture_debug_messages(true);
//get info on what's happening in shader
var _tex = sprite_get_texture(spr_toxicpalette_2,0);
var _uvs = sprite_get_uvs(spr_toxicpalette_2,0);
var _tex_pw = texture_get_texel_width(_tex);
var _tex_ph = texture_get_texel_height(_tex);
var _tex_tw = texture_get_width(_tex);
var _tex_th = texture_get_height(_tex);
var _uvs_left = _uvs[0];
var _uvs_right = _uvs[2];
var _uvs_top = _uvs[1];
var _uvs_bottom = _uvs[3];
//get palette pixel shift needed determined by suit count
if (global.suit_shock > 0)
{
var _tex_test = (2.1 * _tex_pw);
}
else if (global.suit_pure > 0)
{
var _tex_test = (1.1 * _tex_pw);
}
else if (global.suit_shock <= 0) && (global.suit_pure <= 0)
{
var _tex_test = 0.0;
}
//use shader
shader_set(shd_fade_toxicsuit)
texture_set_stage(palette_sampler_index,_tex);
shader_set_uniform_f(palette_index, _tex_test);
shader_set_uniform_f(pw,_tex_pw);
shader_set_uniform_f(ph,_tex_ph);
shader_set_uniform_f(tw,_tex_tw);
shader_set_uniform_f(th,_tex_th);
shader_set_uniform_f(uv_l, _uvs_left);
shader_set_uniform_f(uv_r, _uvs_right);
shader_set_uniform_f(uv_t, _uvs_top);
shader_set_uniform_f(uv_b, _uvs_bottom);
shader_set_uniform_f_array(uvs, _uvs);
draw_sprite(sprite_index, image_index, 100, 100);
shader_reset()
//TESTING Texel Height to figure out why 8th row of pixels are being skipped
var _tex_ph_test = _tex_ph
for (i = 0; i < _tex_th; i += _tex_ph)
{
var _tex_ph_test2 = i / _tex_ph
}
//texture debug switch- OFF
texture_debug_messages(false);
}```
^draw event function to activate palette swapping
My shader works by getting the color of the current pixel being drawn from texture2d, then it loops through all x and y co ordinates of my palette swapping sprite which is 3x18 pixels.
If the rgb values between the current pixel and a color on the first row of the palette sprite match, replace the current pixel's color with the second coulombs color in the same row as the previous matching color.
^ the sprite I'm checking matching colors for
Ok it seems to be an issue with game maker itself when importing animations, because even importing a brand new animation, it messes up my shader for no reason.
this is the new animation I made in gimp
and this appears
I used the blue colors and while it is correctly swapping them to red (the suit colors in column 2), it's ALSO got this background color which shouldn't be there.
here's what it looks like when using pure black on the sprite
interestingly the white colors seems to be coming from my secondary color in gimp....somehow
I will test this theory
ok I've set the 2nd color to pink
huh
I didn't change anything else
all I did was change my secondary color and then export again then import in game maker
ok
I'll test again
this time my colors are here
the green color is from the palette sprite
it seems like, SOMEHOW, gimp is making my secondary color into the background color of my animation, even though I told it to have a transparent background.
The green was my background color, and now the shader transformed it to orange
remember that the original sprite is unchanged
transparent background
I will try exporting the animation with my 1st and 2ndary colors being ones not on my palette
colors I'm exporting with
well well well....
how the turn tables
theory confirmed
no more stupid background
It has been fixed.
thats so bizzarre
this might be an issue with gimp & gamemaker who knows
this is solved but this looks really interesting
the shader must be swapping a color thats 0 in alpha but still an accepted color by the palette
yeah see its checking if palette texel.rgb == current texel.rgb
can you do a little more expirimentation with the shader and make the transparent bg a palette color
again
then if possible replace texel.rgb’s with texel.rgba
and see if that completely solves it even better
yeah, like a hidden color
ok
changed this
now I'm gonna reexport the test animation with my primary and secondary colors being from the palette sprite
no background
Now...if I change the shader code back to rgb instead of rgba
oh
it's still working now?
I took out the alpha value check too
wait
nope I'm using the shader
I have no idea what's going on now. Like the engine's code just updated itself and now the bug no longer exists.
neat
maybe the devs saw my posts and decided to secretly update game maker
they transmitted a secret update
through a 5g tower
to only have 0,0,0 rgb for 0 alpha pixels
they do a bit of trolling