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
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Share a Shader!

Post by Ref »

If nothing else, persistent.
Another shader.
One thing you can say about shaders is they are counter-intuitive.
Have to reverse your logic.
Think this shader is for a glass ball but (as dumb as it might seem) not sure what a glass ball should look like.
Appreciate feedback.
Best,
Attachments
Glass Ball.love
Glass shader
(206.13 KiB) Downloaded 637 times
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Share a Shader!

Post by vrld »

Ref wrote:Would like a transparent ball shader.
What do you mean by that?
Ref wrote:One thing you can say about shaders is they are counter-intuitive.
Have to reverse your logic.
Yeah, you basically have to think in terms of what should be done to the pixel that you are processing right now instead of what are the pixels that you need to process given the thing that you have at the moment. Or in other words: You have to think in implicit rather than explicit terms.
I really like the pixel effect way, because it forces you approach you problem from a new direction, which in turn leads to a better understanding of what you are doing.

Cool effect by the way ;)
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Share a Shader!

Post by Ref »

Guess I didn't really appreciate how setPixelEffect works.
Ran into another gotchU.
Coordinate system (y axis) appears to be inverted when effect is applied to an 'image' rather than to a 'canvas'.
Such is life.
Have to do some more reading.
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Share a Shader!

Post by Ref »

Still trying to figure out PixelEffect.
Got a morphing effect to almost work.

Code: Select all

morph = gr.newPixelEffect [[
   extern float  tran;
   vec4 effect(vec4 color, Image texture, vec2 tc, vec2 pc )
   {
   vec4 pixel = Texel( texture, tc );
   {pixel.r = tran*pixel.r;}
   {pixel.g = tran*pixel.g;}
   {pixel.b = tran*pixel.b;}
   {pixel.a = tran*pixel.a;}
   return pixel;
   }
   ]]
and in love.draw()

Code: Select all

morph:send( 'tran', tran )
gr.setPixelEffect( morph )
gr.draw( image1,0,0,0,1,1 )
morph:send( 'tran', 1-tran )
gr.setPixelEffect( morph )
gr.draw( image2,0,0,0,1,1 )
gr.setPixelEffect()
Works as expected but ran into a dumb situation when I tried to create a Love file.
The image files hve to have an alpha channel - so I used png files.
Zip doesn't seem to like to include png files.
What am I doing wrong?
Help appreciated.
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 »

What program do you use to create .zips?
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Share a Shader!

Post by vrld »

You can shorten the code by sending the target image to the effect.

Effect code:

Code: Select all

extern Image target_image;
extern number s; // from 0 to 1
vec4 effect(vec4 color, Image texture, vec2 tc, vec2 pc )
{
    vec4 pixel_from = Texel(texture, tc);
    vec4 pixel_to = Texel(target_image, tc);
    // you don't have to add the individual channels here
    return (1.0 - s) * pixel_from + s * pixel_to;
    // you could also write:
    // return (1.0 - s) * Texel(texture,tx) + s * Texel(target_image, tc);
}
Lua side code:

Code: Select all

fade:send('target_image', image2) -- somewhere in love.load
-- ...
fade:send('s', s)
love.graphics.setPixelEffect(fade)
love.graphics.draw(image1, 0, 0)
love.graphics.setPixelEffect()
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Share a Shader!

Post by Ref »

Thanks for the responses!
Nixola - using Windows SENG TO which works fine for jpg - so was surprised when it didn't do png.
Vrid - exactly what I wanted to know! will try your code.
Thanks all1
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 »

I don't trust Windows anymore, I'd suggest trying 7zip
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Share a Shader!

Post by Ref »

Sorry! Problem with zip was a typo.
Vrid's PixelEffect works fine (once tx is shanged to tc).
Would still like to be ale to change only a portion of the image so need to know how to index image2 data.
Attachments
morph.love
Simple image morphing
(1.03 MiB) Downloaded 546 times
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Share a Shader!

Post by Ref »

Ok!
Just another (not too bright) example of PixelEffect.
Falls into the pigless 8 second category.
If you get tired of seeing random spots before your eyes, just hit 'r' and arrow keys & 'a'/'s' keys are available.
Still struggling with syntax for GLSL effects but coming slowly.
Best
Attachments
spot.love
(1.04 MiB) Downloaded 549 times
Post Reply

Who is online

Users browsing this forum: Amazon [Bot] and 15 guests