GMS 1.4 Shader/Texture interpolation on fullscreen trouble

Wile94

Member
Hi, so basically I'm testing the code from this video:

In the create event I have something like this:
Code:
color_sets = 4;
color_row_index = 1;

v_offset = shader_get_uniform(shdr_palette_swap, "Offset");
v_normal = color_row_index/256;
palette_swap_sampler = shader_get_sampler_index(shdr_palette_swap, "Palette");
texture_palette = background_get_texture(bg_palette);
texture_set_interpolation_ext(palette_swap_sampler,false);
In the begin step event I update my v_normal if the row index is changed

Then on the draw event this:
Code:
shader_set(shdr_palette_swap);
texture_set_stage(palette_swap_sampler, texture_palette);
shader_set_uniform_f(v_offset, v_normal);
draw_sprite_ext(anim[animNo],animFrame,x,y,animFacing,1,0,c_white,1);
shader_reset();
This is the fragment shader code:
Code:
varying vec2 v_vTexcoord;
varying vec4 v_vColour;

//  Get palette as texture
uniform sampler2D Palette;

//  Color Offset Index
uniform float Offset;

void main() {

    vec4 ref = texture2D(gm_BaseTexture, v_vTexcoord);
    
    vec2 uv_coord = vec2(ref.r, Offset);
    
    vec4 new_color = texture2D(Palette, uv_coord);
    
    gl_FragColor = new_color;
}
Then I have my "bg_palette" with a size of 256x256 and checked with "Used for 3D"

Everything works great until I set the game in fullscreen, then my palettes gets all glitchy like it's getting a color value between 2 positions in the texture uvs. I tried working this out by changing the texture_set_interpolation code inside the draw event, this makes it work but my global interpolation gets deactivated and all the images in the view gets glitchy and sharp, basically loses anykind of antialiasing.

Honestly I'm a noob related to shaders and gpu processing, so any kind of help will be appreciated. I'm guessing that manually setting the interpolation for that specific sampler when setting the fullscreen(false/true) would end up having the same result.

PS: If I start the game in fullscreen this doesn't happen but when I switch to windowed mode it happens anway
 
Last edited:
Without testing I'd probably try two ways to fix this.

Var 1: if you're setting the texture interpolation somewhere else in your code, then best move this line from create event to draw event right after setting the shader:
texture_set_interpolation_ext(palette_swap_sampler,false);

Var 2: get the texel size, pass it into the shader as a uniform and add half of texel width and height to the vec2 offset. then the samples should be taken at the centre of a texel instead of in between.
 

Wile94

Member
Var 2: get the texel size, pass it into the shader as a uniform and add half of texel width and height to the vec2 offset. then the samples should be taken at the centre of a texel instead of in between.
That actually solve my interpolation problem, I don't even have to call the function anymore. But i don't know why my subpixels are getting drawn now, I think it has to do with the shader not returning the original alpha from the fragment
 

Wile94

Member
Ok, after some researching I finally understand that color swapping shaders in pixel art games don't match with pixel interpolation. I just worked it around it by rounding the x,y coordinates when I'm drawing the sprite so I can keep the smooth motion from physics and let the interpolation on, I thought it would look kinda ugly but no, it doesn't make much difference only now I don't have a lot of subpixels getting drawn o_O
 
Top