Hi everyone,
I thought I'd share this piece of code. The program simulates a strong impact that makes the screen shake and makes a shockwave propagate across the screen.
The image doesn't do it justice since it's a dynamic effect.
sync on
sync rate 100
randomize timer()
`Load background
load image "DistortionMap.bmp", 1
`Load effect
IK load effect "Shockwave.fx", 1
`Vector
r = make vector4(1)
`Maximum shockwave radius
#constant MaxShockRadius 2.0
IK set effect float 1, "ShockRadius", MaxShockRadius
ShockRadius# = MaxShockRadius
PropagationSpeed# = 0.015
`Screen position
global ScreenX# as float
global ScreenY# as float
do
if mouseclick() = 1 and ShockRadius# >= MaxShockRadius
`Initiate shockwave
set vector4 1, mousex() / 1.0 / screen width(), mousey() / 1.0 / screen height(), 0.0, 0.0
IK set effect vector4 1, "ShockCenter", 1
`Start shockwave
ShockRadius# = 0.0
endif
`Propagate shockwave
if ShockRadius# < MaxShockRadius
`Change radius
inc ShockRadius#, PropagationSpeed#
IK set effect float 1, "ShockRadius", ShockRadius#
`Shake screen
Amplitude# = 2.0 * (MaxShockRadius - ShockRadius#)^2
inc ScreenX#, Amplitude# * (-1.0 + (0.2 * rnd(10)))
inc ScreenY#, Amplitude# * (-1.0 + (0.2 * rnd(10)))
endif
`Paste image
ScreenX# = 0.96 * ScreenX#
ScreenY# = 0.96 * ScreenY#
IK paste image 1, ScreenX#, ScreenY#, 1
sync
loop
Click on the screen to activate shockwave.
Attached is the project and media (including the shader).
Cheers!
Sven B