Shockwave effect

General discussion about LÖVE, Lua, game development, puns, and unicorns.
UltraRPG
Prole
Posts: 5
Joined: Sat Sep 20, 2014 9:55 am

Shockwave effect

Post by UltraRPG »

Hello! Yesterday I watched this video and was inspired to make a shockwave shader. It turned out alright but I feel that I am doing something wrong. It just feels that way. Most of my projects that I have started don't have any graphics yet. Most of my time I've spent coding the gameplay stuff so I have no experience in drawing to the screen. I would be happy if someone could take a look at my code and tell me if I am doing something wrong. Thank you in advance.
------
How it works:
I have a canvas where I store the displacement data:
Pixel's red and blue values represent a direction vector of displacement, green value is the distance of displacement, and alpha is just the strength of the displacement. I draw to the canvas using a shader that generates the data I need. When the shockwave data is drawn to the canvas I send the canvas to the displacement shader and then draw the background. The background image is not mine. It's just a screenshot I found on google.

------
Controls:
Mouse 1 to spawn a shockwave.
Hold space to keep spawning shockwaves.
R to toggle displacement shader.
Attachments
Shockwave.love
(1.1 MiB) Downloaded 340 times
User avatar
evgiz
Citizen
Posts: 83
Joined: Mon Aug 29, 2016 11:05 pm
Contact:

Re: Shockwave effect

Post by evgiz »

Looks awesome! I used a similar effect in an old project of mine using a modified fisheye-effect shader. This method however seems much better, I'll remember this if I ever need something similar!

There was one thing I didnt quite understand though. When holding down space while the displacement shader is toggled, it looks quite different than the displacement "circle" texture with regular clicks. What are the cyan/pink lines, and how come the rest is completely white?
Computer science student and part time game dev! Currently working on Depths of Limbo! :cool:

Check out the game website DepthsOfLimbo.com! :ultrahappy:
And my personal website with all my projects evgiz.net! :megagrin:
UltraRPG
Prole
Posts: 5
Joined: Sat Sep 20, 2014 9:55 am

Re: Shockwave effect

Post by UltraRPG »

evgiz wrote: Mon Mar 06, 2017 6:59 pm Looks awesome!
Thanks!
evgiz wrote: Mon Mar 06, 2017 6:59 pm There was one thing I didnt quite understand though. When holding down space while the displacement shader is toggled, it looks quite different than the displacement "circle" texture with regular clicks. What are the cyan/pink lines, and how come the rest is completely white?
Oh, I forgot to explain one thing. Direction vector's range is (-1;1) but colour value range is (0;1). So I have to convert between those in the shaders. The cyan, pink, and white colours are a result of the screen blend mode. The screen blend mode is not suitable for this thing. It just ruins everything but at least it looks better than the alpha blend mode. You can clearly see what's wrong if you slow down the speed of expanding (the v.t = v.t + dt*1000 part) and spawn some shockwaves near each other. If there's a way to make your own blend mode I would make one that takes into account that we are not really working with colours but with vector data.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Shockwave effect

Post by Nixola »

Aren't shaders basically custom blend modes?
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
UltraRPG
Prole
Posts: 5
Joined: Sat Sep 20, 2014 9:55 am

Re: Shockwave effect

Post by UltraRPG »

Nixola wrote: Mon Mar 06, 2017 7:13 pm Aren't shaders basically custom blend modes?
I would guess that blend mode takes into account the pixel values of the image you are drawing and the pixel values of the image you are drawing onto. I'm new to shaders, but I think that if you wanted to make your own custom blend mode you had to pass additional image data to the shader each time you want to draw something which would be a hit on performance. Like I said I don't know much about drawing but maybe the built-in blend modes also give you a performance hit.
User avatar
nice
Party member
Posts: 191
Joined: Sun Sep 15, 2013 12:17 am
Location: Sweden

Re: Shockwave effect

Post by nice »

This is super cool!
It felt like I was pulling a water-blob around the screen!
:awesome: Have a good day! :ultraglee:
UltraRPG
Prole
Posts: 5
Joined: Sat Sep 20, 2014 9:55 am

Re: Shockwave effect

Post by UltraRPG »

nice wrote: Mon Mar 06, 2017 7:30 pm This is super cool!
It felt like I was pulling a water-blob around the screen!
Thank you!
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Shockwave effect

Post by Jasoco »

Oh my, I've been looking for something like this to use when an explosion goes off. I'll have to see if I can implement it in when I redo bombs.
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Shockwave effect

Post by zorg »

UltraRPG wrote: Mon Mar 06, 2017 7:20 pm
Nixola wrote: Mon Mar 06, 2017 7:13 pm Aren't shaders basically custom blend modes?
I would guess that blend mode takes into account the pixel values of the image you are drawing and the pixel values of the image you are drawing onto. I'm new to shaders, but I think that if you wanted to make your own custom blend mode you had to pass additional image data to the shader each time you want to draw something which would be a hit on performance. Like I said I don't know much about drawing but maybe the built-in blend modes also give you a performance hit.
When you activate a shader and call love.graphics.draw on a drawable, guess what gets passed into it. :3
Yes, the thing that needs to be drawn, be it an image, a text object, a canvas, etc.

No need to manually supply it, since it's already there. This means that making (simpler) custom blendmodes is easy, and not at all taxing on the GPU.

The "normal" blendmodes shouldn't have a huge performance hit either, but i didn't look into what they did exactly, but i'm guessing that instead of defining a custom shader, they use the old gl blendfunctions and such. (in a constrained manner, though; if you want XOR or any other not available, then you'll have to go with shaders)
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.
UltraRPG
Prole
Posts: 5
Joined: Sat Sep 20, 2014 9:55 am

Re: Shockwave effect

Post by UltraRPG »

zorg wrote: Mon Mar 06, 2017 8:32 pm When you activate a shader and call love.graphics.draw on a drawable, guess what gets passed into it. :3
Yes, the thing that needs to be drawn, be it an image, a text object, a canvas, etc.
For example, I have a canvas with a tree drawn in it, let's call it TreeCanvas, and I want to draw an apple (ImageApple) onto it using a shader (SomeShader).

Code: Select all

love.graphics.setCanvas(TreeCanvas)
  love.graphics.setShader(SomeShader)
    love.graphics.draw(ImageApple)
  love.graphics.setShader()
love.graphics.setCanvas()
Will the shader get the TreeCanvas passed to it? Because you need two pictures for a blend mode to work. In this example, we need TreeCanvas and ImageApple to be passed into the shader.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 0 guests