Problems with custom shader

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Drakkahn
Prole
Posts: 28
Joined: Sat Jan 17, 2015 11:09 pm

Problems with custom shader

Post by Drakkahn »

I've been trying to make a shader that allows you to use "palettes".
First the images that you want to use are converted to images with the r value as the index and g and b as 0.
These palettes are images that contain a single pixel of the color to use. Example: (0,0) would be color one with color #FAFAFA, (1,0) would be color 2, and so on and so on.

This is the shader code.

Code: Select all

[[
	extern Image palette;
	extern vec2 palette_dimensions;

	vec4 effect(vec4 color,Image img,vec2 img_pos,vec2 screen_pos) {
		vec4 cpixel=Texel(img,img_pos);
		vec2 upos=vec2(cpixel.r/palette_dimensions.r,0);
		return Texel(palette,upos)*color;
	}
]]
For some reason the colors kind of blend into each other instead of using the absolute color.
Untitled.png
Untitled.png (4.94 KiB) Viewed 5238 times
Left is blended, right is how it should be.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Problems with custom shader

Post by grump »

You're sampling the palette between pixels, when you should be sampling at the center of each pixel. And you should switch from linear to nearest neighbor interpolation for the palette texture.
User avatar
Drakkahn
Prole
Posts: 28
Joined: Sat Jan 17, 2015 11:09 pm

Re: Problems with custom shader

Post by Drakkahn »

I modified the shader code to get the pixels in-between, yet it still didn't work. It was only when I did "use_palette:setFilter("nearest","nearest",0)" that it worked. Changing the filter for the image did nothing, I just needed to change the filter for the palette.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 4 guests