Skip to content

Instantly share code, notes, and snippets.

@PatoFlamejanteTV
Last active October 15, 2024 19:43
Show Gist options
  • Save PatoFlamejanteTV/cdaab4cb082be2611da4d30d064d5f5e to your computer and use it in GitHub Desktop.
Save PatoFlamejanteTV/cdaab4cb082be2611da4d30d064d5f5e to your computer and use it in GitHub Desktop.
Simple shader system using 'Dirty Edge.frag' for Psych Engine | Ported from https://github.com/PatoFlamejanteTV/ImaturidadePlusPlus/blob/main/scripts/Dirty%20Edge.lua.hfesjklghjk
-- For Psych Engine
-- https://github.com/PatoFlamejanteTV/ImaturidadePlusPlus/blob/main/scripts/Dirty%20Edge.lua.hfesjklghjk
-- needs Dirty Edge.frag to work (yourmod/shaders/Dirty Edge.frag)
-- https://github.com/PatoFlamejanteTV/ImaturidadePlusPlus/blob/main/shaders/Dirty%20Edge.frag
local shaderName = "Dirty Edge"
function onCreate()
shaderCoordFix() -- initialize a fix for textureCoord when resizing game window
makeLuaSprite("Dirty Edge")
makeGraphic("shaderImage", screenWidth, screenHeight)
setSpriteShader("shaderImage", "Dirty Edge")
runHaxeCode([[
var shaderName = "]] .. shaderName .. [[";
game.initLuaShader(shaderName);
var shader0 = game.createRuntimeShader(shaderName);
game.camGame.setFilters([new ShaderFilter(shader0)]);
game.getLuaObject("Dirty Edge").shader = shader0; // setting it into temporary sprite so luas can set its shader uniforms/properties
game.camHUD.setFilters([new ShaderFilter(game.getLuaObject("Dirty Edge").shader)]);
return;
]])
end
function onUpdate(elapsed)
setShaderFloat("Dirty Edge", "iTime", os.clock())
end
function shaderCoordFix()
runHaxeCode([[
resetCamCache = function(?spr) {
if (spr == null || spr.filters == null) return;
spr.__cacheBitmap = null;
spr.__cacheBitmapData = null;
}
fixShaderCoordFix = function(?_) {
resetCamCache(game.camGame.flashSprite);
resetCamCache(game.camHUD.flashSprite);
resetCamCache(game.camOther.flashSprite);
}
FlxG.signals.gameResized.add(fixShaderCoordFix);
fixShaderCoordFix();
return;
]])
local temp = onDestroy
function onDestroy()
runHaxeCode([[
FlxG.signals.gameResized.remove(fixShaderCoordFix);
return;
]])
if (temp) then temp() end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment