Page 1 of 1

How to change the Bit Depth

Posted: Tue Aug 09, 2022 6:26 pm
by NoreoAlles
Hey, i want to make a low-res retro game and i am wondering how to change the bit-depth per pixel.
I am displaying a high bit per Pixel depth image and thought changing this: "t.window.depth = nil " in the conf.lua file to 4 instead of nil would result in a 4 bit version of same image being displayed

Thanks :P

Re: How to change the Bit Depth

Posted: Tue Aug 09, 2022 7:14 pm
by darkfrei
Just use the shader for it: https://www.shadertoy.com/view/MtcXD4

(I cannot translate it for the Löve)

Re: How to change the Bit Depth

Posted: Wed Aug 10, 2022 4:46 am
by zorg
You don't. You use assets that only use certain colors, and your problem is solved.
Also, t.window.depth is not color depth; as https://love2d.org/wiki/Config_Files says, it's the precision of the depth buffer.

The above linked shader also seems to do way more than just emulating a lower color depth though.

Re: How to change the Bit Depth

Posted: Wed Aug 10, 2022 6:12 am
by ReFreezed
Well, you can change the bit depth with different PixelFormats for canvases, but it doesn't give you much control, and some formats are not available on all platforms. You should be using shaders for this, or as zorg says, just limit the colors used in the textures directly.

darkfrei's linked shader just emulates a low screen resolution, which I'm guessing is not what you're asking for.

Re: How to change the Bit Depth

Posted: Wed Aug 10, 2022 7:15 am
by zorg
By the way, a simple shader for this could be something like this:

Code: Select all

vec4 effect(vec4 color, Image tex, vec2 texture_coords, vec2 screen_coords)
{
    float colordepth = 8;
    vec4 texturecolor = Texel(tex, texture_coords);
    vec4 output = floor((texturecolor * color) * colordepth) / colordepth;
    return output;
}