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.
User avatar
veethree
Inner party member
Posts: 877
Joined: Sat Dec 10, 2011 7:18 pm

Re: Share a Shader!

Post by veethree »

Palmar wrote:Bump.
See number 7.
Palmar wrote:I am totally confused of Love2D Shader GLSL structure. Could sombody post color inverse shader? Thanks in advance.
Read this.

You can also load shader files directly i think (.glsl/.sh/.frag or whatever the extensions were.)
Germanunkol
Party member
Posts: 712
Joined: Fri Jun 22, 2012 4:54 pm
Contact:

Re: Share a Shader!

Post by Germanunkol »

Palmar wrote:I am totally confused of Love2D Shader GLSL structure. Could sombody post color inverse shader? Thanks in advance.
Here you go:
ColorInvert.love
Unpack to see the code...
(146.47 KiB) Downloaded 781 times
It's pretty straight forward, check the colorInvert.glsl file for the shader function.
texture2D gives you the color at of the image you're drawing, at the coordinates you give to the function as a second argument.
Note that the colors in glsl are always between 0 and 1 (and the coordinates usually are, too), so "1-color" gives you an inverted color.
The function in the shader is run every frame on every pixel, and its return value is the value used for the pixel on the screen. So basically, the programm passes to the function "this is how I'd draw the pixel", the function modifies the pixel color and then draws the pixel, modified.
If you have questions, check the wiki or feel free to ask...
trAInsported - Write AI to control your trains
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
User avatar
beforan
Prole
Posts: 10
Joined: Sat Dec 15, 2012 1:15 pm
Location: Nottingham, UK

Re: Share a Shader!

Post by beforan »

this is pretty simple stuff, and sorry if it's duplicated but I couldn't find one from cursory searching:

a colour cycling shader!

pixel code:

Code: Select all

extern number time;
number t;
vec4 effect(vec4 color, Image tex, vec2 tc, vec2 pc)
{
    t = time * 1.5; //may want to vary this for cycle speed?
    color = Texel(tex, tc);
    return vec4(vec3(sin(t + 5)+0.3, -sin(t+5)+0.3, sin(t + 10)) * (max(color.r, max(color.g, color.b))), 1.0); //cycles colors and pulses brightness slightly
}
vertex code (standard, doing nothing special):

Code: Select all

varying vec4 vpos;
vec4 position( mat4 transform_projection, vec4 vertex_position )
{
    vpos = vertex_position;
    return transform_projection * vertex_position;
}
then send time to the shader every update:

Code: Select all

--shader updates
self.t = self.t + math.min(dt, 1/30)
self.bgShader:send("time", self.t)
I recently used this with a repeated grey scrolling gradient to produce a lovely "retro" effect (attached .love)

I realise I could do the whole effect in a shader, but I'm still dipping my toes here, and the color cycling can be applied to whatever you're drawing now!
Attachments
colorcycle.love
(1.88 KiB) Downloaded 732 times
User avatar
PriorBlue
Prole
Posts: 43
Joined: Fri Feb 28, 2014 3:46 am
Location: Munich, Germany

Re: Share a Shader!

Post by PriorBlue »

Hi,

i scripted a pixel light shader effect. It is very slow, but it looks nice, so i want to share it. :joker:

Maybe someone can improve the performance. At the moment, it doesn't work with shadows from walls outside the screen.

In this example you can move the lights and draw/erase walls. Every pixel can cast a shadow or change the color of the light (glass).

It is very simple to use:

Code: Select all

require "lightmap"

function love.load()
	-- create light world
	lightWorld = love.lightmap.newWorld()
	lightWorld.setAmbientColor(31, 31, 31)
	-- set the shadow canvas with alpha/color informations
	lightWorld.setShadowCanvas(shadowCanvas)

	-- create lights
	myLight = lightWorld.newLight(x, y, red, green, blue, range)
end

