Merge pull request #504 from MihailRis/post-effects
Post-processing effects
This commit is contained in:
@@ -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}
|
||||
};
|
||||
@@ -19,6 +19,7 @@ static debug::Logger logger("scripting-hud");
|
||||
|
||||
Hud* scripting::hud = nullptr;
|
||||
WorldRenderer* scripting::renderer = nullptr;
|
||||
PostProcessing* scripting::post_processing = nullptr;
|
||||
|
||||
static void load_script(const std::string& name) {
|
||||
auto file = io::path("res:scripts") / name;
|
||||
@@ -28,9 +29,12 @@ static void load_script(const std::string& name) {
|
||||
lua::execute(lua::get_main_state(), 0, src, file.string());
|
||||
}
|
||||
|
||||
void scripting::on_frontend_init(Hud* hud, WorldRenderer* renderer) {
|
||||
void scripting::on_frontend_init(
|
||||
Hud* hud, WorldRenderer* renderer, PostProcessing* postProcessing
|
||||
) {
|
||||
scripting::hud = hud;
|
||||
scripting::renderer = renderer;
|
||||
scripting::post_processing = postProcessing;
|
||||
|
||||
auto L = lua::get_main_state();
|
||||
|
||||
@@ -39,6 +43,7 @@ void scripting::on_frontend_init(Hud* hud, WorldRenderer* renderer) {
|
||||
lua::openlib(L, "gfx", "particles", particleslib);
|
||||
lua::openlib(L, "gfx", "weather", weatherlib);
|
||||
lua::openlib(L, "gfx", "text3d", text3dlib);
|
||||
lua::openlib(L, "gfx", "posteffects", posteffectslib);
|
||||
|
||||
load_script("hud_classes.lua");
|
||||
|
||||
@@ -85,6 +90,7 @@ void scripting::on_frontend_close() {
|
||||
|
||||
scripting::renderer = nullptr;
|
||||
scripting::hud = nullptr;
|
||||
scripting::post_processing = nullptr;
|
||||
}
|
||||
|
||||
void scripting::load_hud_script(
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
class Hud;
|
||||
class WorldRenderer;
|
||||
class PostProcessing;
|
||||
|
||||
namespace gui {
|
||||
class UINode;
|
||||
@@ -18,8 +19,11 @@ namespace gui {
|
||||
namespace scripting {
|
||||
extern Hud *hud;
|
||||
extern WorldRenderer* renderer;
|
||||
extern PostProcessing* post_processing;
|
||||
|
||||
void on_frontend_init(Hud* hud, WorldRenderer* renderer);
|
||||
void on_frontend_init(
|
||||
Hud* hud, WorldRenderer* renderer, PostProcessing* postProcessing
|
||||
);
|
||||
void on_frontend_render();
|
||||
void on_frontend_close();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user