how to attach a shader to a sprite?

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.
Post Reply
girng
Prole
Posts: 40
Joined: Fri Sep 07, 2018 5:42 am

how to attach a shader to a sprite?

Post by girng »

i have a shader in godot:
shader_type canvas_item;

uniform float aura_width=2;
uniform vec4 aura_color=vec4(0.4,0.7,0.3,1);
//uniform vec4 aura_color : hint_color;
void fragment() {
vec4 col = texture(TEXTURE,UV);
vec2 ps = TEXTURE_PIXEL_SIZE;
float a;
float maxa=col.a;
float mina=col.a;
a=texture(TEXTURE,UV+vec2(0,-aura_width)*ps).a;
maxa=max(a,maxa);
mina=min(a,mina);

a=texture(TEXTURE,UV+vec2(0,aura_width)*ps).a;

maxa=max(a,maxa);
mina=min(a,mina);
a=texture(TEXTURE,UV+vec2(-aura_width,0)*ps).a;

maxa=max(a,maxa);
mina=min(a,mina);
a=texture(TEXTURE,UV+vec2(aura_width,0)*ps).a;
maxa=max(a,maxa);
mina=min(a,mina);
col.rgb*=col.a;
COLOR=col;//mix(col,aura_color,maxa-mina);


//COLOR.rgb = vec3(aura_color[0],aura_color[1],aura_color[2]);
//COLOR.a = 0.1;
float auraa=(maxa-mina);

COLOR.rgb+=aura_color.rgb*(maxa-mina);
}
but i want to attach it to a sprite, so i can make it glow. i did some googling and searching but with no prevail ty

i got a nice is_overlap function too. so i can do onhover events on world objects. it's gonna be fun.
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: how to attach a shader to a sprite?

Post by zorg »

You set the shader you want to use, then draw the sprite you want to use the shader on.

http://blogs.love2d.org/content/let-it- ... characters
can be relevant, although it's probably for an older version; still some of the techniques may still apply.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
girng
Prole
Posts: 40
Joined: Fri Sep 07, 2018 5:42 am

Re: how to attach a shader to a sprite?

Post by girng »

zorg wrote: Wed Sep 12, 2018 9:25 am You set the shader you want to use, then draw the sprite you want to use the shader on.

http://blogs.love2d.org/content/let-it- ... characters
can be relevant, although it's probably for an older version; still some of the techniques may still apply.

ty. just read over it. followed it

got here

Code: Select all

shader_glow:send( "stepSize", {3/sprite2.image:getWidth(), 3/sprite2.image:getHeight()})
        love.graphics.setShader( shader_glow )
        love.graphics.draw(sprite2.image, body_x, body_y)
        love.graphics.setShader()
however. my sprite then disappears lol

but if i comment the setShader line, sprite appears, but with no shader.

hmm. i'm on latest 11.1 btw

gtx 950
User avatar
pgimeno
Party member
Posts: 3550
Joined: Sun Oct 18, 2015 2:58 pm

Re: how to attach a shader to a sprite?

Post by pgimeno »

That shader only draws the outline itself, not the sprite. After drawing it, you need to draw the sprite again.

When you say "glow", I'm not sure if you mean a bloom effect, or an outline. These are different effects.

If you mean bloom effect, this thread talks about it, viewtopic.php?t=82133 and I believe there are shader libraries that incorporate it as a pre-made effect.

If you mean outline, this thread talks about it: viewtopic.php?f=4&t=85284 and there's a post based on it with a shader that also draws the sprite, rather than having to be drawn separately: viewtopic.php?p=221215#p221215
girng
Prole
Posts: 40
Joined: Fri Sep 07, 2018 5:42 am

Re: how to attach a shader to a sprite?

Post by girng »

pgimeno wrote: Wed Sep 12, 2018 10:46 am That shader only draws the outline itself, not the sprite. After drawing it, you need to draw the sprite again.

When you say "glow", I'm not sure if you mean a bloom effect, or an outline. These are different effects.

If you mean bloom effect, this thread talks about it, viewtopic.php?t=82133 and I believe there are shader libraries that incorporate it as a pre-made effect.

If you mean outline, this thread talks about it: viewtopic.php?f=4&t=85284 and there's a post based on it with a shader that also draws the sprite, rather than having to be drawn separately: viewtopic.php?p=221215#p221215
yes thx. however, i believe something is bugged because some of the shaders just show a white overlay over my sprite or just disappears them.

for example:
viewtopic.php?f=4&t=3733&start=200#p159576

this one is exactly what i want, and it just poofs my sprite (totally disappears).

am i rendering it in the right order?

Code: Select all

love.graphics.setShader( shader_glow )
love.graphics.draw(sprite2.image, body_x, body_y)
love.graphics.setShader()
girng
Prole
Posts: 40
Joined: Fri Sep 07, 2018 5:42 am

Re: how to attach a shader to a sprite?

Post by girng »

ok i think i got it.

i can't just copy and paste shaders online because the extern thing needs get data from :send?
i did :send and i am starting to see some of the outlines
Post Reply

Who is online

Users browsing this forum: No registered users and 82 guests