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)
Share a Shader!
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- wazoowazoo
- Prole
- Posts: 16
- Joined: Sun Jan 22, 2017 2:47 pm
Re: Share a Shader!
I have created a basic water shader, hope you will like it.
I am currently working on reflection.- wazoowazoo
- Prole
- Posts: 16
- Joined: Sun Jan 22, 2017 2:47 pm
Re: Share a Shader!
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:
Here's a preview:
Re: Share a Shader!
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 !
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!
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):
BTW, I suppose for this question a separate thread will be more appropriate
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
Re: Share a Shader!
well thanks Sasha264, that is very helpful
Re: Share a Shader!
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
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
- Attachments
-
- love2dshadertests.zip
- (4.17 KiB) Downloaded 490 times
-
- Prole
- Posts: 2
- Joined: Wed Oct 02, 2019 4:53 pm
Re: Share a Shader!
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?
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!
Do anyone have a simple invert colors shader?
Who is online
Users browsing this forum: No registered users and 9 guests