8 Bit / Pixel Shaders

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
ZacG
Prole
Posts: 5
Joined: Mon Mar 02, 2015 6:21 pm

8 Bit / Pixel Shaders

Post by ZacG »

Does anybody know of a way to create a shader which pixelates and/or limits colours of the screen?
The colour limiting could be either inputting a number of colours or just making a table consisting of all possible colours. There would also need to be a way to get the closest colour to the pixel's colour I would imagine. Anyway, has anyone made this / knows how I could make it? :awesome:
User avatar
Tjakka5
Party member
Posts: 243
Joined: Thu Dec 26, 2013 12:17 pm

Re: 8 Bit / Pixel Shaders

Post by Tjakka5 »

You mean kind of like The Binding Of Isaac Rebirth uses when you enter/exit a level?
User avatar
HDPLocust
Citizen
Posts: 65
Joined: Thu Feb 19, 2015 10:56 pm
Location: Swamp
Contact:

Re: 8 Bit / Pixel Shaders

Post by HDPLocust »

You can use this pixelisation shader:

Code: Select all

shader = love.graphics.newShader [[
      extern vec2 size;            //vector contains image size, like shader:send('size', {img:getWidth(), img:getHeight()})	
      extern number factor;    //nimber contains sample size, like shader:send('factor', 2), use number is divisible by two
      vec4 effect(vec4 color, Image img, vec2 texture_coords, vec2 pixel_coords){
         vec2 tc = floor(texture_coords * size / factor) * factor / size;
         return Texel(img, tc);
      }
]]
Using a big factor, you can get giant pixels.

Image

For realy nice pixelisation, it needs to get average pixel from sample. I don't do this.
Science and violence
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: 8 Bit / Pixel Shaders

Post by Jasoco »

Tjakka5 wrote:You mean kind of like The Binding Of Isaac Rebirth uses when you enter/exit a level?
Or the SNES effect when games would transition from one setting to another like in Mario World when you change from the castle or ghost house intro to the level itself, or Zelda LTTP when you open the map.

But I think the OP means taking the screen image and using a Photoshop-like color dither effect like when you convert an image to a GIF which has a 256 color limit so it has to dither.

I'd say it's easier just to dither the images from the start instead of trying to fake it because it's not going to look right without a lot of work.

Then again, there are times you still need to dither I guess.
Post Reply

Who is online

Users browsing this forum: No registered users and 248 guests