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
retrotails
Party member
Posts: 212
Joined: Wed Apr 18, 2012 12:37 am

Re: Share a Shader!

Post by retrotails »

While I'm here...
Ratchet wrote:I want to do a 360 ° view using a panorama image. To fake a perspective I want to use a inverted fisheye effect. The goal is a game like Myst with 360 ° environment. Or is there a better way to fake some kind of perspective?
http://99.30.162.147/static/code/fisheye.love
Is this what you were looking for?

Anyway, on to why I'm posting here.
Sorry, the board attachment quota has been reached.
Image
http://99.30.162.147/static/code/tetris.love
I plan on making a fancy looking Tetris clone with refractive peices and Oculus Rift support.
It uses my totally-inaccurate-but-that's-okay-because-it-still-looks-neat normal map shader.
User avatar
josefnpat
Inner party member
Posts: 955
Joined: Wed Oct 05, 2011 1:36 am
Location: your basement
Contact:

Re: Share a Shader!

Post by josefnpat »

I'm very new to shaders, but I did manage to squeeze one out.

While the shader is not very complicated, it comes with a module that should do a lot of stuff to emulate the DMG-01 style.
ozLGjZs.gif
ozLGjZs.gif (288.49 KiB) Viewed 1116 times
To make this shader work correctly, it requires a;

Code: Select all

shader:send('COLOR_MASKS',color1,color2,color3,color4)
(example in context)

I went and abstracted a bunch of color palettes (seven in total) for the DMG-01, and you can see them in action here.

And here's the shader. It is implemented here:
https://github.com/josefnpat/DMGake/blo ... 1.lua#L105

Code: Select all

extern number value;

uniform vec3 COLOR_MASKS[ 4 ];

vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords){
                        vec4 pixel = Texel(texture, texture_coords);
                        float avg = min(0.9999,max(0.0001,(pixel.r + pixel.g + pixel.b)/3));
                        int index = int(avg*4);

                        pixel.r = COLOR_MASKS[index][0];
                        pixel.g = COLOR_MASKS[index][1];
                        pixel.b = COLOR_MASKS[index][2];

                        return  pixel;
                }
https://github.com/josefnpat/DMGake

Here's a .love of the example project:

H for Help
LEFT/RIGHT for palette change
UP/DOWN for scale change
RETURN to see the image move
Attachments
DMGake.love
(221.45 KiB) Downloaded 453 times
Missing Sentinel Software | Twitter

FORCIBLY IGNORED.
<leafo> when in doubt delete all of your code
<bartbes> git rm -r *
<bartbes> git commit -m "Fixed all bugs"
<bartbes> git push
User avatar
gim
Prole
Posts: 10
Joined: Sat Dec 07, 2013 7:09 pm

Re: Share a Shader!

Post by gim »

Bumping old thread.

I've ported my old plasma code. It's based on vrld metaballs code, formula is bit different (and heavier due to sqrt).

's' will switch palette to some ugly one.
bkXKvpH.png
bkXKvpH.png (299.42 KiB) Viewed 1114 times
Attachments
plasma.love
(1.08 KiB) Downloaded 1791 times
"We must have perseverance and above all confidence in ourselves. We must believe that we are gifted for something, and that this thing, at whatever cost, must be attained." - Marie Skłodowska-Curie
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Share a Shader!

Post by Ref »

Thought we were bored with this.
Oh, well!
More nonsense.
Attachments
warp.love
Image distortion
(46.86 KiB) Downloaded 395 times
numbers.love
Stop watch
(2.1 KiB) Downloaded 330 times
flower.love
Simple circles
(1.45 KiB) Downloaded 320 times
User avatar
Davidobot
Party member
Posts: 1226
Joined: Sat Mar 31, 2012 5:18 am
Location: Oxford, UK
Contact:

Re: Share a Shader!

Post by Davidobot »

slime wrote: Here is the other way shown in the video

Code: Select all

const number pi = 3.14159265;
const number pi2 = 2.0 * pi;

extern number time;
		
