I’m trying to set up a very simple gradient map post processing shader. It’s set up as a custom effect pass in the effect composer & the shader simple turns the scene grayscale, then maps the lightness to a gradient texture, hence re-colouring the image to the gradient colours (same as photoshop’s gradient map function).
The shader is very basic:
const GradientMapShader = `
uniform float mapAmount;
uniform sampler2D gradientMap;
float desaturate(in vec3 inColor) {
return ((inColor.r + inColor.g + inColor.b) / 3.0);
}
void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {
float lightness = desaturate(inputColor.rgb);
vec4 gradientImage = texture2D(gradientMap, vec2(clamp(lightness, 0.0, 1.0), 0.0));
vec4 finalColor = mix(vec4(gradientImage), vec4(inputColor), mapAmount);
outputColor = vec4(finalColor.rgb, inputColor.a);
// just lightness map for testing
//outputColor = vec4(vec3(lightness), inputColor.a);
}
`
export { GradientMapShader }
However, it creates jagged (multi-colored) edges around all of the objects in the scene:
When compared to just the lightness map that it’s based off, there are no jagged edges:
Does anyone have any idea why this is happening?
Thanks in advance