Problems with custom shader
Posted: Wed Jan 27, 2021 9:20 am
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.
For some reason the colors kind of blend into each other instead of using the absolute color.
Left is blended, right is how it should be.
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;
}
]]