Page 32 of 33
Re: Share a Shader!
Posted: Fri Sep 07, 2018 7:31 pm
by girng
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)
Re: Share a Shader!
Posted: Tue Oct 30, 2018 1:13 pm
by wazoowazoo
I have created a basic water shader, hope you will like it.
I am currently working on reflection.
Re: Share a Shader!
Posted: Wed Nov 07, 2018 12:07 pm
by wazoowazoo
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 !
Here's a preview:
- Fractal.png (228.97 KiB) Viewed 49206 times
Re: Share a Shader!
Posted: Wed Sep 11, 2019 9:54 pm
by trabitboy
Hi!
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;
scenario:
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 !
Re: Share a Shader!
Posted: Thu Sep 12, 2019 10:18 am
by Sasha264
trabitboy,
Hi!
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
https://love2d.org/wiki/Shader:send
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]
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 = love.graphics.newShader(pixelcode)
end
-- call once for change eraser texture
function SetEraserTexture(eraser)
shader:send("eraser", eraser)
end
-- call every time you want to move eraser, i.e. every frame
function SetEraserShift(shift)
shader:send("shift", shift)
end
BTW, I suppose for this question a separate thread will be more appropriate
Re: Share a Shader!
Posted: Fri Sep 13, 2019 12:48 am
by trabitboy
well thanks Sasha264, that is very helpful
Re: Share a Shader!
Posted: Mon Sep 16, 2019 4:13 pm
by trabitboy
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()
offset={}
offset.x=400.0
offset.y=400.0
circle=love.graphics.newImage('circle.png')
cvs1=love.graphics.newCanvas(640,480)
love.graphics.setCanvas(cvs1)
--first canvas is filled with redmod
love.graphics.clear(1.0,0.0,0.0,1.0)
--the canvas holding the real image data
curcvs=cvs1
cvs2=love.graphics.newCanvas(640,480)
love.graphics.setCanvas(cvs2)
love.graphics.clear(0.0,0.0,0.0,0.0)
backcvs=cvs2 -- the back buffer the frag shader will render to
love.graphics.setCanvas()
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 ;
ret.a=ret.a-secondPixel.a;
return ret;
}
]]
shader=love.graphics.newShader(pixelcode)
shader:send("second",circle)
shader:send("cvsw",640.0)
shader:send("brshw",64.0)
shader:send("cvsh",480.0)
shader:send("brshh",64.0)
shader:send("offx",offset.x)
shader:send("offy",offset.y)
--test erase from curcvs to backcvs
love.graphics.setCanvas(backcvs)
love.graphics.setShader(shader)
love.graphics.draw(curcvs)
love.graphics.setShader()
love.graphics.setCanvas()
end
function love.draw()
love.graphics.draw(backcvs)
love.graphics.print('eraser shader test')
end
Re: Share a Shader!
Posted: Wed Oct 02, 2019 6:13 pm
by aoi_saboten
Hello guys.
Can you look to that CRT-shader used here -->
https://github.com/Akylzhan/CRT-shader
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?
Re: Share a Shader!
Posted: Sun Dec 22, 2019 2:56 pm
by YounYokel
Do anyone have a simple invert colors shader?
Re: Share a Shader!
Posted: Sun Dec 22, 2019 9:10 pm
by pgimeno