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
StoneCrow
Party member
Posts: 199
Joined: Sat Apr 17, 2010 9:31 am
Location: Wales the land of leeks and leaks
Contact:

Re: Share a Shader!

Post by StoneCrow » Thu Jun 07, 2012 4:08 pm

Dont mind at all, its actually good to see how its supposed to work I havent got a very good grasp of love-glsl yet
Dull but sincere filler.

User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Share a Shader!

Post by Robin » Thu Jun 07, 2012 6:17 pm

Patalo wrote:Well, I took StoneCrow's code to finish the adaptation of the film effect (I hope you don't mind :3 )
It works pretty well, I think I will take some parts for my project. The desaturation/illumination that comes with the grain is really cool.
Oh, wow, that shader actually works on my computer! I thought none of them would work...

EDIT: so far all of them work. :O
Last edited by Robin on Thu Jun 07, 2012 6:40 pm, edited 1 time in total.
Help us help you: attach a .love.

User avatar
Ref
Party member
Posts: 690
Joined: Wed May 02, 2012 11:05 pm

Re: Share a Shader!

Post by Ref » Thu Jun 07, 2012 6:35 pm

Great!
Thanks for completing this.
Learning something with every example.

User avatar
Lafolie
Inner party member
Posts: 805
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: Share a Shader!

Post by Lafolie » Thu Jun 07, 2012 7:22 pm

The film grain is very pretty! I love it.
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.

User avatar
AaronWizard
Citizen
Posts: 68
Joined: Sun Nov 06, 2011 2:45 pm
Location: Canada

Re: Share a Shader!

Post by AaronWizard » Sat Jun 09, 2012 7:56 pm

Simplex noise terrain generator, based on this project for GLSL noise.

There are two things I can't figure out though. One, I want the terrain to wrap horizontally and vertically for a preferably arbitrary pair of dimensions; e.g. the screen width and height. Two, I want to be able stick in a seed value somewhere (os.time() I guess) so that I can get different landscapes, plus different noise patterns to get things like rainfall. Both features apparently need lots of maths for me to implement even with regular simplex noise, not mentioning the GLSL optimized simplex noise code I copy-and-pasted.
Attachments
simplex_terrain.png
simplex_terrain.png (265.6 KiB) Viewed 2761 times
worldgen.love
(2.83 KiB) Downloaded 271 times

User avatar
kexisse
Citizen
Posts: 56
Joined: Wed Jun 13, 2012 2:52 pm

Re: Share a Shader!

Post by kexisse » Thu Jun 14, 2012 2:21 am

These effects are beautiful! I'm trying to create my first shader, but I still can't get my head around it. Are there any books or tutorials people can recommend?

Also, is there a way to apply a shader to everything on-screen? So far it seems to only apply to the way each of my individual objects are drawn.

(Edit: I think I answered my own question, you make a canvas object the size of the screen, draw all your stuff to it, apply a shader, then draw it to the screen. Right?)

User avatar
richapple
Citizen
Posts: 65
Joined: Sun Dec 25, 2011 10:25 am

Re: Share a Shader!

Post by richapple » Thu Jun 14, 2012 10:43 am

kexisse wrote:you make a canvas object the size of the screen, draw all your stuff to it, apply a shader, then draw it to the screen. Right?
Or you can

Code: Select all

function love.load()
    blank = love.graphics.newImage(love.graphics.newImageData(1, 1))
end
and then

Code: Select all

function love.draw()
    love.graphics.setPixelEffect(effect)
    love.graphics.draw(blank, 0, 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
    love.graphics.setPixelEffect()
end
This code creates a 1px image and then stretches it to the size of screen with pixels accesible through texture_coords. I'm doing it because many people say they don't support canvases but you are free to do anything.
kexisse wrote:Are there any books or tutorials people can recommend?
For sure:
  1. glsl.heroku.com > 100 effects that are free to fork and learn from
  2. duh
  3. this thread. No, seriously the most helpful examples I've ever seen. I learned from totally zero.
AaronWizard wrote:Simplex noise terrain generator, based on this project for GLSL noise.
Ah, I remember playing around with it. Very awesome code. About randomness I did it this way:
(Please note I don't completely remember)

Code: Select all

effect = love.graphics.newPixelEffect([[
    extern number randx;
    extern number randy;
    vec4 effect(-some stuff-)
    {
        float x = -your coords- + randx;
        float y = -your coords- + randx;
        -your effect code-
    }
]])
effect:send("randx", math.random()*100)
effect:send("randy", math.random()*100)
or maybe if something like that will work:

Code: Select all

effect = love.graphics.newPixelEffect([[
    number randx = (]] .. math.random()*100 .. [[);
    number randy = (]] .. math.random()*100 .. [[);
    vec4 effect(-some stuff-)
    {
        float x = -your coords- + randx;
        float y = -your coords- + randx;
        -your effect code-
    }
]])
Because our shader is basically a string, we can concatenate it with anything

User avatar
Mandarancio
Prole
Posts: 11
Joined: Mon Nov 03, 2008 5:08 pm
Location: Parma - Italy
Contact:

Re: Share a Shader!

Post by Mandarancio » Wed Jul 04, 2012 7:06 pm

God-Rays shader

From http://fabiensanglard.net/lightScattering/index.php
External variable (play with this parametrs):
decay (~0.5-0.8)
density (~0.2-0.4)
weight (~0.5-2)
lightPositionOnScreen (vec2 with the position of the light [using texture coordinate (0.0-1.0,0.0-1.0)])

Code: Select all

extern number decay;
extern number density;
extern number weight;
extern vec2 lightPositionOnScreen;
//uniform sampler2D firstPass;
const number NUM_SAMPLES = 100 ;

 vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords)
{

  vec2 deltaTextCoord = texture_coords - lightPositionOnScreen;
 
  deltaTextCoord *= 1.0 / float(NUM_SAMPLES) * density;
  number illuminationDecay = 1.0;
  vec2 textCoo=texture_coords;
 
  vec4 result=texture2D(texture, textCoo );
  for(int i=0; i < NUM_SAMPLES ; i++)
   {
     	  textCoo -= deltaTextCoord;
     	  vec4 sample = texture2D(texture, textCoo );
          sample *= illuminationDecay * weight;
          result += sample;
          illuminationDecay *= decay;
  } 
  return result;
}
Enjoy!
Arch Linux user..
..No Freedom without Sharing..
http://mandarancio.deviantart.com/
http://manda.netsons.org/

User avatar
Ref
Party member
Posts: 690
Joined: Wed May 02, 2012 11:05 pm

Re: Share a Shader!

Post by Ref » Fri Jul 06, 2012 11:52 pm

Thanks Mandarancio!
Hacked together a Love to try out all the parameters.
Not that easy to get the right combination so provided a random keyboard parameter selection - I know, no real no logic but at least I gave you a help screen and on-screen parameter setting display.
Found adding 'fog' made the effect a little more apparent.
Press <g> and <f> to toggle effects on/off.
Don't know exactly how you would use in a game but fun to play around with.
<New version of god_ray that doesn't recreate effect each cycle.>
Attachments
god_ray.love
Updated test script for god_ray
(101.29 KiB) Downloaded 462 times

User avatar
Ref
Party member
Posts: 690
Joined: Wed May 02, 2012 11:05 pm

Re: Share a Shader!

Post by Ref » Sun Jul 08, 2012 11:41 pm

Hi!
Anybody create a Sobel (edge detection) PixelEffect using the kernal:
1 2 1
0 0 0
-1 -2 -1

Post Reply

Who is online

Users browsing this forum: No registered users and 20 guests