Share a 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.
Posts: 40
Joined: Fri Sep 07, 2018 5:42 am

Re: Share a Shader!

Post by girng » Fri Sep 07, 2018 7:31 pm

I have a shader that works in Godot, can I still use it in love2d?

It basically just creates an outline around a sprite (of a certain color)

User avatar
Posts: 16
Joined: Sun Jan 22, 2017 2:47 pm

Re: Share a Shader!

Post by wazoowazoo » Tue Oct 30, 2018 1:13 pm

I have created a basic water shader, hope you will like it.
(230.82 KiB) Downloaded 463 times
I am currently working on reflection.

User avatar
Posts: 16
Joined: Sun Jan 22, 2017 2:47 pm

Re: Share a Shader!

Post by wazoowazoo » Wed Nov 07, 2018 12:07 pm

I have created another shader, this time a fractal. Left mouse button is to place a fractal, backspace to reset graphics, return (enter) to reset frames, space to pause/unpause and scrolling makes it evolve faster or slower. I hope you will have fun playing around with it ! :)
(1.25 KiB) Downloaded 312 times

Here's a preview:
Fractal.png (228.97 KiB) Viewed 7529 times

Posts: 15
Joined: Sun May 12, 2019 2:09 pm

Re: Share a Shader!

Post by trabitboy » Wed Sep 11, 2019 9:54 pm


I am currently porting a paint tool to love2d because:
lua is awesome and
love2d is awesome and supports shaders

I am looking for an example of a love 2d shader with 2 textures as input;
I want to erase using the gpu,
meaning I want to have painting canvas and an eraser texture as an input, blitting to another canvas as output .

I climbed back this thread quite far but I could find no multiple inputs shader ?

Thanks for any help !

User avatar
Posts: 85
Joined: Mon Sep 08, 2014 7:57 am

Re: Share a Shader!

Post by Sasha264 » Thu Sep 12, 2019 10:18 am

Hi! :awesome:

To pass 2 or more images (canvases, textures) to the shader you can declare they inside shader code using extern directive.
And after that but before using this shader you need to send this texture to a shader using shader:send(...) method

Note, that you can ignore "default" texture from the second argument from effect(...) function at all and use only yours named textures, declared using extern Image [name] :cool:

Here is some possible "erasing" shader (but I don't know exact details so it can be adjusted):

Code: Select all

local shader

-- call once per program run
function InitShader()
	local pixelcode = [[
		extern vec2 shift;
		extern Image eraser;

		vec4 effect(vec4 color, Image texture, vec2 tc, vec2 sc)
			vec4 texturePixel = Texel(texture, tc);
			vec4 eraserPixel = Texel(texture, tc + shift);
			texturePixel.a = texturePixel.a * (1.0f - eraserPixel.a);
			return texturePixel;

	shader =

-- call once for change eraser texture
function SetEraserTexture(eraser)
	shader:send("eraser", eraser)

-- call every time you want to move eraser, i.e. every frame
function SetEraserShift(shift)
	shader:send("shift", shift)
BTW, I suppose for this question a separate thread will be more appropriate :3

Posts: 15
Joined: Sun May 12, 2019 2:09 pm

Re: Share a Shader!

Post by trabitboy » Fri Sep 13, 2019 12:48 am

well thanks Sasha264, that is very helpful :awesome:

Posts: 15
Joined: Sun May 12, 2019 2:09 pm

Re: Share a Shader!

Post by trabitboy » Mon Sep 16, 2019 4:13 pm

Here is my example inspired from Sasha264 ,
but offset calculation is not correct in my case .
( getting pretty close )

EDIT: corrected, was not offseting on tex coords but cvs coords

Code: Select all

--this shader substracts alpha of the eraser brush
--offset calculation still incorrect

function love.load()

	--first canvas is filled with redmod,0.0,0.0,1.0)

	--the canvas holding the real image data

	backcvs=cvs2 -- the back buffer the frag shader will render to

	local pixelcode=[[
		//second is the eraser
		extern Image second;
		extern float cvsw;
		extern float brshw;
		extern float cvsh;
		extern float brshh;
		extern float offx;//pixels
		extern float offy;//pixels

		vec4 effect(vec4 color,Image texture,vec2 tc,vec2 sc){
			float pxw=1.0 / brshw;
			float pxh=1.0/brshh;
			vec4 texturePixel=Texel(texture,tc);
			float tcx = tc.x*cvsw/brshw-offx*pxw;
			if (tcx>1.0 || tcx<0.0 ){
				return texturePixel;
			float tcy = tc.y*cvsh/brshh-offy*pxh;
			if (tcy>1.0 || tcy<0.0){
				return texturePixel;
			vec2 rtc=vec2(tcx,tcy);
			vec4 secondPixel=Texel(second,rtc);
				vec4 ret=texturePixel ;
				return ret;


	--test erase from curcvs to backcvs


function love.draw()'eraser shader test')


(4.17 KiB) Downloaded 165 times

Posts: 2
Joined: Wed Oct 02, 2019 4:53 pm

Re: Share a Shader!

Post by aoi_saboten » Wed Oct 02, 2019 6:13 pm

Hello guys.

Can you look to that CRT-shader used here -->

Is it possible to make that effect much better? I am worried about color palette since it is very colorful and about display boundaries, can I make it smoother?

User avatar
Posts: 35
Joined: Thu Oct 03, 2019 5:57 pm

Re: Share a Shader!

Post by YounYokel » Sun Dec 22, 2019 2:56 pm

Do anyone have a simple invert colors shader?

Post Reply

Who is online

Users browsing this forum: No registered users and 20 guests