From 430245f2fa98f89f7a61e1c16cb2e8cb6f282431 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Pinochet?= Date: Tue, 31 Oct 2017 13:01:10 -0300 Subject: [PATCH 01/22] Fixed missing bracket on README. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8972099..21a0600 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ is equivalent to the above: ```lua chain.parameters = { glow = {strenght = 10}, - crt = {distortionFactor = {1.06, 1.065}, + crt = {distortionFactor = {1.06, 1.065}}, } ``` From e315dbe79145e1451bbed6808f49daf602b305fe Mon Sep 17 00:00:00 2001 From: Andrew Minnich Date: Wed, 1 Nov 2017 13:15:04 -0400 Subject: [PATCH 02/22] fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 21a0600..13a5574 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ is equivalent to the above: ```lua chain.parameters = { - glow = {strenght = 10}, + glow = {strength = 10}, crt = {distortionFactor = {1.06, 1.065}}, } ``` From 549f1777769c14331360df711478e14b7cad41b4 Mon Sep 17 00:00:00 2001 From: Matthias Richter Date: Sun, 19 Nov 2017 21:49:00 +0100 Subject: [PATCH 03/22] Initially use only front buffer as canvas (issue #32) --- init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.lua b/init.lua index 0f0c3a5..710cc4d 100644 --- a/init.lua +++ b/init.lua @@ -52,7 +52,7 @@ moonshine.chain = function(effect) local color = {love.graphics.getColor()} -- draw scene to front buffer - love.graphics.setCanvas(buffer()) + love.graphics.setCanvas((buffer())) -- parens are needed: take only front buffer love.graphics.clear() func(...) From 3a7ca1b2260286cfce7897d8be840f8dd895e62a Mon Sep 17 00:00:00 2001 From: vrld Date: Mon, 20 Nov 2017 13:50:12 +0100 Subject: [PATCH 04/22] Fix #33 - Clear background with correct color --- init.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/init.lua b/init.lua index 710cc4d..33381f8 100644 --- a/init.lua +++ b/init.lua @@ -49,18 +49,18 @@ moonshine.chain = function(effect) -- save state local canvas = love.graphics.getCanvas() local shader = love.graphics.getShader() - local color = {love.graphics.getColor()} + local fg_r, fg_g, fg_b, fg_a = love.graphics.getColor() -- draw scene to front buffer love.graphics.setCanvas((buffer())) -- parens are needed: take only front buffer - love.graphics.clear() + love.graphics.clear(love.graphics.getBackgroundColor()) func(...) -- save more state local blendmode = love.graphics.getBlendMode() -- process all shaders - love.graphics.setColor(color) + love.graphics.setColor(fg_r, fg_g, fg_b, fg_a) love.graphics.setBlendMode("alpha", "premultiplied") for _,e in ipairs(chain) do (e.draw or moonshine.draw_shader)(buffer, e.shader) From d4e5f6755a1ffb9ac06e72b6bdb096af0b18a96f Mon Sep 17 00:00:00 2001 From: Matthias Richter Date: Sun, 8 Apr 2018 15:38:06 +0200 Subject: [PATCH 05/22] Fix #38: Way to add/remove effects --- README.md | 18 ++++++++++++++++++ init.lua | 20 ++++++++++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 13a5574..36d3bfa 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,24 @@ will be left untouched. Similar to chain creation, `chain(func, ...)` is an alias to the more verbose `chain.draw(func, ...)`. +### Temporarily disabling effects + +You can disable effects in a chain by using `chain.disable(names...)` and +`chain.enable(names...)`. +For example, + +```lua +effect = moonshine(moonshine.effects.boxblur) + .chain(moonshine.effects.filmgrain) + .chain(moonshine.effects.vignette) +effect.disable("boxblur", "filmgrain") +effect.enable("filmgrain") +``` + +would first disable the boxblur and filmgrain effect, and then enable the +filmgrain again. +Note that the effects are still in the chain, they are only not drawn. + ### Is this efficient? Of course, using moonshine is not as efficient as writing your own shader that diff --git a/init.lua b/init.lua index 33381f8..b5c140f 100644 --- a/init.lua +++ b/init.lua @@ -43,8 +43,8 @@ moonshine.chain = function(effect) return front, back end + local disabled = {} -- set of disabled effects local chain = {} - chain.draw = function(func, ...) -- save state local canvas = love.graphics.getCanvas() @@ -63,7 +63,9 @@ moonshine.chain = function(effect) love.graphics.setColor(fg_r, fg_g, fg_b, fg_a) love.graphics.setBlendMode("alpha", "premultiplied") for _,e in ipairs(chain) do - (e.draw or moonshine.draw_shader)(buffer, e.shader) + if not disabled[e.name] then + (e.draw or moonshine.draw_shader)(buffer, e.shader) + end end -- present result @@ -87,6 +89,20 @@ moonshine.chain = function(effect) end chain.chain = chain.next + chain.disable = function(name, ...) + if name then + disabled[name] = name + return chain.disable(...) + end + end + + chain.enable = function(name, ...) + if name then + disabled[name] = nil + return chain.enable(...) + end + end + setmetatable(chain, { __call = function(_, ...) return chain.draw(...) end, __index = function(_,k) From 07974ceb30437826113956d544e512967389023e Mon Sep 17 00:00:00 2001 From: Matthias Richter Date: Sun, 8 Apr 2018 15:45:17 +0200 Subject: [PATCH 06/22] From #39: explicit type conversion in godsray shader --- godsray.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/godsray.lua b/godsray.lua index 2c3cfc7..6c9f74a 100644 --- a/godsray.lua +++ b/godsray.lua @@ -52,7 +52,7 @@ return function(moonshine) number illumination = decay; vec4 c = vec4(.0, .0, .0, 1.0); - for (int i = 0; i < samples; ++i) { + for (int i = 0; i < int(samples); ++i) { uv -= offset; c += Texel(tex, uv) * illumination * weight; illumination *= decay; From ad7165088216ef0216f1a5ed988d13672f4725a6 Mon Sep 17 00:00:00 2001 From: Matthias Richter Date: Sun, 8 Apr 2018 16:07:34 +0200 Subject: [PATCH 07/22] Fix #36 - Make canvas resizable Add width and height parameters to chain constructor. Add chain.resize(w, h) as Positive07 suggested. --- README.md | 14 ++++++++++++++ init.lua | 15 +++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 36d3bfa..94b1d1f 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,20 @@ would first disable the boxblur and filmgrain effect, and then enable the filmgrain again. Note that the effects are still in the chain, they are only not drawn. +### Canvas size + +You can change the size of the internal canvas, for example when the window was +resized, by calling `chain.resize(width, height)`. +Do this anytime you want, but best not during `chain.draw()`. + +You can also specify the initial canvas size by starting the chain like this: + +```lua +effect = moonshine(400,300, moonshine.effects.vignette) +``` + +That is, you specify the width and height before the first effect in the chain. + ### Is this efficient? Of course, using moonshine is not as efficient as writing your own shader that diff --git a/init.lua b/init.lua index b5c140f..6639e99 100644 --- a/init.lua +++ b/init.lua @@ -36,8 +36,14 @@ moonshine.draw_shader = function(buffer, shader) love.graphics.draw(back) end -moonshine.chain = function(effect) - local front, back = love.graphics.newCanvas(), love.graphics.newCanvas() +moonshine.chain = function(w,h,effect) + -- called as moonshine.chain(effect)' + if h == nil then + effect, w,h = w, love.window.getMode() + end + assert(effect ~= nil, "No effect") + + local front, back = love.graphics.newCanvas(w,h), love.graphics.newCanvas(w,h) local buffer = function() back, front = front, back return front, back @@ -45,6 +51,11 @@ moonshine.chain = function(effect) local disabled = {} -- set of disabled effects local chain = {} + chain.resize = function(w, h) + front, back = love.graphics.newCanvas(w,h), love.graphics.newCanvas(w,h) + return chain + end + chain.draw = function(func, ...) -- save state local canvas = love.graphics.getCanvas() From cbed7a81bd93f7904569a1da9ca338869b3d6770 Mon Sep 17 00:00:00 2001 From: Matthias Richter Date: Sun, 8 Apr 2018 16:15:47 +0200 Subject: [PATCH 08/22] Fix #34 --- README.md | 4 ++-- scanlines.lua | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 94b1d1f..5b2d00d 100644 --- a/README.md +++ b/README.md @@ -435,8 +435,8 @@ moonshine.effects.scanlines Name | Type | Default -----|------|-------- -width | number | 1 -frequency | number | screen-height / 1 +width | number | 2 +frequency | number | screen-height phase | number | 0 thickness | number | 1 opacity | number | 1 diff --git a/scanlines.lua b/scanlines.lua index 59ba947..590abe3 100644 --- a/scanlines.lua +++ b/scanlines.lua @@ -43,6 +43,9 @@ return function(moonshine) setters.width = function(v) shader:send("width", tonumber(v) or defaults.width) end + setters.frequency = function(v) + shader:send("width", love.graphics.getHeight()/(tonumber(v) or love.graphics.getHeight())) + end setters.phase = function(v) shader:send("phase", tonumber(v) or defaults.phase) end From 177f2bbdfad5ab592454dc534dbb97fee1dbf4a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=BD=28*=E2=89=A7=CF=89=E2=89=A6=29=EF=BE=89=20shru?= Date: Tue, 10 Apr 2018 15:32:22 +0930 Subject: [PATCH 09/22] Declare "front" and "back" as local in moonshine.draw_shader() --- init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.lua b/init.lua index 6639e99..431c6c0 100644 --- a/init.lua +++ b/init.lua @@ -27,7 +27,7 @@ local BASE = ... local moonshine = {} moonshine.draw_shader = function(buffer, shader) - front, back = buffer() + local front, back = buffer() love.graphics.setCanvas(front) love.graphics.clear() if shader ~= love.graphics.getShader() then From dc43eb15fe26d2aecf368556ab31441513bf53c9 Mon Sep 17 00:00:00 2001 From: Matthias Richter Date: Sat, 5 May 2018 12:52:10 +0200 Subject: [PATCH 10/22] Fix #43: Add licensing information to readme --- README.md | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5b2d00d..4ca54be 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ Chainable post-processing shaders for LÖVE. * [General usage](#general-usage) * [List of effects](#list-of-effects) * [Writing effects](#writing-effects) +* [License](#license) ## Getting started @@ -479,8 +480,6 @@ color | color / table of numbers | {0,0,0} ## Writing effects -**Under construction** - An effect is essentially a function that returns a `moonshine.Effect{}`, which must specify at least a `name` and a `shader` or a `draw` function. @@ -511,3 +510,57 @@ If for some reason you need more than two buffer, you are more or less on your own. You can do everything, but make sure that the blend mode and the order of back and front buffer is the same before and after your custom `draw` function. The `glow` effect gives an example of a more complicated `draw` function. + + + +## License + +See [here](https://github.com/vrld/moonshine/graphs/contributors) for a list of +contributors. + +The main library can freely be used under the following conditions: + + The MIT License (MIT) + + Copyright (c) 2017 Matthias Richter + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + +Most of the effects are public domain (see comments inside the files): + +* boxblur.lua +* chromasep.lua +* colorgradesimple.lua +* crt.lua +* desaturate.lua +* filmgrain.lua +* gaussianblur.lua +* glow.lua +* pixelate.lua +* posterize.lua +* scanlines.lua +* vignette.lua + +These effects are MIT-licensed with multiple authors: + +* dmg.lua: Joseph Patoprsty, Matthias Richter +* fastgaussianblur.lua: Tim Moore, Matthias Richter +* godsray.lua: Joseph Patoprsty, Matthias Richter. Based on work by ioxu, Fabien Sanglard, Kenny Mitchell and Jason Mitchell. +* sketch.lua: Martin Felis, Matthias Richter + From 1203c9d40620a77bf9079c9dc4e7eb18431f2bfb Mon Sep 17 00:00:00 2001 From: flamendless Date: Fri, 1 Feb 2019 19:44:49 +0800 Subject: [PATCH 11/22] added fog --- README.md | 16 +++++++++- fog.lua | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 fog.lua diff --git a/README.md b/README.md index 4ca54be..635ffdb 100644 --- a/README.md +++ b/README.md @@ -475,6 +475,20 @@ softness | number > 0 | 0.5 opacity | number > 0 | 0.5 color | color / table of numbers | {0,0,0} + +### fog + +```lua +moonshine.effects.fog +``` + +**Parameters:** + +Name | Type | Default +-----|------|-------- +fog_color | color/table of numbers | {0.35, 0.48, 0.95} +octaves | number > 0 | 4 +speed | vec2/table of numbers | {0.5, 0.5} @@ -563,4 +577,4 @@ These effects are MIT-licensed with multiple authors: * fastgaussianblur.lua: Tim Moore, Matthias Richter * godsray.lua: Joseph Patoprsty, Matthias Richter. Based on work by ioxu, Fabien Sanglard, Kenny Mitchell and Jason Mitchell. * sketch.lua: Martin Felis, Matthias Richter - +* fog.lua: Brandon Blanker Lim-it. Based on work by Gonkee. diff --git a/fog.lua b/fog.lua new file mode 100644 index 0000000..eb08ef3 --- /dev/null +++ b/fog.lua @@ -0,0 +1,91 @@ +--[[ +Animated 2D Fog (procedural) +Originally for Godot Engine by Gonkee https://www.youtube.com/watch?v=QEaTsz_0o44&t=6s + +Translated for löve by Brandon Blanker Lim-it @flamendless +]]-- + +return function(moonshine) + local fog_color + local octaves + local speed + + local shader = love.graphics.newShader([[ + extern vec3 fog_color = vec3(0.35, 0.48, 0.95); + extern int octaves = 4; + extern vec2 speed = vec2(0.0, 1.0); + extern float time; + + float rand(vec2 coord) + { + return fract(sin(dot(coord, vec2(56, 78)) * 1000.0) * 1000.0); + } + + float noise(vec2 coord) + { + vec2 i = floor(coord); //get the whole number + vec2 f = fract(coord); //get the fraction number + float a = rand(i); //top-left + float b = rand(i + vec2(1.0, 0.0)); //top-right + float c = rand(i + vec2(0.0, 1.0)); //bottom-left + float d = rand(i + vec2(1.0, 1.0)); //bottom-right + vec2 cubic = f * f * (3.0 - 2.0 * f); + return mix(a, b, cubic.x) + (c - a) * cubic.y * (1.0 - cubic.x) + (d - b) * cubic.x * cubic.y; //interpolate + } + + float fbm(vec2 coord) //fractal brownian motion + { + float value = 0.0; + float scale = 0.5; + for (int i = 0; i < octaves; i++) + { + value += noise(coord) * scale; + coord *= 2.0; + scale *= 0.5; + } + return value; + } + + vec4 effect(vec4 color, Image texture, vec2 tc, vec2 sc) + { + vec2 coord = tc * 20.0; + vec2 motion = vec2(fbm(coord + vec2(time * speed.x, time * speed.y))); + float final = fbm(coord + motion); + return vec4(fog_color, final * 0.5); + } + ]]) + + local setters = {} + + setters.fog_color = function(t) + assert(type(v) == "table", "Passed argument to fog_color must be a table containing 3 color values") + fog_color = t + shader:send("fog_color", fog_color) + end + + setters.octaves = function(i) + assert(type(i) == "number", "Passed argument to octaves must be an integer") + octaves = i + shader:send("octaves", octaves) + end + + setters.speed = function(speed_x, speed_y) + assert(type(speed_x) == "number", "Passed argument to speed must be a number (float)") + assert(type(speed_y) == "number", "Passed argument to speed must be a number (float)") + speed = {speed_x, speed_y} + shader:send("speed", speed) + end + + local defaults = { + fog_color = {0.35, 0.48, 0.95}, + octaves = 4, + speed = {0.5, 0.5}, + } + + return moonshine.Effect({ + name = "Fog", + shader = shader, + setters = setters, + defaults = defaults, + }) +end From 7894b32c3283a37d3ed08497ced629202af252a4 Mon Sep 17 00:00:00 2001 From: flamendless Date: Fri, 1 Feb 2019 19:51:42 +0800 Subject: [PATCH 12/22] quickfix --- fog.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fog.lua b/fog.lua index eb08ef3..1ddcbe9 100644 --- a/fog.lua +++ b/fog.lua @@ -58,7 +58,7 @@ return function(moonshine) local setters = {} setters.fog_color = function(t) - assert(type(v) == "table", "Passed argument to fog_color must be a table containing 3 color values") + assert(type(t) == "table", "Passed argument to fog_color must be a table containing 3 color values") fog_color = t shader:send("fog_color", fog_color) end From 2c02d1fed9993d9ee61f17332de4ae07c6dfa28a Mon Sep 17 00:00:00 2001 From: flamendless Date: Fri, 1 Feb 2019 19:55:00 +0800 Subject: [PATCH 13/22] quickfix --- fog.lua | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/fog.lua b/fog.lua index 1ddcbe9..c4cc64a 100644 --- a/fog.lua +++ b/fog.lua @@ -69,10 +69,9 @@ return function(moonshine) shader:send("octaves", octaves) end - setters.speed = function(speed_x, speed_y) - assert(type(speed_x) == "number", "Passed argument to speed must be a number (float)") - assert(type(speed_y) == "number", "Passed argument to speed must be a number (float)") - speed = {speed_x, speed_y} + setters.speed = function(t) + assert(type(t) == "tabe", "Passed argument to speed must be a table containing 2 values") + speed = t shader:send("speed", speed) end @@ -83,7 +82,7 @@ return function(moonshine) } return moonshine.Effect({ - name = "Fog", + name = "fog", shader = shader, setters = setters, defaults = defaults, From d4b5ad51feac3744043bc4cda8540cffe0cbb40e Mon Sep 17 00:00:00 2001 From: flamendless Date: Fri, 1 Feb 2019 19:56:48 +0800 Subject: [PATCH 14/22] added time --- fog.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fog.lua b/fog.lua index c4cc64a..b693d9a 100644 --- a/fog.lua +++ b/fog.lua @@ -9,6 +9,7 @@ return function(moonshine) local fog_color local octaves local speed + local time local shader = love.graphics.newShader([[ extern vec3 fog_color = vec3(0.35, 0.48, 0.95); @@ -75,6 +76,12 @@ return function(moonshine) shader:send("speed", speed) end + setters.time = function(n) + assert(type(n) == "number", "Passed argument to time must be a number") + time = n + shader:send("time", time) + end + local defaults = { fog_color = {0.35, 0.48, 0.95}, octaves = 4, From 80bd81e82308128a9f8c9bb49979d187bdf8d50f Mon Sep 17 00:00:00 2001 From: flamendless Date: Fri, 1 Feb 2019 19:57:53 +0800 Subject: [PATCH 15/22] added sample usage --- fog.lua | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/fog.lua b/fog.lua index b693d9a..d6bbd73 100644 --- a/fog.lua +++ b/fog.lua @@ -5,6 +5,38 @@ Originally for Godot Engine by Gonkee https://www.youtube.com/watch?v=QEaTsz_0o4 Translated for löve by Brandon Blanker Lim-it @flamendless ]]-- +--[[ +SAMPLE USAGE: +local moonshine = require("moonshine") +local effect + +local image, bg +local image_data +local shader_fog +local time = 0 + +function love.load() + image_data = love.image.newImageData(love.graphics.getWidth(), love.graphics.getHeight()) + image = love.graphics.newImage(image_data) + bg = love.graphics.newImage("bg.png") + effect = moonshine(moonshine.effects.fog) + effect.fog.fog_color = {0.1, 0.0, 0.0} + effect.fog.speed = {0.2, 0.9} +end + +function love.update(dt) + time = time + dt + effect.fog.time = time +end + +function love.draw() + love.graphics.draw(bg) + effect(function() + love.graphics.draw(image) + end) +end +]] + return function(moonshine) local fog_color local octaves From b820904916dfc68eb7748b812d7b0a88ea0f6cf2 Mon Sep 17 00:00:00 2001 From: flamendless Date: Fri, 1 Feb 2019 20:00:10 +0800 Subject: [PATCH 16/22] quickfix --- fog.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fog.lua b/fog.lua index d6bbd73..9c90f9a 100644 --- a/fog.lua +++ b/fog.lua @@ -103,7 +103,7 @@ return function(moonshine) end setters.speed = function(t) - assert(type(t) == "tabe", "Passed argument to speed must be a table containing 2 values") + assert(type(t) == "table", "Passed argument to speed must be a table containing 2 values") speed = t shader:send("speed", speed) end From 3ace7c9e352127d56ab2b96fd9a130463067de9b Mon Sep 17 00:00:00 2001 From: Nikhilesh Sigatapu Date: Wed, 4 Jul 2018 03:45:46 -0700 Subject: [PATCH 17/22] no floating point suffixes for shaders (iOS fix) --- boxblur.lua | 6 +++--- colorgradesimple.lua | 2 +- crt.lua | 2 +- desaturate.lua | 2 +- fastgaussianblur.lua | 2 +- gaussianblur.lua | 2 +- glow.lua | 2 +- vignette.lua | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/boxblur.lua b/boxblur.lua index 54924e8..bb6afc1 100644 --- a/boxblur.lua +++ b/boxblur.lua @@ -21,13 +21,13 @@ return function(moonshine) extern vec2 direction; extern number radius; vec4 effect(vec4 color, Image texture, vec2 tc, vec2 _) { - vec4 c = vec4(0.0f); + vec4 c = vec4(0.0); - for (float i = -radius; i <= radius; i += 1.0f) + for (float i = -radius; i <= radius; i += 1.0) { c += Texel(texture, tc + i * direction); } - return c / (2.0f * radius + 1.0f) * color; + return c / (2.0 * radius + 1.0) * color; }]] local setters = {} diff --git a/colorgradesimple.lua b/colorgradesimple.lua index c4728de..f0e0278 100644 --- a/colorgradesimple.lua +++ b/colorgradesimple.lua @@ -19,7 +19,7 @@ return function(moonshine) local shader = love.graphics.newShader[[ extern vec3 factors; vec4 effect(vec4 color, Image texture, vec2 tc, vec2 _) { - return vec4(factors, 1.0f) * Texel(texture, tc) * color; + return vec4(factors, 1.0) * Texel(texture, tc) * color; }]] local setters = {} diff --git a/crt.lua b/crt.lua index 9b73799..f9cdde3 100644 --- a/crt.lua +++ b/crt.lua @@ -16,7 +16,7 @@ PERFORMANCE OF THIS SOFTWARE. ]]-- return function(moonshine) - -- Barrel distortion adapted from Daniel Oaks (see commit cef01b67fd) + -- Barrel distortion adapted from Daniel Oaks (see commit cef01b67d) -- Added feather to mask out outside of distorted texture local distortionFactor local shader = love.graphics.newShader[[ diff --git a/desaturate.lua b/desaturate.lua index b89af2f..8a55217 100644 --- a/desaturate.lua +++ b/desaturate.lua @@ -21,7 +21,7 @@ return function(moonshine) extern number strength; vec4 effect(vec4 color, Image texture, vec2 tc, vec2 _) { color = Texel(texture, tc); - number luma = dot(vec3(0.299f, 0.587f, 0.114f), color.rgb); + number luma = dot(vec3(0.299, 0.587, 0.114), color.rgb); return mix(color, tint * luma, strength); }]] diff --git a/fastgaussianblur.lua b/fastgaussianblur.lua index 65b566b..364b766 100644 --- a/fastgaussianblur.lua +++ b/fastgaussianblur.lua @@ -64,7 +64,7 @@ local function build_shader(taps, offset, offset_type, sigma) local norm = 0 if #g_weights % 2 == 0 then - code[#code+1] = 'vec4 c = vec4( 0.0f );' + code[#code+1] = 'vec4 c = vec4( 0.0 );' else local weight = g_weights[1] norm = norm + weight diff --git a/gaussianblur.lua b/gaussianblur.lua index 8d8882a..693414a 100644 --- a/gaussianblur.lua +++ b/gaussianblur.lua @@ -15,7 +15,7 @@ local function resetShader(sigma) local code = {[[ extern vec2 direction; vec4 effect(vec4 color, Image texture, vec2 tc, vec2 _) - { vec4 c = vec4(0.0f); + { vec4 c = vec4(0.0); ]]} local blur_line = "c += vec4(%f) * Texel(texture, tc + vec2(%f) * direction);" diff --git a/glow.lua b/glow.lua index 8e414dd..cec010b 100644 --- a/glow.lua +++ b/glow.lua @@ -25,7 +25,7 @@ local function make_blur_shader(sigma) local code = {[[ extern vec2 direction; vec4 effect(vec4 color, Image texture, vec2 tc, vec2 _) { - vec4 c = vec4(0.0f); + vec4 c = vec4(0.0); ]]} local blur_line = "c += vec4(%f) * Texel(texture, tc + vec2(%f) * direction);" diff --git a/vignette.lua b/vignette.lua index a389afa..3021801 100644 --- a/vignette.lua +++ b/vignette.lua @@ -27,7 +27,7 @@ return function(moonshine) number aspect = love_ScreenSize.x / love_ScreenSize.y; aspect = max(aspect, 1.0 / aspect); // use different aspect when in portrait mode number v = 1.0 - smoothstep(radius, radius-softness, - length((tc - vec2(0.5f)) * aspect)); + length((tc - vec2(0.5)) * aspect)); return mix(Texel(tex, tc), color, v*opacity); }]] From d39271e0c000e2fedbc2e3ad286b78b5a5146065 Mon Sep 17 00:00:00 2001 From: Nikhilesh S Date: Wed, 4 Jul 2018 15:29:06 -0700 Subject: [PATCH 18/22] undo accidental 'f' removal not in a shader --- crt.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crt.lua b/crt.lua index f9cdde3..9b73799 100644 --- a/crt.lua +++ b/crt.lua @@ -16,7 +16,7 @@ PERFORMANCE OF THIS SOFTWARE. ]]-- return function(moonshine) - -- Barrel distortion adapted from Daniel Oaks (see commit cef01b67d) + -- Barrel distortion adapted from Daniel Oaks (see commit cef01b67fd) -- Added feather to mask out outside of distorted texture local distortionFactor local shader = love.graphics.newShader[[ From ef19b40f6a9189d630850231520fe81aec02620f Mon Sep 17 00:00:00 2001 From: David Briscoe Date: Thu, 30 Dec 2021 00:13:30 -0800 Subject: [PATCH 19/22] Use colours in [0,1] Update to love 11.0 colour format where all colours are normalized. --- README.md | 4 ++-- desaturate.lua | 9 +++++---- filmgrain.lua | 2 +- scanlines.lua | 7 ++++--- sketch.lua | 2 +- vignette.lua | 7 ++++--- 6 files changed, 17 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 635ffdb..062937a 100644 --- a/README.md +++ b/README.md @@ -286,7 +286,7 @@ moonshine.effects.desaturate Name | Type | Default -----|------|-------- -tint | color / table of numbers | {255,255,255} +tint | color / table of numbers | {1,1,1} strength | number between 0 and 1 | 0.5 @@ -312,7 +312,7 @@ DMG ships with 7 palettes: 7. `pocket` Custom palettes must be in the format `{{R,G,B}, {R,G,B}, {R,G,B}, {R,G,B}}`, -where `R`, `G`, and `B` are numbers between `0` and `255`. +where `R`, `G`, and `B` are numbers between `0` and `1`. diff --git a/desaturate.lua b/desaturate.lua index 8a55217..dd51230 100644 --- a/desaturate.lua +++ b/desaturate.lua @@ -29,10 +29,11 @@ return function(moonshine) setters.tint = function(c) assert(type(c) == "table" and #c == 3, "Invalid value for `tint'") + assert(c[1] <= 1, "Colors should be normalized in [0,1]") shader:send("tint", { - (tonumber(c[1]) or 0) / 255, - (tonumber(c[2]) or 0) / 255, - (tonumber(c[3]) or 0) / 255, + (tonumber(c[1]) or 0), + (tonumber(c[2]) or 0), + (tonumber(c[3]) or 0), 1 }) end @@ -41,7 +42,7 @@ return function(moonshine) shader:send("strength", math.max(0, math.min(1, tonumber(v) or 0))) end - local defaults = {tint = {255,255,255}, strength = 0.5} + local defaults = {tint = {1,1,1}, strength = 0.5} return moonshine.Effect{ name = "desaturate", diff --git a/filmgrain.lua b/filmgrain.lua index 8491f17..7044567 100644 --- a/filmgrain.lua +++ b/filmgrain.lua @@ -18,7 +18,7 @@ PERFORMANCE OF THIS SOFTWARE. return function(moonshine) local noisetex = love.image.newImageData(256,256) noisetex:mapPixel(function() - local l = love.math.random() * 255 + local l = love.math.random() return l,l,l,l end) noisetex = love.graphics.newImage(noisetex) diff --git a/scanlines.lua b/scanlines.lua index 590abe3..c800fad 100644 --- a/scanlines.lua +++ b/scanlines.lua @@ -57,10 +57,11 @@ return function(moonshine) end setters.color = function(c) assert(type(c) == "table" and #c == 3, "Invalid value for `color'") + assert(c[1] <= 1, "Colors should be normalized in [0,1]") shader:send("color", { - (tonumber(c[1]) or defaults.color[0]) / 255, - (tonumber(c[2]) or defaults.color[1]) / 255, - (tonumber(c[3]) or defaults.color[2]) / 255 + (tonumber(c[1]) or defaults.color[0]), + (tonumber(c[2]) or defaults.color[1]), + (tonumber(c[3]) or defaults.color[2]) }) end diff --git a/sketch.lua b/sketch.lua index befe213..dcd4844 100644 --- a/sketch.lua +++ b/sketch.lua @@ -26,7 +26,7 @@ SOFTWARE. return function(moonshine) local noisetex = love.image.newImageData(256,256) noisetex:mapPixel(function() - return love.math.random() * 255,love.math.random() * 255, 0, 0 + return love.math.random(),love.math.random(), 0, 0 end) noisetex = love.graphics.newImage(noisetex) noisetex:setWrap ("repeat", "repeat") diff --git a/vignette.lua b/vignette.lua index 3021801..f13fb8b 100644 --- a/vignette.lua +++ b/vignette.lua @@ -37,10 +37,11 @@ return function(moonshine) end setters.color = function(c) assert(type(c) == "table" and #c == 3, "Invalid value for `color'") + assert(c[1] <= 1, "Colors should be normalized in [0,1]") shader:send("color", { - (tonumber(c[1]) or 0) / 255, - (tonumber(c[2]) or 0) / 255, - (tonumber(c[3]) or 0) / 255, + (tonumber(c[1]) or 0), + (tonumber(c[2]) or 0), + (tonumber(c[3]) or 0), 1 }) end From e5adb93ee83f380de591413c57c0dbf84b3493e6 Mon Sep 17 00:00:00 2001 From: David Briscoe Date: Thu, 30 Dec 2021 00:15:14 -0800 Subject: [PATCH 20/22] Use valid indices for colours Lua tables start at 1. --- scanlines.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scanlines.lua b/scanlines.lua index c800fad..fb5423d 100644 --- a/scanlines.lua +++ b/scanlines.lua @@ -59,9 +59,9 @@ return function(moonshine) assert(type(c) == "table" and #c == 3, "Invalid value for `color'") assert(c[1] <= 1, "Colors should be normalized in [0,1]") shader:send("color", { - (tonumber(c[1]) or defaults.color[0]), - (tonumber(c[2]) or defaults.color[1]), - (tonumber(c[3]) or defaults.color[2]) + (tonumber(c[1]) or defaults.color[1]), + (tonumber(c[2]) or defaults.color[2]), + (tonumber(c[3]) or defaults.color[3]) }) end From c47b93bfcc0ddbd32f0ae1c204d73c9c16ecdb9c Mon Sep 17 00:00:00 2001 From: David Briscoe Date: Thu, 30 Dec 2021 00:32:30 -0800 Subject: [PATCH 21/22] Update suit to use colors in [0,1] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Get latest version of suit so UI draws correctly with love 11.0's normalized colours. Changelog: Fix a sentence in docs Merge pull request #72 from SimonLarsen/imagebutton-fix [docs] better words Fix #70: overlapping buttons both react to hover Fix #68: ImageButton error on LÖVE 11.1 Fix rockspec Fix #62: Add rockspec Merge pull request #64 from rodel77/master --- suit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/suit b/suit index 5d48cf9..1767782 160000 --- a/suit +++ b/suit @@ -1 +1 @@ -Subproject commit 5d48cf97b876696e9ea20a9a9946e26cc7e8c643 +Subproject commit 17677826030a7270b474c5717af43834d583094c From 7fc1fbde9b6aeb8db338126ca75483e9bc475f74 Mon Sep 17 00:00:00 2001 From: David Briscoe Date: Thu, 30 Dec 2021 00:13:30 -0800 Subject: [PATCH 22/22] Use colours in [0,1] for demo Update demo to love 11.0 colour format where all colours are normalized. --- main.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/main.lua b/main.lua index 6264284..05afb1e 100644 --- a/main.lua +++ b/main.lua @@ -73,9 +73,9 @@ local ParamInfo = { return {changed = c} end, state = { - {value = r, min = 0, max = 255}, - {value = g, min = 0, max = 255}, - {value = b, min = 0, max = 255} + {value = r, min = 0, max = 1}, + {value = g, min = 0, max = 1}, + {value = b, min = 0, max = 1} }, val = function(s) return {s[1].value, s[2].value, s[3].value} end } @@ -126,7 +126,7 @@ local effects = { feather = ParamInfo.number(0.02, 0, .2) }, EffectInfo'desaturate'{ - tint = ParamInfo.RGB(255,255,255), + tint = ParamInfo.RGB(1,1,1), strength = ParamInfo.number(0.5, 0, 1) }, EffectInfo'dmg'{ @@ -297,7 +297,7 @@ function love.update(dt) end function love.draw() - love.graphics.setColor(255,255,255) + love.graphics.setColor(1,1,1) effect(function() love.graphics.draw(img) @@ -306,12 +306,12 @@ function love.draw() love.graphics.push() love.graphics.translate(550,200) love.graphics.rotate(t) - love.graphics.setColor(100,100,200) + love.graphics.setColor(0.4,0.4,0.8) love.graphics.rectangle('fill', -100,-50,200,100) love.graphics.pop() end) - love.graphics.setColor(0,0,0,200) + love.graphics.setColor(0,0,0,0.8) -- background for chain editor local h = ((show_edit_chain.checked and #effects or 0) + 1) * 22 + 8 love.graphics.rectangle('fill', 5,5, 195, h)