function love.update(dt)
	-- update light position, color, range etc.
	myLight.setPosition(x, y)
	-- update lightmap
	lightWorld.update()
end

function love.draw()
	-- draw lightmap
	lightWorld.draw() -- or use love.graphics.draw(lightWorld.canvas)
end
Here is a screenshot for your entertainment.
Image

Have fun! :awesome:
Attachments
pixellight.love
(24 KiB) Downloaded 845 times
User avatar
Fenrir
Party member
Posts: 222
Joined: Wed Nov 27, 2013 9:44 am
Contact:

Re: Share a Shader!

Post by Fenrir »

It's very nice, congratulation!
Can I ask you what formula are you using to blend your light color with the ground ? It gives a really good looking result.

Cheers,

EDIT: OK I checked and it's multiplicative blending ! :)
User avatar
veethree
Inner party member
Posts: 877
Joined: Sat Dec 10, 2011 7:18 pm

Re: Share a Shader!

Post by veethree »

Wavy distortion i found here and ported. You can use the mouse wheel to change the size of the waves, Hold shift to change it faster. May contain penguins.
Image
Attachments
Distortion.love
0.9.0
(757.81 KiB) Downloaded 1047 times
Germanunkol
Party member
Posts: 712
Joined: Fri Jun 22, 2012 4:54 pm
Contact:

Re: Share a Shader!

Post by Germanunkol »

Haha, distortion size 2 to 4 makes them drunk, distortion 10 makes them dance :D
trAInsported - Write AI to control your trains
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
User avatar
andmatand
Prole
Posts: 21
Joined: Wed Jan 25, 2012 8:46 pm
Location: Eugene, OR
Contact:

Re: Share a Shader!

Post by andmatand »

josefnpat wrote:Image
Whaaaaat where did you get those pictures of Monkey Island and Psychonauts as Gameboy games?? Did you make those?? THEY ARE THE COOLEST THING EVER :o
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Share a Shader!

Post by Nixola »

Germanunkol wrote:Haha, distortion size 2 to 4 makes them drunk, distortion 10 makes them dance :D
9651 kinda wraps around here
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: Share a Shader!

Post by Positive07 »

beforan wrote:this is pretty simple stuff, and sorry if it's duplicated but I couldn't find one from cursory searching:

a colour cycling shader!

pixel code:

Code: Select all

extern number time;
number t;
vec4 effect(vec4 color, Image tex, vec2 tc, vec2 pc)
{
    t = time * 1.5; //may want to vary this for cycle speed?
    color = Texel(tex, tc);
    return vec4(vec3(sin(t + 5)+0.3, -sin(t+5)+0.3, sin(t + 10)) * (max(color.r, max(color.g, color.b))), 1.0); //cycles colors and pulses brightness slightly
}
vertex code (standard, doing nothing special):

Code: Select all

varying vec4 vpos;
vec4 position( mat4 transform_projection, vec4 vertex_position )
{
    vpos = vertex_position;
    return transform_projection * vertex_position;
}
then send time to the shader every update:

Code: Select all

--shader updates
self.t = self.t + math.min(dt, 1/30)
self.bgShader:send("time", self.t)
I recently used this with a repeated grey scrolling gradient to produce a lovely "retro" effect (attached .love)

I realise I could do the whole effect in a shader, but I'm still dipping my toes here, and the color cycling can be applied to whatever you're drawing now!
I wanted to know the shader support on the love-android port so I decided to try this one... It's awesome!! I just made one little change in line 11 of your main.lua

Code: Select all

 return vec4(vec3(sin(t + 5.0)+0.3, -sin(t+5.0)+0.3, sin(t + 10.0)) * (max(color.r, max(color.g, color.b))), 1.0); //cycles colors and pulses brightness slightly
Insted of using 5 it uses 5.0 (same with 10) since it can't add a float and a constant integer. Just that and your shader is compatible with android :awesome:
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 2 guests