Skip to content
Snippets Groups Projects
Commit afb7b7a1 authored by DarkGod's avatar DarkGod
Browse files

Particle systems can now define a global use_shader={type="foo"} to attach a shader

Particle systems can check availability of shaders
Particle systems can now also the background that is under them, allowing things like distortion effects
New distortion effect for the Repulsion Blast and Gravity Spike
parent bad8f10e
No related branches found
No related tags found
No related merge requests found
Showing
with 242 additions and 2 deletions
......@@ -625,6 +625,9 @@ function _M:instanciate(mod, name, new_game, no_reboot)
-- Turn based by default
core.game.setRealtime(0)
-- Disable particles FBO
core.particles.defineFramebuffer(nil)
-- FOV Shape
core.fov.set_algorithm("large_ass")
core.fov.set_permissiveness(0.01)
......
......@@ -57,6 +57,8 @@ function _M:loaded()
local _
setfenv(f, setmetatable(t, {__index=_G}))
_, _ , _, gl, _ = f()
if t.use_shader then self.shader = t.use_shader end
else error("unsupported particle type: "..type(self.def))
end
......
......@@ -1306,7 +1306,10 @@ function _M:setupCommands()
print("===============")
end end,
[{"_g","ctrl"}] = function() if config.settings.cheat then
game.player:takeHit(100, game.player)
local particle = engine.Particles.new("shader_square", 1, {life=600}, {type="fireball"})
particle.x, particle.y = game.player.x, game.player.y
game.level.map:addParticleEmitter(particle)
do return end
game:changeLevel(1, "stellar-system-shandral")
do return end
......
-- ToME - Tales of Maj'Eyal
-- Copyright (C) 2009, 2010, 2011, 2012, 2013 Nicolas Casalini
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- Nicolas Casalini "DarkGod"
-- darkgod@te4.org
local ray = {}
local tiles = math.ceil(math.sqrt(tx*tx+ty*ty))
local tx = tx * engine.Map.tile_w
local ty = ty * engine.Map.tile_h
ray.dir = math.atan2(ty, tx)
ray.size = math.sqrt(tx*tx+ty*ty)
return {
--system_rotation = 0, system_rotationv = rotation or 3,
generator = function()
local a = ray.dir
local r = rng.range(16, ray.size)
local ra = a + (rng.chance(2) and math.rad(-90) or math.rad(90))
local rr = rng.float(2, engine.Map.tile_w * 0.60)
local vel = rng.float(4, 8)
return {
life = 45 / vel,
size = rng.float(30, 45), sizev = -0.1, sizea = 0,
x = r * math.cos(a) + rr * math.cos(ra), xv = 0, xa = 0,
y = r * math.sin(a) + rr * math.sin(ra), yv = 0, ya = 0,
dir = ray.dir, dirv = 0, dira = 0,
vel = vel, velv = -0.1, vela = 0.01,
r = 1, rv = 0, ra = 0,
g = 1, gv = 0, ga = 0,
b = 1, bv = 0, ba = 0,
a = 1, av = 0, aa = 0,
}
end, },
function(self)
self.nb = (self.nb or 0) + 1
if self.nb < 6 then
self.ps:emit(1*tiles)
end
end,
45*1*tiles, "particles_images/distort_singularity"
\ No newline at end of file
......@@ -24,6 +24,46 @@ local radius = radius or 6
dir = math.deg(math.atan2(ty, tx))
--------------------------------------------------------------------------------------
-- Advanced shaders
--------------------------------------------------------------------------------------
if core.shader.active(4) then
use_shader = {type="distort", power=0.06, power_time=1000000, blacken=30}
base_size = 64
local nb = 0
local life=16
local sizev=2*64*radius / life
return {
system_rotation = dir, system_rotationv = 0,
generator = function()
return {
trail = 0,
life = life or 32,
size = 10, sizev = sizev or 0, sizea = 0,
x = 0, xv = 0, xa = 0,
y = 0, yv = 0, ya = 0,
dir = 0, dirv = dirv, dira = 0,
vel = 0, velv = 0, vela = 0,
r = 1, rv = 0, ra = 0,
g = 1, gv = 0, ga = 0,
b = 1, bv = 0, ba = 0,
a = 1, av = 0, aa = 0,
}
end, },
function(self)
if nb < 1 then self.ps:emit(1) nb = nb + 1 end
end,
1, "particles_images/distort_wave_directional"
--------------------------------------------------------------------------------------
-- Default
--------------------------------------------------------------------------------------
else
return { generator = function()
local sradius = (radius + 0.5) * (engine.Map.tile_w + engine.Map.tile_h) / 2
local ad = rng.float(dir - spread, dir + spread)
......@@ -60,3 +100,5 @@ function(self)
end,
30*radius*7*12,
"particle_cloud"
end
\ No newline at end of file
......@@ -17,10 +17,48 @@
-- Nicolas Casalini "DarkGod"
-- darkgod@te4.org
--------------------------------------------------------------------------------------
-- Advanced shaders
--------------------------------------------------------------------------------------
if core.shader.active(4) then
use_shader = {type="distort"}
base_size = 64
local nb = 0
local size=2*radius*64
local sizev=-radius*8
local life=16
local rotation=22
return {
system_rotation = 0, system_rotationv = rotation or 0,
generator = function()
return {
trail = 0,
life = life or 32,
size = size or 64, sizev = sizev or 0, sizea = 0,
x = 0, xv = 0, xa = 0,
y = 0, yv = 0, ya = 0,
dir = 0, dirv = dirv, dira = 0,
vel = 0, velv = 0, vela = 0,
r = 1, rv = 0, ra = 0,
g = 1, gv = 0, ga = 0,
b = 1, bv = 0, ba = 0,
a = 1, av = 0, aa = 0,
}
end, },
function(self)
if nb < 1 then self.ps:emit(1) nb = nb + 1 end
end,
1, "particles_images/distort_wave2"
--------------------------------------------------------------------------------------
-- Default
--------------------------------------------------------------------------------------
else
local nb = 0
return { generator = function()
local radius = radius
......@@ -64,4 +102,5 @@ function(self)
nb = nb + 1
end
end,
5*radius*266
\ No newline at end of file
5*radius*266
end
-- ToME - Tales of Maj'Eyal
-- Copyright (C) 2009, 2010, 2011, 2012, 2013 Nicolas Casalini
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- Nicolas Casalini "DarkGod"
-- darkgod@te4.org
base_size = 64
local nb = 0
return {
system_rotation = 0, system_rotationv = rotation or 0,
generator = function()
return {
trail = 0,
life = life or 32,
size = size or 64, sizev = sizev or 0, sizea = 0,
x = 0, xv = 0, xa = 0,
y = 0, yv = 0, ya = 0,
dir = 0, dirv = dirv, dira = 0,
vel = 0, velv = 0, vela = 0,
r = 1, rv = 0, ra = 0,
g = 1, gv = 0, ga = 0,
b = 1, bv = 0, ba = 0,
a = 1, av = 0, aa = 0,
}
end, },
function(self)
if nb < 1 then self.ps:emit(1) nb = nb + 1 end
end,
1, "particles_images/"..(image or "square")
\ No newline at end of file
game/modules/tome/data/gfx/particles_images/distort.png

10.5 KiB

game/modules/tome/data/gfx/particles_images/distort_shield.png

4.62 KiB

game/modules/tome/data/gfx/particles_images/distort_singularity.png

10.4 KiB

game/modules/tome/data/gfx/particles_images/distort_singularity2.png

9.95 KiB

game/modules/tome/data/gfx/particles_images/distort_singularity3.png

9.16 KiB

game/modules/tome/data/gfx/particles_images/distort_singularity4.png

8.7 KiB

game/modules/tome/data/gfx/particles_images/distort_wave.png

7.34 KiB

game/modules/tome/data/gfx/particles_images/distort_wave2.png

9.8 KiB

game/modules/tome/data/gfx/particles_images/distort_wave3.png

15.8 KiB

game/modules/tome/data/gfx/particles_images/distort_wave_directional.png

4.17 KiB

game/modules/tome/data/gfx/particles_images/distort_wave_directional2.png

3.53 KiB

uniform sampler2D tex;
uniform float tick;
uniform sampler2D mainfbo;
uniform vec2 texSize;
uniform float power;
uniform float power_time;
uniform float blacken;
void main(void)
{
float distortionPower = power * cos(tick / power_time);
vec3 distortionColor = texture2D(tex, gl_TexCoord[0].xy);
vec2 distortionOffset = vec2(distortionColor.r - 0.5f, distortionColor.g - 0.5f) * distortionPower;
gl_FragColor = texture2D(mainfbo, gl_FragCoord.xy / texSize.xy + distortionOffset.xy) * (1.0 - length(distortionOffset) * blacken);
}
-- ToME - Tales of Maj'Eyal
-- Copyright (C) 2009, 2010, 2011, 2012, 2013 Nicolas Casalini
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- Nicolas Casalini "DarkGod"
-- darkgod@te4.org
return {
frag = "distort",
vert = nil,
args = {
tex = { texture = 0 },
mainfbo = { texture = 1 },
power = power or 0.06,
power_time = power_time or 100,
blacken = blacken or 10,
},
clone = false,
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment