Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Waste Not

A puzzle platformer about sorting boxes in a warehouse · By Catelyn

Post-jam thoughts Sticky

A topic by Catelyn created Mar 22, 2021 Views: 39
Viewing posts 1 to 1
Developer (5 edits)

I'm writing this in the hour after submitting the game to the jam, to talk about the (in my opinion) most interesting this game uses.


The main one is the palette swap shader, which is only 13 lines of godot shader code

shader_type canvas_item;
uniform sampler2D palette;
void fragment() {    
    vec4 col = texture(SCREEN_TEXTURE, SCREEN_UV, 0);
    if (col.r == col.g && col.g == col.b)  {    
        COLOR = texture(palette, vec2(col.r, 0));            
        COLOR.a = col.a;        
    }  else  {
        COLOR = vec4(0);
    }
}

All it does is check if the color at that pixel is grayscale, and if so, performs a color lookup in the palette texture, this means that behind the scenes, all the sprites look like this:

This shader also made it really easy to make the 1 bit per pixel variants, since the dark gray and light gray lookups just fall into black and white respectively!

the truck dithering and game over effect are created with another shader, which is 39 lines long, and vaguely based on this shader here: by u/Interference22

shader_type canvas_item;
uniform vec2 target = vec2(0); 
uniform float dither_dist = 300f; 
uniform float baseline_alpha = 0.5f;
  
void fragment() {
    vec2 resolution = 1f / SCREEN_PIXEL_SIZE;
    vec2 current_pixel = SCREEN_UV * resolution;
    vec2 target_pixel = vec2(target.x, 1f - target.y) * resolution;    
    float dist = distance(current_pixel, target_pixel);      
    COLOR = texture(TEXTURE, UV) * MODULATE;    
    float alpha = baseline_alpha;     
 
    if (dist < dither_dist) {
        alpha *= (dist / dither_dist) * (dist / dither_dist);
    }
    int x = int(mod(current_pixel.x, 4));
    int y = int(mod(current_pixel.y, 4));
    int index = x + y * 4;
    float limit = 0.0;
    if (x < 8) {
        if (index == 0) limit = 0.0625;
        if (index == 1) limit = 0.5625;
        if (index == 2) limit = 0.1875; 
        if (index == 3) limit = 0.6875;      
        if (index == 4) limit = 0.8125;       
        if (index == 5) limit = 0.3125;     
        if (index == 6) limit = 0.9375;     
        if (index == 7) limit = 0.4375;    
        if (index == 8) limit = 0.25;      
        if (index == 9) limit = 0.75;       
        if (index == 10) limit = 0.125;   
        if (index == 11) limit = 0.625; 
        if (index == 12) limit = 1.0;  
        if (index == 13) limit = 0.5;     
        if (index == 14) limit = 0.875;   
        if (index == 15) limit = 0.375;  
    }          
    if (alpha < limit)
        discard; 
}