Page 8 of 33

Re: Share a Shader!

Posted: Wed May 09, 2012 7:36 pm
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,

Re: Share a Shader!

Posted: Wed May 09, 2012 7:50 pm
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 ;)

Re: Share a Shader!

Posted: Sat May 12, 2012 3:13 pm
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.

Re: Share a Shader!

Posted: Mon May 21, 2012 3:37 pm
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.

Re: Share a Shader!

Posted: Mon May 21, 2012 3:49 pm
by Nixola
What program do you use to create .zips?

Re: Share a Shader!

Posted: Mon May 21, 2012 4:36 pm
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()

Re: Share a Shader!

Posted: Mon May 21, 2012 4:56 pm
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

Re: Share a Shader!

Posted: Mon May 21, 2012 5:53 pm
by Nixola
I don't trust Windows anymore, I'd suggest trying 7zip

Re: Share a Shader!

Posted: Mon May 21, 2012 6:46 pm
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.

Re: Share a Shader!

Posted: Wed May 23, 2012 4:06 pm
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