Love2d GLSL Shaders

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.
AndreyMust19
Prole
Posts: 21
Joined: Thu Mar 06, 2014 3:00 pm

Re: Love2d GLSL Shaders

Post by AndreyMust19 »

Hello, guys. I'm ask here.

With

Code: Select all

vec4 effect(vec4 color, Image texture, vec2 tc, vec2 pc) {
vec4 pixel = Texel(texture, tc)
return pixel*color
}
drawing images, but not drawing lines, circles and rectanges (they not have texture).

And with

Code: Select all

vec4 effect(vec4 color, Image texture, vec2 tc, vec2 pc) {
return color
}
drawing lines, but not images (just fills color).
How to draw images and drawable-primitives with one shader? How to find what no have texture coordinates?
User avatar
slime
Solid Snayke
Posts: 3132
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Love2d GLSL Shaders

Post by slime »

The first one will work in both cases, because the Texel function will always return pure white when drawing untextured things.
AndreyMust19
Prole
Posts: 21
Joined: Thu Mar 06, 2014 3:00 pm

Re: Love2d GLSL Shaders

Post by AndreyMust19 »

Create new project.

Draw-code:

Code: Select all

if settings.effect ~= 0 then love.graphics.setPixelEffect(effects[settings.effect]) end
	love.graphics.draw(image);
	love.graphics.setColor(255,255,255,255)
	love.graphics.rectangle('fill',0,0,200,100)
love.graphics.setPixelEffect()
NO SHADER
Image

NORMAL SHADER
Image
[[
vec4 effect(vec4 color, Image texture, vec2 tc, vec2 pc)
{
return Texel(texture, tc)*color;
}
]]
GRAYSCALE
Image
[[
vec4 effect(vec4 color, Image texture, vec2 tc, vec2 pc)
{
vec4 pixel = Texel(texture, tc);
float gray = (pixel.r + pixel.g + pixel.b)/3;
pixel.r = gray;
pixel.g = gray;
pixel.b = gray;
pixel.a = color.a
return pixel;
}
]]
What i doing wrong? Why rectangle is gray, not white ('grayscale2' is just name of normal shader)?
What standart shader love2d used, for 'blend' mode?
User avatar
slime
Solid Snayke
Posts: 3132
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Love2d GLSL Shaders

Post by slime »

The issue is that you're using LÖVE 0.8.0 (which has been superseded for over half a year already.) What I said only applies to 0.9.0 and newer - update your LÖVE! You'll need to update your code too, but it's worth it.
User avatar
Jeeper
Party member
Posts: 611
Joined: Tue Mar 12, 2013 7:11 pm
Contact:

Re: Love2d GLSL Shaders

Post by Jeeper »

slime wrote:The issue is that you're using LÖVE 0.8.0 (which has been superseded for over half a year already.) What I said only applies to 0.9.0 and newer - update your LÖVE! You'll need to update your code too, but it's worth it.
To add to this, updating your code will not take long at all. I had a quite huge project that took 5-10min or so to convert.
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Love2d GLSL Shaders

Post by Ref »

Presume you have this figured out by now. If not, look at attachment.
Attachments
rbg2gray.love
Simple rgb to gray shader
(277.47 KiB) Downloaded 162 times
AndreyMust19
Prole
Posts: 21
Joined: Thu Mar 06, 2014 3:00 pm

Re: Love2d GLSL Shaders

Post by AndreyMust19 »

Thx all for helping. Anyway game almost ready.
AndreyMust19
Prole
Posts: 21
Joined: Thu Mar 06, 2014 3:00 pm

Re: Love2d GLSL Shaders

Post by AndreyMust19 »

Hello again!

How with shader transform from:
Image
to this:
Image

I think, need drawing of image down? How it make at GLSL?
Germanunkol
Party member
Posts: 712
Joined: Fri Jun 22, 2012 4:54 pm
Contact:

Re: Love2d GLSL Shaders

Post by Germanunkol »

If the shapes you're showing are meshes, using vertices, then you should look into vertex shaders.

Vertex shaders can take a vertex and move it somewhere else, think of it as "positioning" objects.

However, it's not quite clear what you want to do: Are the shapes moving? Do you know exactly where the shapes are? Or are they somewhere else every time?

In any case, the method above is not the best way to go - instead, create the shapes in Lua and then move them in Lua.
Or why does it need to be in glsl (why on the graphics card?)
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
Zilarrezko
Party member
Posts: 345
Joined: Mon Dec 10, 2012 5:50 am
Location: Oregon

Re: Love2d GLSL Shaders

Post by Zilarrezko »

It took me a couple look overs to see what was happening.

The shapes from the top image are "smeared" downward. Kinda like how lighting creates a shadow, this is kinda what's happening here. Except It's not like a point light, it's like a wave of light or something from the top.

I am very unfamiliar with working with shaders, and in no way can manipulate them to do something that I would like without basically copying someone else. So when I saw it yesterday, I passed it by.

However, I did see something that had a very similar effect.

I would guess you would do what he is doing. Though you don't need to bend the objects like he did with rectangular to polar.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 219 guests