Merge pull request #504 from MihailRis/post-effects

Post-processing effects
This commit is contained in:
MihailRis
2025-04-07 20:24:03 +03:00
committed by GitHub
35 changed files with 764 additions and 180 deletions
+2 -1
View File
@@ -38,6 +38,7 @@ extern const luaL_Reg networklib[];
extern const luaL_Reg packlib[];
extern const luaL_Reg particleslib[]; // gfx.particles
extern const luaL_Reg playerlib[];
extern const luaL_Reg posteffectslib[]; // gfx.posteffects
extern const luaL_Reg quatlib[];
extern const luaL_Reg text3dlib[]; // gfx.text3d
extern const luaL_Reg timelib[];
@@ -46,7 +47,7 @@ extern const luaL_Reg utf8lib[];
extern const luaL_Reg vec2lib[]; // vecn.cpp
extern const luaL_Reg vec3lib[]; // vecn.cpp
extern const luaL_Reg vec4lib[]; // vecn.cpp
extern const luaL_Reg weatherlib[];
extern const luaL_Reg weatherlib[]; // gfx.weather
extern const luaL_Reg worldlib[];
extern const luaL_Reg yamllib[];
@@ -0,0 +1,68 @@
#include "libhud.hpp"
#include "assets/Assets.hpp"
#include "content/Content.hpp"
#include "graphics/core/PostEffect.hpp"
#include "graphics/core/PostProcessing.hpp"
using namespace scripting;
static int l_index(lua::State* L) {
auto name = lua::require_string(L, 1);
auto& indices = content->getIndices(ResourceType::POST_EFFECT_SLOT);
return lua::pushinteger(L, indices.indexOf(name));
}
static int l_set_effect(lua::State* L) {
size_t index = static_cast<size_t>(lua::tointeger(L, 1));
auto name = lua::require_string(L, 2);
auto& assets = *engine->getAssets();
auto effect = std::make_shared<PostEffect>(assets.require<PostEffect>(name));
post_processing->setEffect(index, std::move(effect));
return 0;
}
static int l_get_intensity(lua::State* L) {
size_t index = static_cast<size_t>(lua::tointeger(L, 1));
auto effect = post_processing->getEffect(index);
return lua::pushnumber(L, effect ? effect->getIntensity() : 0.0f);
}
static int l_set_intensity(lua::State* L) {
size_t index = static_cast<size_t>(lua::tointeger(L, 1));
float value = lua::tonumber(L, 2);
post_processing->getEffect(index)->setIntensity(value);
return 0;
}
static int l_is_active(lua::State* L) {
size_t index = static_cast<size_t>(lua::tointeger(L, 1));
auto effect = post_processing->getEffect(index);
return lua::pushboolean(L, effect ? effect->isActive() : false);
}
static int l_set_params(lua::State* L) {
size_t index = static_cast<size_t>(lua::tointeger(L, 1));
auto table = lua::tovalue(L, 2);
if (!table.isObject()) {
throw std::runtime_error("params table expected");
}
auto effect = post_processing->getEffect(index);
if (effect == nullptr) {
return 0;
}
for (const auto& [key, value] : table.asObject()) {
effect->setParam(key, value);
}
return 0;
}
const luaL_Reg posteffectslib[] = {
{"index", lua::wrap<l_index>},
{"set_effect", lua::wrap<l_set_effect>},
{"get_intensity", lua::wrap<l_get_intensity>},
{"set_intensity", lua::wrap<l_set_intensity>},
{"is_active", lua::wrap<l_is_active>},
{"set_params", lua::wrap<l_set_params>},
{NULL, NULL}
};