diff --git a/game/engines/default/engine/Entity.lua b/game/engines/default/engine/Entity.lua index 2e452b12383ad7f1b280bc5d16167dcafb5b66d1..8c4697774704a41cd86d0e9706d187ea3eed2c5c 100644 --- a/game/engines/default/engine/Entity.lua +++ b/game/engines/default/engine/Entity.lua @@ -201,11 +201,13 @@ function _M:removeParticles(ps) end --- Get the particle emitters of this entity -function _M:getParticlesList() +function _M:getParticlesList(back) local ps = {} for e, _ in pairs(self.__particles) do - e:checkDisplay() - ps[#ps+1] = e + if (not back and not e.toback) or (back and e.toback) then + e:checkDisplay() + ps[#ps+1] = e + end end return ps end diff --git a/game/modules/tome/class/Actor.lua b/game/modules/tome/class/Actor.lua index b4cc2da57608f9a5b7766b689a07384954b6b042..19dc652a3273a7dbfe941bc8e8c97ef78069b2e2 100644 --- a/game/modules/tome/class/Actor.lua +++ b/game/modules/tome/class/Actor.lua @@ -18,7 +18,7 @@ -- darkgod@te4.org require "engine.class" -require "engine.Actor" +local Actor = require "engine.Actor" require "engine.Autolevel" require "engine.interface.ActorInventory" require "engine.interface.ActorTemporaryEffects" @@ -836,11 +836,30 @@ function _M:setupMinimapInfo(mo, map) end end +function _M:makeMapObject(tiles, idx) + local mo, z, lastmo = Actor.makeMapObject(self, tiles, idx) + + if idx == 1 and mo then + if mo and mo:isValid() then return mo, z, lasmo end + + local submo = core.map.newObject(self.uid, 1, self:check("display_on_seen"), self:check("display_on_remember"), self:check("display_on_unknown"), self:check("display_x") or 0, self:check("display_y") or 0, self:check("display_w") or 1, self:check("display_h") or 1, self:check("display_scale") or 1) + local tex, texx, texy, pos_x, pos_y = tiles:get("", 0, 0, 0, 0, 0, 0, "invis.png", false, false, true) + submo:texture(0, tex, false, texx, texy, pos_x, pos_y) + submo:chain(mo) + if lastmo == mo then lastmo = submo end + mo = submo + self._mo = mo + end + + return mo, z, lastmo +end + --- Attach or remove a display callback -- Defines particles to display function _M:defineDisplayCallback() if not self._mo then return end + local backps = self:getParticlesList(true) local ps = self:getParticlesList() local f_self = nil @@ -942,15 +961,30 @@ function _M:defineDisplayCallback() end end + local function backparticles(x, y, w, h, zoom, on_map) + local e + local dy = 0 + if h > w then dy = (h - w) / 2 end + for i = 1, #backps do + e = backps[i] + e:checkDisplay() + if e.ps:isAlive() then e.ps:toScreen(x + w / 2, y + dy + h / 2, true, w / (game.level and game.level.map.tile_w or w)) + else self:removeParticles(e) + end + end + end + if self._mo == self._last_mo or not self._last_mo then self._mo:displayCallback(function(x, y, w, h, zoom, on_map, tlx, tly) tactical(tlx or x, tly or y, w, h, zoom, on_map) + backparticles(x, y, w, h, zoom, on_map) particles(x, y, w, h, zoom, on_map) return true end) else self._mo:displayCallback(function(x, y, w, h, zoom, on_map, tlx, tly) tactical(tlx or x, tly or y, w, h, zoom, on_map) + backparticles(x, y, w, h, zoom, on_map) return true end) self._last_mo:displayCallback(function(x, y, w, h, zoom, on_map) diff --git a/game/modules/tome/data/gfx/particles/shader_wings.lua b/game/modules/tome/data/gfx/particles/shader_wings.lua new file mode 100644 index 0000000000000000000000000000000000000000..3cbfe1f6a95f0e141e2b1800f22e8c19d3aa05b4 --- /dev/null +++ b/game/modules/tome/data/gfx/particles/shader_wings.lua @@ -0,0 +1,49 @@ +-- 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 + +use_shader = {type="flamewings"} +base_size = 32 + +local r = 1 +local g = 1 +local b = 1 +local a = 1 + +return { generator = function() + return { + trail = 0, + life = 10, + size = 64 * (size_factor or 1), sizev = 0, sizea = 0, + + x = 0, xv = 0, xa = 0, + y = -20, yv = 0, ya = 0, + dir = 0, dirv = dirv, dira = 0, + vel = 0, velv = 0, vela = 0, + + r = r, rv = 0, ra = 0, + g = g, gv = 0, ga = 0, + b = b, bv = 0, ba = 0, + a = a, av = -0.02, aa = 0.005, + } +end, }, +function(self) + self.ps:emit(1) +end, +1, +"particles_images/"..(img or "wings") diff --git a/game/modules/tome/data/gfx/particles_images/wings.png b/game/modules/tome/data/gfx/particles_images/wings.png new file mode 100644 index 0000000000000000000000000000000000000000..2c018bcc154da8608e93f4cbb545b521483ba281 Binary files /dev/null and b/game/modules/tome/data/gfx/particles_images/wings.png differ diff --git a/game/modules/tome/data/gfx/shaders/flamewings.frag b/game/modules/tome/data/gfx/shaders/flamewings.frag new file mode 100644 index 0000000000000000000000000000000000000000..f767b0333aaef3430ba3d540ea8eb5ecc83550f7 --- /dev/null +++ b/game/modules/tome/data/gfx/shaders/flamewings.frag @@ -0,0 +1,200 @@ +uniform sampler2D tex; +uniform float tick; +uniform float aadjust; +uniform vec3 color; +uniform float time_factor; +uniform float tick_start; + +uniform float ellipsoidalFactor = 1.7; //1 is perfect circle, >1 is ellipsoidal +uniform float oscillationSpeed = 0.0; //oscillation between ellipsoidal and spherical form + +vec4 permute( vec4 x ) { + return mod( ( ( x * 34.0 ) + 1.0 ) * x, 289.0 ); +} + +vec4 taylorInvSqrt( vec4 r ) { + + return 1.79284291400159 - 0.85373472095314 * r; + +} + +float snoise( vec3 v ) { + + const vec2 C = vec2( 1.0 / 6.0, 1.0 / 3.0 ); + const vec4 D = vec4( 0.0, 0.5, 1.0, 2.0 ); + + // First corner + + vec3 i = floor( v + dot( v, C.yyy ) ); + vec3 x0 = v - i + dot( i, C.xxx ); + + // Other corners + + vec3 g = step( x0.yzx, x0.xyz ); + vec3 l = 1.0 - g; + vec3 i1 = min( g.xyz, l.zxy ); + vec3 i2 = max( g.xyz, l.zxy ); + + vec3 x1 = x0 - i1 + 1.0 * C.xxx; + vec3 x2 = x0 - i2 + 2.0 * C.xxx; + vec3 x3 = x0 - 1. + 3.0 * C.xxx; + + // Permutations + + i = mod( i, 289.0 ); + vec4 p = permute( permute( permute( + i.z + vec4( 0.0, i1.z, i2.z, 1.0 ) ) + + i.y + vec4( 0.0, i1.y, i2.y, 1.0 ) ) + + i.x + vec4( 0.0, i1.x, i2.x, 1.0 ) ); + + // Gradients + // ( N*N points uniformly over a square, mapped onto an octahedron.) + + float n_ = 1.0 / 7.0; // N=7 + + vec3 ns = n_ * D.wyz - D.xzx; + + vec4 j = p - 49.0 * floor( p * ns.z *ns.z ); // mod(p,N*N) + + vec4 x_ = floor( j * ns.z ); + vec4 y_ = floor( j - 7.0 * x_ ); // mod(j,N) + + vec4 x = x_ *ns.x + ns.yyyy; + vec4 y = y_ *ns.x + ns.yyyy; + vec4 h = 1.0 - abs( x ) - abs( y ); + + vec4 b0 = vec4( x.xy, y.xy ); + vec4 b1 = vec4( x.zw, y.zw ); + + + vec4 s0 = floor( b0 ) * 2.0 + 1.0; + vec4 s1 = floor( b1 ) * 2.0 + 1.0; + vec4 sh = -step( h, vec4( 0.0 ) ); + + vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy; + vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww; + + vec3 p0 = vec3( a0.xy, h.x ); + vec3 p1 = vec3( a0.zw, h.y ); + vec3 p2 = vec3( a1.xy, h.z ); + vec3 p3 = vec3( a1.zw, h.w ); + + // Normalise gradients + + vec4 norm = taylorInvSqrt( vec4( dot( p0, p0 ), dot( p1, p1 ), dot( p2, p2 ), dot( p3, p3 ) ) ); + p0 *= norm.x; + p1 *= norm.y; + p2 *= norm.z; + p3 *= norm.w; + + // Mix final noise value + + vec4 m = max( 0.6 - vec4( dot( x0, x0 ), dot( x1, x1 ), dot( x2, x2 ), dot( x3, x3 ) ), 0.0 ); + m = m * m; + return 42.0 * dot( m*m, vec4( dot( p0, x0 ), dot( p1, x1 ), + dot( p2, x2 ), dot( p3, x3 ) ) ); + +} + +vec2 snoise2(vec3 pos) +{ + return vec2(snoise(pos), snoise(pos + vec3(0.0, 0.0, 1.0))); +} + +vec2 GetFireDelta(float currTime, vec2 pos, float freqMult, float stretchMult) +{ + //firewall + vec2 delta = vec2(0.0, 0.0); +// pos.y += (1.0 - pos.y) * 0.5; + //pos.y += 0.5; + pos.y /= stretchMult; + pos *= freqMult; + pos.y += currTime * 3.0; +// pos.y -= currTime * 3.0; + delta += vec2(0.0, snoise(vec3(pos * 1.0, currTime * 0.5)) * 1.5); + delta += vec2(0.0, snoise(vec3(pos * 2.0, currTime * 1.0)) * 1.5); + delta += vec2(0.0, snoise(vec3(pos * 4.0, currTime * 2.0)) * 1.5); + delta += vec2(0.0, snoise(vec3(pos * 8.0, currTime * 4.0)) * 1.5); + delta += vec2(0.0, snoise(vec3(pos * 16.0, currTime * 8.0)) * 0.5); + /*delta += vec2(0.0, snoise(vec3(pos * 2.0, 1*currTime * 4.0)) * 0.4); + delta += vec2(0.0, snoise(vec3(pos * 8.0, 1*currTime * 16.0)) * 0.8); + delta += vec2(0.0, snoise(vec3(pos * 16.0, 1*currTime * 32.0)) * 0.4);*/ + return delta; +} + +vec4 GetFireColor(float currTime, vec2 pos, float freqMult, float stretchMult, float ampMult) +{ + if(pos.x < 0.0 || pos.x > 1.0 || pos.y < 0.0 || pos.y > 1.0) return vec4(0.0, 0.0, 0.0, 0.0); + /*if(mod(pos.x, 0.1) < 0.05 ^ mod(pos.y, 0.1) < 0.05) + return vec4(pos.x, pos.y, 0, 1); + else + return vec4(0, 0, 0, 1);*/ + vec2 delta = GetFireDelta(currTime, pos, freqMult, stretchMult); + delta *= min(1.0, max(0.0, 1.0 * (1.0 - pos.y))); + delta *= min(1.0, max(0.0, 1.0 * (0.0 + pos.y))); + vec2 displacedPoint = pos + delta * ampMult; + displacedPoint.y = min(0.99, displacedPoint.y); + displacedPoint.y = max(0.01, displacedPoint.y); + return texture2D(tex, displacedPoint); +} + +void main(void) +{ + vec2 pos = gl_TexCoord[0].xy; + pos.x = 0.5 + (pos.x - 0.5) * ellipsoidalFactor; + pos = vec2(0.5, 0.5) + (pos - vec2(0.5, 0.5)) * 1.1; + + float foldRatio = 1.0; +// float foldRatio = max(0.0, min(1.0, (tick - tick_start) / time_factor * 0.5)); +// foldRatio = (1.0 + sin(tick / time_factor * 20.0)) * 0.5; + foldRatio *= 0.95 + 0.05 * sin(tick / time_factor * 15.0); + + float radius = 0.25 * (foldRatio * 0.5 + 0.5); + vec2 center = vec2(0.5, 0.85 - radius); + float timeShift = 0.0; + if(pos.x > 0.5) + timeShift = 100; + + + if(length(pos - center) < radius) + { + vec2 delta = pos - center; + float pi = 3.141592; + float ang = atan(delta.x, delta.y); + + vec2 polarPoint = vec2(abs(ang) / pi, radius - length(delta)); + vec2 planarPoint = vec2((polarPoint.x - 0.07) / (0.70 - (1.0 - foldRatio) * 0.3), polarPoint.y * 24.0); + planarPoint.x -= (0.0 + planarPoint.x) * planarPoint.y * 0.2; + planarPoint.y += pow((0.0 + planarPoint.x), 10.0) * planarPoint.y * 10.0; + + planarPoint.y = 1.0 - planarPoint.y; + gl_FragColor = GetFireColor(timeShift + tick / time_factor, planarPoint, 4.0, 8.0, 1.0); + }else + { + + vec2 delta = pos - center; + float pi = 3.141592; + float ang = atan(delta.x, delta.y); + + vec2 polarPoint = vec2(abs(ang) / pi, length(delta) - radius); + + vec2 planarPoint = vec2((polarPoint.x - 0.07) / (0.70 - (1.0 - foldRatio) * 0.3), polarPoint.y * 2.5); + /* planarPoint.x -= (1.0 - planarPoint.x) * planarPoint.y * 0.7; + planarPoint.x -= (0.0 + planarPoint.x) * planarPoint.y * 0.2; + planarPoint.y += pow((0.0 + planarPoint.x) * planarPoint.y, 3.0) * 7.9;*/ + planarPoint.x -= (1.0 - planarPoint.x) * planarPoint.y * 0.8; + planarPoint.x -= (0.0 + planarPoint.x) * planarPoint.y * 0.3 * (foldRatio * 3.0 - 2.0); + planarPoint.y += pow((1.0 - planarPoint.x), 7.0) * planarPoint.y * 2.7; + + planarPoint.y = 1.0 - planarPoint.y; + + gl_FragColor = GetFireColor(timeShift + tick / time_factor, planarPoint, 2.0, 4.0, 1.0); + + float antialiasingCoef = 40.0; + gl_FragColor.a *= min(1.0, max(0.0, planarPoint.x * antialiasingCoef)); + //gl_FragColor.a *= min(1.0, max(0.0, planarPoint.y * antialiasingCoef)); + gl_FragColor.a *= min(1.0, max(0.0, (1.0 - planarPoint.x) * antialiasingCoef)); + //gl_FragColor.a *= min(1.0, max(0.0, (1.0 - planarPoint.y) * antialiasingCoef)); + } + gl_FragColor.a *= 1.0 - pow(1.0 - foldRatio, 3.0); +} diff --git a/game/modules/tome/data/gfx/shaders/flamewings.lua b/game/modules/tome/data/gfx/shaders/flamewings.lua new file mode 100644 index 0000000000000000000000000000000000000000..5114faecfe82af0ec60bc4f10491fabbc9e67c21 --- /dev/null +++ b/game/modules/tome/data/gfx/shaders/flamewings.lua @@ -0,0 +1,32 @@ +-- 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 = "flamewings", + vert = nil, + args = { + tex = { texture = 0 }, + tick_start = core.game.getTime(), + time_factor = 6000, + ellipsoidalFactor = 1.7, --1 is perfect circle, >1 is ellipsoidal + oscillationSpeed = 0.0, --oscillation between ellipsoidal and spherical form + growRatio = 1.0, + }, + clone = false, +} diff --git a/game/modules/tome/data/talents/spells/wildfire.lua b/game/modules/tome/data/talents/spells/wildfire.lua index 55e3d536dc3703faf81efa4f6f234c366ed9e0d0..ab983ffcb952b841372100e9f9ecf3e897151804 100644 --- a/game/modules/tome/data/talents/spells/wildfire.lua +++ b/game/modules/tome/data/talents/spells/wildfire.lua @@ -124,7 +124,10 @@ newTalent{ local particle if core.shader.active(4) then - particle = self:addParticles(Particles.new("shader_ring_rotating", 1, {radius=1.1}, {type="flames", hide_center=0, xy={self.x, self.y}})) + local p = Particles.new("shader_wings", 1) + p.toback = true + particle = self:addParticles(p) +-- particle = self:addParticles(Particles.new("shader_ring_rotating", 1, {radius=1.1}, {type="flames", hide_center=0, xy={self.x, self.y}})) else particle = self:addParticles(Particles.new("wildfire", 1)) end