Commit a00429bd4683708e19be491f58bdf9e2f64938a7

Authored by DarkGod
1 parent 0360b756

Added an UI option to sharpen the map display, as requested by some

... ... @@ -634,6 +634,7 @@ function _M:createFBOs()
634 634 timestop = Shader.new("main_fbo/timestop"),
635 635 line_grids = Shader.new("main_fbo/line_grids"),
636 636 gestures = Shader.new("main_fbo/gestures"),
  637 + sharpen = Shader.new("main_fbo/sharpen"),
637 638 }
638 639 self.posteffects_use = { self.fbo_shader.shad }
639 640 if not self.fbo_shader.shad then self.fbo = nil self.fbo_shader = nil end
... ...
... ... @@ -509,6 +509,12 @@ function _M:updateMainShader()
509 509 pf.timestop.shad:paramNumber("tick_start", core.game.getTime())
510 510 end
511 511
  512 + -- Sharpen shader
  513 + if config.settings.tome.sharpen_display and config.settings.tome.sharpen_display > 1 then
  514 + effects[pf.sharpen.shad] = true
  515 + pf.sharpen.shad:paramNumber("sharpen_power", config.settings.tome.sharpen_display)
  516 + end
  517 +
512 518 game.posteffects_use = table.keys(effects)
513 519 game.posteffects_use[#game.posteffects_use+1] = game.fbo_shader.shad
514 520 end
... ...
  1 +uniform float sharpen_power;
  2 +uniform vec2 texSize;
  3 +uniform sampler2D tex;
  4 +
  5 +void main(void) {
  6 + float step_w = 1.0 / texSize.x;
  7 + float step_h = 1.0 / texSize.y;
  8 +
  9 + float kernel[9];
  10 + vec2 offset[9];
  11 +
  12 + offset[0] = vec2(-step_w, -step_h);
  13 + offset[1] = vec2(0.0, -step_h);
  14 + offset[2] = vec2(step_w, -step_h);
  15 + offset[3] = vec2(-step_w, 0.0);
  16 + offset[4] = vec2(0.0, 0.0);
  17 + offset[5] = vec2(step_w, 0.0);
  18 + offset[6] = vec2(-step_w, step_h);
  19 + offset[7] = vec2(0.0, step_h);
  20 + offset[8] = vec2(step_w, step_h);
  21 +
  22 +
  23 + /* SHARPEN KERNEL
  24 + 0 -1 0
  25 + -1 5 -1
  26 + 0 -1 0
  27 + */
  28 +
  29 + // float power = 2.0;
  30 + float rest = -(sharpen_power - 1.0) / 4.0;
  31 +
  32 + kernel[0] = 0.;
  33 + kernel[1] = rest;
  34 + kernel[2] = 0.;
  35 + kernel[3] = rest;
  36 + kernel[4] = sharpen_power;
  37 + kernel[5] = rest;
  38 + kernel[6] = 0.;
  39 + kernel[7] = rest;
  40 + kernel[8] = 0.;
  41 +
  42 + vec4 sum = vec4(0.0);
  43 + int i;
  44 +
  45 + for (i = 0; i < 9; i++) {
  46 + vec4 color = texture2D(tex, gl_TexCoord[0].xy + offset[i]);
  47 + sum += color * kernel[i];
  48 + }
  49 + gl_FragColor = sum;
  50 +}
... ...
  1 +-- ToME - Tales of Maj'Eyal
  2 +-- Copyright (C) 2009 - 2018 Nicolas Casalini
  3 +--
  4 +-- This program is free software: you can redistribute it and/or modify
  5 +-- it under the terms of the GNU General Public License as published by
  6 +-- the Free Software Foundation, either version 3 of the License, or
  7 +-- (at your option) any later version.
  8 +--
  9 +-- This program is distributed in the hope that it will be useful,
  10 +-- but WITHOUT ANY WARRANTY; without even the implied warranty of
  11 +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12 +-- GNU General Public License for more details.
  13 +--
  14 +-- You should have received a copy of the GNU General Public License
  15 +-- along with this program. If not, see <http://www.gnu.org/licenses/>.
  16 +--
  17 +-- Nicolas Casalini "DarkGod"
  18 +-- darkgod@te4.org
  19 +
  20 +return {
  21 + frag = "main_fbo/sharpen",
  22 + vert = nil,
  23 + args = {
  24 + tex = { texture = 0 },
  25 + sharpen_power = 3,
  26 + },
  27 + clone = false,
  28 + permanent = true,
  29 +}
... ...
... ... @@ -23,6 +23,7 @@ local TreeList = require "engine.ui.TreeList"
23 23 local Textzone = require "engine.ui.Textzone"
24 24 local Separator = require "engine.ui.Separator"
25 25 local GetQuantity = require "engine.dialogs.GetQuantity"
  26 +local GetQuantitySlider = require "engine.dialogs.GetQuantitySlider"
26 27 local Tabs = require "engine.ui.Tabs"
27 28 local GraphicMode = require("mod.dialogs.GraphicMode")
28 29 local FontPackage = require "engine.FontPackage"
... ... @@ -439,6 +440,19 @@ function _M:generateListUi()
439 440 self.c_list:drawItem(item)
440 441 end,}
441 442
  443 + local zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text=string.toTString"Sharpen Visuals, set to 0 to disable.#WHITE#"}
  444 + list[#list+1] = { zone=zone, name=string.toTString"#GOLD##{bold}#Sharpen Visuals#WHITE##{normal}#", status=function(item)
  445 + return tostring((config.settings.tome.sharpen_display or 0))
  446 + end, fct=function(item)
  447 + game:registerDialog(GetQuantitySlider.new("Enter Sharpen Power", "From 0(disable) to 10", math.floor(config.settings.tome.sharpen_display), 0, 10, 1, function(qty)
  448 + qty = util.bound(qty, 0, 10)
  449 + game:saveSettings("tome.sharpen_display", ("tome.sharpen_display = %f\n"):format(qty))
  450 + config.settings.tome.sharpen_display = qty
  451 + self.c_list:drawItem(item)
  452 + if self:isTome() and game.player then game.player:updateMainShader() end
  453 + end))
  454 + end,}
  455 +
442 456 self.list = list
443 457 end
444 458
... ...