vec4 effect(vec4 color, Image texture, vec2 tc, vec2 pixel_coords)
{
	vec2 p = 2.0 * (tc - 0.5);
	
	number r = sqrt(p.x*p.x + p.y*p.y);

	if (r > 1.0) discard;
	
	number d = r != 0.0 ? asin(r) / r : 0.0;
				
	vec2 p2 = d * p;
	
	number x3 = mod(p2.x / (pi2) + 0.5 + time, 1.0);
	number y3 = p2.y / (pi2) + 0.5;
	
	vec2 newCoord = vec2(x3, y3);
	
	vec4 sphereColor = color * Texel(texture, newCoord);
				
	return sphereColor;
}
First off, really sorry for replying to an old thread.
Secondly, I can not, for the love of me, work out how to use this shader properly, the image doens't spin!

Controls for the .love file:
Z - Toggle Shader
Space - Generate new planet
Attachments
Planet Generation.love
(1.79 KiB) Downloaded 402 times
PM me on here or elsewhere if you'd like to discuss porting your game to Nintendo Switch via mazette!
personal page and a raycaster
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Share a Shader!

Post by Ref »

Davidobot wrote: I can not, for the love of me, work out how to use this shader properly, the image doens't spin!
I love these types of questions.
They almost make me fell like I know what I'm talking about.
Try adding this:

Code: Select all

function love.update(dt)
   tm  = tm + dt
   sphere:send( 'time', tm )
end
(don't forget to add tm = 0 in love.load )
If you don't update anything, nothing will change.
Best
User avatar
Davidobot
Party member
Posts: 1226
Joined: Sat Mar 31, 2012 5:18 am
Location: Oxford, UK
Contact:

Re: Share a Shader!

Post by Davidobot »

Ref wrote:
Davidobot wrote: If you don't update anything, nothing will change.
Thank you, kind sir! :monocle:
PM me on here or elsewhere if you'd like to discuss porting your game to Nintendo Switch via mazette!
personal page and a raycaster
User avatar
qwook
Prole
Posts: 40
Joined: Fri Dec 13, 2013 5:53 am

Re: Share a Shader!

Post by qwook »

Left 4 Dead style glow
Image

Code: Select all

local glow_effect = love.graphics.newShader([[
extern vec2 size;

vec2 clamp(vec2 pos) {
    number x = pos.x;
    number y = pos.y;
    if (x < 0.0) x = 0.0;
    if (y < 0.0) y = 0.0;
    if (x > 1.0) x = 1.0;
    if (y > 1.0) y = 1.0;
    return vec2(x, y);
}

vec4 effect ( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords ) {
    number distance = 1.0;
    number num = 0.0;
    vec4 averagecolor = vec4(0.0, 0.0, 0.0, 0.0);
    for (number x = -6.0 ; x <= 6.0; x++)
    for (number y = -6.0 ; y <= 6.0; y++) {
        vec4 color = Texel(texture, clamp(vec2(texture_coords.x + x/size.x, texture_coords.y + y/size.y)));
        if (color.a > 0.0) {
            num = num + 1.0;
            averagecolor.r = (averagecolor.r + color.r);
            averagecolor.g = (averagecolor.g + color.g);
            averagecolor.b = (averagecolor.b + color.b);
            averagecolor.a = (averagecolor.a + color.a);
            number x1 = x/size.x;
            number y1 = y/size.y;
            number dist = sqrt( x1*x1 + y1*y1 ) * 200;
            if (dist < distance) {
                distance = dist;
            }
        }
    }
    return vec4(averagecolor.r / num, averagecolor.g / num, averagecolor.b / num, averagecolor.a / num - distance);
}
]])
Can probably be simplified with a hard-coded color, but this way you can set the glow color to anything you want without having to use multiple framebuffers. I used a framebuffer here instead of rendering each individual sprite under the effect.
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Share a Shader!

Post by Ranguna259 »

Can anyone make me this shader ? Motion blur effect or per pixel motion blur or per object motion blur, whichever strikes you guys best.
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
styves
Prole
Posts: 5
Joined: Mon Jan 13, 2014 5:45 pm

Re: Share a Shader!

Post by styves »

Per-pixel motion blur is on my todo-list. :)
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 5 guests