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

New Map:enableFBORenderer to allow map effects to turn into nice overlays instead of plain quads.

Retch uses a much cooler map effect gfx
parent dc8f7f79
No related branches found
No related tags found
No related merge requests found
......@@ -98,6 +98,18 @@ function _M:setViewPort(x, y, w, h, tile_w, tile_h, fontname, fontsize, allow_ba
if otw ~= self.tile_w or oth ~= self.tile_h then print("[MAP] Reseting tiles caches") self:resetTiles() end
end
--- Setup a fbo/shader pair to display map effects
-- If not set this just uses plain quads
function _M:enableFBORenderer(shader)
if not shader or not core.display.fboSupportsTransparency then self.fbo = nil return end
self.fbo = core.display.newFBO(self.viewport.width, self.viewport.height)
if not self.fbo then return end
local Shader = require "engine.Shader"
self.fbo_shader = Shader.new(shader)
if not self.fbo_shader.shad then self.fbo = nil return end
end
--- Sets the map viewport padding, for scrolling purposes (defaults to 0)
-- Static
-- @param left left padding
......@@ -200,6 +212,8 @@ end
--- Serialization
function _M:save()
return class.save(self, {
fbo_shader = true,
fbo = true,
_check_entities = true,
_check_entities_store = true,
_map = true,
......@@ -521,14 +535,14 @@ end
-- @param y the coord where to start drawing, if null it uses self.display_y
-- @param nb_keyframes the number of keyframes elapsed since last draw
-- @param always_show tell the map code to force display unseed entities as remembered (used for smooth FOV shading)
function _M:display(x, y, nb_keyframe, always_show)
function _M:display(x, y, nb_keyframe, always_show, prevfbo)
nb_keyframes = nb_keyframes or 1
local ox, oy = self.display_x, self.display_y
self.display_x, self.display_y = x or self.display_x, y or self.display_y
self._map:toScreen(self.display_x, self.display_y, nb_keyframe, always_show, self.changed)
self:displayParticles(nb_keyframe)
self:displayEffects()
self:displayEffects(prevfbo)
self.display_x, self.display_y = ox, oy
......@@ -1012,20 +1026,45 @@ function _M:addEffect(src, x, y, duration, damtype, dam, radius, dir, angle, ove
end
--- Display the overlay effects, called by self:display()
function _M:displayEffects()
function _M:displayEffects(prevfbo)
local sx, sy = self._map:getScroll()
for i, e in ipairs(self.effects) do
-- Dont bother with obviously out of screen stuff
if e.overlay and e.x + e.radius >= self.mx and e.x - e.radius < self.mx + self.viewport.mwidth and e.y + e.radius >= self.my and e.y - e.radius < self.my + self.viewport.mheight then
local s = self.tilesEffects:get(e.overlay.display, e.overlay.color_r, e.overlay.color_g, e.overlay.color_b, e.overlay.color_br, e.overlay.color_bg, e.overlay.color_bb, e.overlay.image, e.overlay.alpha)
-- Now display each grids
for lx, ys in pairs(e.grids) do
for ly, _ in pairs(ys) do
if self.seens(lx, ly) then
s:toScreen(self.display_x + sx + (lx - self.mx) * self.tile_w * self.zoom, self.display_y + sy + (ly - self.my) * self.tile_h * self.zoom, self.tile_w * self.zoom, self.tile_h * self.zoom)
-- If we dont have a special fbo/shader or no shader image to use, just display with simple quads
if not self.fbo or not e.overlay.effect_shader then
-- Now display each grids
for lx, ys in pairs(e.grids) do
for ly, _ in pairs(ys) do
if self.seens(lx, ly) then
s:toScreen(self.display_x + sx + (lx - self.mx) * self.tile_w * self.zoom, self.display_y + sy + (ly - self.my) * self.tile_h * self.zoom, self.tile_w * self.zoom, self.tile_h * self.zoom)
end
end
end
-- We have a fbo/shader pair, so we display everything inside it and apply the shader to get nice borders and such
else
if not e.overlay.effect_shader_tex then
e.overlay.effect_shader_tex = Tiles:loadImage(e.overlay.effect_shader):glTexture()
end
self.fbo:use(true, 0, 0, 0, 0)
-- Now display each grids
for lx, ys in pairs(e.grids) do
for ly, _ in pairs(ys) do
if self.seens(lx, ly) then
s:toScreen((lx - self.mx) * self.tile_w * self.zoom, (ly - self.my) * self.tile_h * self.zoom, self.tile_w * self.zoom, self.tile_h * self.zoom)
end
end
end
self.fbo:use(false, prevfbo)
e.overlay.effect_shader_tex:bind(1, false)
self.fbo_shader.shad:use(true)
self.fbo_shader.shad:uniTileSize(self.tile_w, self.tile_h)
self.fbo_shader.shad:uniScrollOffset(0, 0)
self.fbo:toScreen(self.display_x + sx, self.display_y + sy, self.viewport.width, self.viewport.height, self.fbo_shader.shad, 1, 1, 1, 1, true)
self.fbo_shader.shad:use(false)
end
end
end
......
-- TE4 - T-Engine 4
-- Copyright (C) 2009 - 2014 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
require "engine.class"
local Entity = require "engine.Entity"
--- Describes a trap
module(..., package.seeall, class.inherit(Entity))
_M.display_on_seen = true
_M._no_save_fields.effect_shader_tex = true
function _M:init(t, no_default)
t.alpha = t.alpha or 100
t.display = t.display or ''
Entity.init(self, t, no_default)
end
......@@ -33,6 +33,7 @@ function _M:loadDefinition(file, env)
Particles = require("engine.Particles"),
Talents = self,
Map = require("engine.Map"),
MapEffect = require("engine.MapEffect"),
newTalent = function(t) self:newTalent(t) end,
newTalentType = function(t) self:newTalentType(t) end,
load = function(f) self:loadDefinition(f, getfenv(2)) end
......
......@@ -494,6 +494,7 @@ function _M:setupDisplayMode(reboot, mode)
self:setupMiniMap()
self:createFBOs()
Map:enableFBORenderer("target_fbo")
end
end
......@@ -1356,7 +1357,7 @@ function _M:displayMap(nb_keyframes)
if self.fbo then
self.fbo:use(true)
if self.level.data.background then self.level.data.background(self.level, 0, 0, nb_keyframes) end
map:display(0, 0, nb_keyframes, config.settings.tome.smooth_fov)
map:display(0, 0, nb_keyframes, config.settings.tome.smooth_fov, self.fbo)
if self.level.data.foreground then self.level.data.foreground(self.level, 0, 0, nb_keyframes) end
if self.level.data.weather_particle then self.state:displayWeather(self.level, self.level.data.weather_particle, nb_keyframes) end
if self.level.data.weather_shader then self.state:displayWeatherShader(self.level, self.level.data.weather_shader, map.display_x, map.display_y, nb_keyframes) end
......@@ -1376,7 +1377,7 @@ function _M:displayMap(nb_keyframes)
-- Basic display; no FBOs
else
if self.level.data.background then self.level.data.background(self.level, map.display_x, map.display_y, nb_keyframes) end
map:display(nil, nil, nb_keyframes, config.settings.tome.smooth_fov)
map:display(nil, nil, nb_keyframes, config.settings.tome.smooth_fov, nil)
if self.target then self.target:display(nil, nil, self.full_fbo, nb_keyframes) end
if self.level.data.foreground then self.level.data.foreground(self.level, map.display_x, map.display_y, nb_keyframes) end
if self.level.data.weather_particle then self.state:displayWeather(self.level, self.level.data.weather_particle, nb_keyframes) end
......
game/modules/tome/data/gfx/shockbolt/shader_images/retch_effect.png

52.2 KiB

......@@ -101,7 +101,7 @@ newTalent{
DamageType.RETCH, dam,
radius,
5, nil,
engine.Entity.new{alpha=100, display='', color_br=30, color_bg=180, color_bb=60},
MapEffect.new{color_br=30, color_bg=180, color_bb=60, effect_shader="shader_images/retch_effect.png"},
nil, self:spellFriendlyFire()
)
game:playSoundNear(self, "talents/cloud")
......
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