I have virtually no knowledge with GLSL so I've been using ChatGPT to try to make an outline shader for my Love2D project, but it doesn't seem to be working, no matter how much troubleshooting I do.
If you're familiar with GLSL, I'd really appreciate some corrections to this shader code, or perhaps the way I'm using it!
Here's the shader code
Code: Select all
outlineShader = love.graphics.newShader([[
vec4 position(mat4 transform_projection, vec4 vertex_position)
{
return transform_projection * vertex_position;
}
]], [[
extern vec2 outlineSize; // the size of the outline (in pixels)
extern vec4 textColor; // the color of the text
extern vec4 outlineColor; // the color of the outline
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords)
{
// calculate the outline color
vec4 outline = vec4(0.0);
for (float x = -outlineSize.x; x <= outlineSize.x; x += 1.0) {
for (float y = -outlineSize.y; y <= outlineSize.y; y += 1.0) {
float factor = (abs(x) + abs(y)) / (outlineSize.x + outlineSize.y);
outline += Texel(texture, texture_coords + vec2(x, y) / love_ScreenSize.xy) * factor;
}
}
outline = mix(outlineColor, outline, outline.a); // mix the outline color with the calculated color
// calculate the text color
vec4 text = Texel(texture, texture_coords);
// blend the outline and text color
vec4 result = mix(outline, text, step(0.0, text.a)); // use the alpha channel of the text to create a mask
result = mix(textColor, result, step(0.0, result.a)); // mix the result with the text color
return result * color;
}
]])
Code: Select all
outlineShader
Code: Select all
outlineShader:send('outlineSize', {2, 2}) -- the size of the outline in pixels
outlineShader:send('textColor', {0, 0, 0, 1}) -- the color of the text (white)
outlineShader:send('outlineColor', {0, 1, 0, 1})
Code: Select all
love.graphics.setShader(outlineShader)
love.graphics.print('Hello, World!)
love.graphics.setShader()
Any and all help is greatly appreciated!
Also, let me know if you need more context in order to help me out!