diff options
author | Indrajith K L | 2022-02-27 01:15:31 +0530 |
---|---|---|
committer | Indrajith K L | 2022-02-27 01:15:31 +0530 |
commit | 62ff5245c26c305e35a2903cc64a60cb20718e96 (patch) | |
tree | 9042f9917e77b584b0ceb421166221ef7777a5d1 /libs/moonshine/sketch.lua | |
download | YEAD-62ff5245c26c305e35a2903cc64a60cb20718e96.tar.gz YEAD-62ff5245c26c305e35a2903cc64a60cb20718e96.tar.bz2 YEAD-62ff5245c26c305e35a2903cc64a60cb20718e96.zip |
Initial Commit
* ECS - In-Progress
* GameStates - Skeleton Implemented
* Library Integrations - Completed
* Levels - In-Progress
Diffstat (limited to 'libs/moonshine/sketch.lua')
-rw-r--r-- | libs/moonshine/sketch.lua | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/libs/moonshine/sketch.lua b/libs/moonshine/sketch.lua new file mode 100644 index 0000000..dcd4844 --- /dev/null +++ b/libs/moonshine/sketch.lua @@ -0,0 +1,64 @@ +--[[ +The MIT License (MIT) + +Copyright (c) 2015 Martin Felis +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. +]]-- + +return function(moonshine) + local noisetex = love.image.newImageData(256,256) + noisetex:mapPixel(function() + return love.math.random(),love.math.random(), 0, 0 + end) + noisetex = love.graphics.newImage(noisetex) + noisetex:setWrap ("repeat", "repeat") + noisetex:setFilter("nearest", "nearest") + + local shader = love.graphics.newShader[[ + extern Image noisetex; + extern number amp; + extern vec2 center; + + vec4 effect(vec4 color, Image texture, vec2 tc, vec2 _) { + vec2 displacement = Texel(noisetex, tc + center).rg; + tc += normalize(displacement * 2.0 - vec2(1.0)) * amp; + + return Texel(texture, tc); + }]] + + shader:send("noisetex", noisetex) + + local setters = {} + setters.amp = function(v) + shader:send("amp", math.max(0, tonumber(v) or 0)) + end + setters.center = function(v) + assert(type(v) == "table" and #v == 2, "Invalid value for `center'") + shader:send("center", v) + end + + return moonshine.Effect{ + name = "sketch", + shader = shader, + setters = setters, + defaults = {amp = .0007, center = {0,0}} + } +end |