diff --git a/mods/_testmod/assets/shaders/wave.glsl b/mods/_testmod/assets/shaders/wave.glsl new file mode 100644 index 000000000..0b8f7a806 --- /dev/null +++ b/mods/_testmod/assets/shaders/wave.glsl @@ -0,0 +1,10 @@ +extern number wave_sine; +extern number wave_mag; +extern number wave_height; +extern vec2 texsize; +vec4 effect( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords ) +{ + number i = texture_coords.y * texsize.y; + vec2 coords = vec2(max(0.0, min(1.0, texture_coords.x + (sin((i / wave_height) + (wave_sine / 30.0)) * wave_mag) / texsize.x)), max(0.0, min(1.0, texture_coords.y + 0.0))); + return Texel(texture, coords) * color; +} diff --git a/mods/_testmod/mod.lua b/mods/_testmod/mod.lua index 5ce3422c9..13eb77f04 100644 --- a/mods/_testmod/mod.lua +++ b/mods/_testmod/mod.lua @@ -21,19 +21,6 @@ function Mod:init() self.dog_activated = false end -Mod.wave_shader = love.graphics.newShader([[ - extern number wave_sine; - extern number wave_mag; - extern number wave_height; - extern vec2 texsize; - vec4 effect( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords ) - { - number i = texture_coords.y * texsize.y; - vec2 coords = vec2(max(0.0, min(1.0, texture_coords.x + (sin((i / wave_height) + (wave_sine / 30.0)) * wave_mag) / texsize.x)), max(0.0, min(1.0, texture_coords.y + 0.0))); - return Texel(texture, coords) * color; - } -]]) - function Mod:preInit() -- make characters woobly --[[Utils.hook(ActorSprite, "init", function(orig, self, ...) @@ -115,7 +102,7 @@ function Mod:registerDebugContext(context, object) object:removeFX("funky_mode") else local offset = Utils.random(0, 100) - object:addFX(ShaderFX(Mod.wave_shader, { + object:addFX(ShaderFX("wave", { ["wave_sine"] = function () return (Kristal.getTime() + offset) * 100 end, ["wave_mag"] = 4, ["wave_height"] = 4, @@ -141,7 +128,7 @@ function Mod:registerDebugOptions(debug) if Game.world.player:getFX("funky_mode") then Game.world.player:removeFX("funky_mode") else - Game.world.player:addFX(ShaderFX(Mod.wave_shader, { + Game.world.player:addFX(ShaderFX("wave", { ["wave_sine"] = function () return Kristal.getTime() * 100 end, ["wave_mag"] = 4, ["wave_height"] = 4, diff --git a/src/engine/drawfx/shaderfx.lua b/src/engine/drawfx/shaderfx.lua index ce548299c..5d316623f 100644 --- a/src/engine/drawfx/shaderfx.lua +++ b/src/engine/drawfx/shaderfx.lua @@ -1,10 +1,14 @@ ---@class ShaderFX : FXBase ----@overload fun(...) : ShaderFX +---@overload fun(shader:string|love.Shader,vars?:table,transformed?:boolean,priority?:number) : ShaderFX local ShaderFX, super = Class(FXBase) function ShaderFX:init(shader, vars, transformed, priority) super.init(self, priority or 0) + if type(shader) == "string" then + shader = Assets.newShader(shader) + end + self.shader = shader self.transformed = transformed or false