I want to show something that I've made.
The shader to make the image made with one color, from black to white with the chosen middle color. I think it looks like the pen ink drawing.
The black will be black, the white will be white, but all gray shades are tinted.
main.lua:
Code: Select all
local shaderCode = [[
extern vec3 colorA;
extern vec3 colorB;
extern vec3 colorC;
vec3 projectOnSegment(vec3 p, vec3 a, vec3 b) {
vec3 ab = b - a;
float t = dot(p - a, ab) / dot(ab, ab);
return a + t * ab;
}
vec4 effect(vec4 color, Image texture, vec2 uv, vec2 screenCoords) {
vec4 pixel = Texel(texture, uv);
vec3 p = pixel.rgb;
// projection of the point onto the segments AB and BC
vec3 projAB = projectOnSegment(p, colorA, colorB);
vec3 projBC = projectOnSegment(p, colorB, colorC);
// calculate relative 't' along the whole A->B->C line
float lenAB = length(colorB - colorA);
float lenBC = length(colorC - colorB);
float totalLen = lenAB + lenBC;
float tAB = length(projAB - colorA) / totalLen;
float tBC = (lenAB + length(projBC - colorB)) / totalLen;
float t = (length(p - colorA) / length(colorC - colorA));
// mix colors based on the adjusted 't' value
vec3 finalColor = mix(projAB, projBC, t);
return vec4(finalColor, pixel.a);
}
]]
function love.load()
image = love.graphics.newImage ('image.jpg')
width, height = image:getDimensions ()
love.window.setMode (width*2, height)
shader = love.graphics.newShader(shaderCode)
-- send colors to the shader
shader:send('colorA', {0, 0, 0})
shader:send('colorB', {0.4, 0.0, 0.8})
shader:send('colorC', {1, 1, 1})
end
function love.draw()
love.graphics.draw(image)
love.graphics.setShader(shader)
love.graphics.draw(image, width, 0)
love.graphics.setShader()
end