Skip to content

Commit

Permalink
Add shader asset to ShaderFX constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
polypoyo authored and NyakoFox committed Nov 6, 2024
1 parent f220681 commit f7dd44a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
10 changes: 10 additions & 0 deletions mods/_testmod/assets/shaders/wave.glsl
Original file line number Diff line number Diff line change
@@ -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;
}
17 changes: 2 additions & 15 deletions mods/_testmod/mod.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...)
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion src/engine/drawfx/shaderfx.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit f7dd44a

Please sign in to comment.