Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #127

Merged
merged 5 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/lua/util/window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
]]

include("/gui/vbox.lua")
include("/gui/pfm/controls_menu.lua")
include("/gui/pfm/controls_menu/controls_menu.lua")

util.open_generic_window = function(title, onOpen)
time.create_simple_timer(0.0, function()
Expand Down
2 changes: 1 addition & 1 deletion build_scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ def download_addon(name,addonName,url,commitId=None):
curDir = os.getcwd()
if not skip_repository_updates:
if with_pfm:
download_addon("PFM","filmmaker","https://github.com/Silverlan/pfm.git","20135f7a0fff67acc4bca0bb6e4998e7fd1fdaf4")
download_addon("PFM","filmmaker","https://github.com/Silverlan/pfm.git","1f8c8420b29fee6dab6f459eb1ea9c282eb38c76")
download_addon("model editor","tool_model_editor","https://github.com/Silverlan/pragma_model_editor.git","bd4844c06b9a42bacd17bb7e52d3381c3fd119e4")

if with_vr:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ namespace pragma::rendering::shader_material {
}
const Property *FindProperty(const char *key) const { return const_cast<ShaderMaterial *>(this)->FindProperty(key); }

Texture *FindTexture(const char *key)
{
auto it = std::find_if(textures.begin(), textures.end(), [key](const Texture &tex) { return tex.name == key; });
if(it == textures.end())
return nullptr;
return &*it;
}
const Texture *FindTexture(const char *key) const { return const_cast<ShaderMaterial *>(this)->FindTexture(key); }

bool LoadFromUdmData(udm::LinkedPropertyWrapperArg prop, std::string &outErr);
std::string ToGlslStruct() const;
};
Expand Down
4 changes: 4 additions & 0 deletions core/client/src/c_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ void CEngine::DumpDebugInformation(uzip::ZIPFile &zip) const
if(GetClientState())
fWriteLuaTraceback(static_cast<ClientState *>(GetClientState())->GetGUILuaState(), "gui");

std::stringstream engineInfo;
engineInfo << "Render API: " << GetRenderAPI();
zip.AddFile("engine_cl.txt", engineInfo.str());

#if 0
prosper::debug::dump_layers(c_engine->GetRenderContext(),ss);
zip.AddFile("vk_layers.txt",ss.str());
Expand Down
94 changes: 93 additions & 1 deletion core/client/src/lua/c_luaclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include "pragma/rendering/shaders/util/c_shader_compose_rma.hpp"
#include "pragma/rendering/shaders/post_processing/c_shader_pp_glow.hpp"
#include "pragma/rendering/shader_material/shader_material.hpp"
#include "pragma/lua/libraries/ludm.hpp"
#include <pragma/lua/lua_entity_component.hpp>
#include <shader/prosper_pipeline_create_info.hpp>
#include <wgui/fontmanager.h>
Expand All @@ -66,6 +67,7 @@
#include <pragma/lua/converters/pair_converter_t.hpp>
#include <pragma/lua/converters/game_type_converters_t.hpp>
#include <pragma/lua/converters/optional_converter_t.hpp>
#include <pragma/lua/converters/vector_converter_t.hpp>
#include <pragma/entities/components/liquid/base_liquid_component.hpp>
#include <shader/prosper_shader_flip_image.hpp>
#include <prosper_prepared_command_buffer.hpp>
Expand Down Expand Up @@ -106,6 +108,11 @@ static void reload_textures(CMaterial &mat)
mat.SetTexture(pair.first, pair.second);
}

static luabind::object shader_mat_value_to_lua_object(lua_State *l, const pragma::rendering::shader_material::PropertyValue &val)
{
return std::visit([l](const auto &val) { return luabind::object {l, val}; }, val);
}

void ClientState::RegisterSharedLuaClasses(Lua::Interface &lua, bool bGUI)
{
auto &modEngine = lua.RegisterLibrary("engine");
Expand Down Expand Up @@ -223,6 +230,16 @@ void ClientState::RegisterSharedLuaClasses(Lua::Interface &lua, bool bGUI)
if(shaderHandler)
shaderHandler(&mat);
}));
materialClassDef.def(
"GetPrimaryShader", +[](lua_State *l, ::Material &mat) -> luabind::object {
auto *shader = static_cast<CMaterial &>(mat).GetPrimaryShader();
if(!shader)
return Lua::nil;
Lua::shader::push_shader(l, *shader);
auto o = luabind::object {luabind::from_stack(l, -1)};
Lua::Pop(l, 1);
return o;
});
modGame[materialClassDef];

// prosper TODO
Expand Down Expand Up @@ -298,6 +315,81 @@ void ClientState::RegisterSharedLuaClasses(Lua::Interface &lua, bool bGUI)
modShader[defBindState];

auto defMat = luabind::class_<pragma::rendering::shader_material::ShaderMaterial>("ShaderMaterial");
defMat.def(
"__tostring", +[](const pragma::rendering::shader_material::ShaderMaterial &shaderMat) -> std::string { return "ShaderMaterial"; });
defMat.def(
"FindProperty", +[](const pragma::rendering::shader_material::ShaderMaterial &shaderMat, const std::string &name) -> const pragma::rendering::shader_material::Property * { return shaderMat.FindProperty(name.c_str()); });
defMat.def(
"FindTexture", +[](const pragma::rendering::shader_material::ShaderMaterial &shaderMat, const std::string &name) -> const pragma::rendering::shader_material::Texture * { return shaderMat.FindTexture(name.c_str()); });
defMat.def(
"GetProperties", +[](const pragma::rendering::shader_material::ShaderMaterial &shaderMat) -> std::vector<const pragma::rendering::shader_material::Property *> {
std::vector<const pragma::rendering::shader_material::Property *> props;
props.reserve(shaderMat.properties.size());
for(auto &prop : shaderMat.properties)
props.push_back(&prop);
return props;
});
defMat.def(
"GetTextures", +[](const pragma::rendering::shader_material::ShaderMaterial &shaderMat) -> std::vector<const pragma::rendering::shader_material::Texture *> {
std::vector<const pragma::rendering::shader_material::Texture *> textures;
textures.reserve(shaderMat.textures.size());
for(auto &tex : shaderMat.textures)
textures.push_back(&tex);
return textures;
});

auto defProp = luabind::class_<pragma::rendering::shader_material::Property>("Property");
defProp.def(
"__tostring", +[](const pragma::rendering::shader_material::Property &prop) -> std::string {
std::stringstream ss;
ss << "Property";
ss << "[" << prop.name << "]";
ss << "[Type:" << magic_enum::enum_name(prop.type) << "]";
return ss.str();
});
defProp.def_readonly("type", &pragma::rendering::shader_material::Property::type);
defProp.property(
"specializationType", +[](const pragma::rendering::shader_material::Property &prop) -> std::optional<std::string> { return prop.specializationType ? *prop.specializationType : std::optional<std::string> {}; });
defProp.property(
"name", +[](const pragma::rendering::shader_material::Property &prop) -> std::string { return prop.name; });
defProp.property(
"defaultValue", +[](lua_State *l, const pragma::rendering::shader_material::Property &prop) -> luabind::object { return shader_mat_value_to_lua_object(l, prop.defaultValue); });
defProp.def_readonly("offset", &pragma::rendering::shader_material::Property::offset);
defProp.def("GetSize", &pragma::rendering::shader_material::Property::GetSize);
defProp.def(
"GetFlags", +[](const pragma::rendering::shader_material::Property &prop) -> std::optional<std::unordered_map<std::string, uint32_t>> {
if(!prop.flags)
return {};
return *prop.flags;
});
defProp.def(
"GetOptions", +[](lua_State *l, const pragma::rendering::shader_material::Property &prop) -> std::optional<std::unordered_map<std::string, luabind::object>> {
if(!prop.options)
return {};
std::unordered_map<std::string, luabind::object> options {};
options.reserve(prop.options->size());
for(auto &[name, value] : *prop.options)
options[name] = shader_mat_value_to_lua_object(l, value);
return options;
});
defMat.scope[defProp];

auto defTex = luabind::class_<pragma::rendering::shader_material::Texture>("Texture");
defTex.def(
"__tostring", +[](const pragma::rendering::shader_material::Texture &tex) -> std::string {
std::stringstream ss;
ss << "Texture";
ss << "[" << tex.name << "]";
return ss.str();
});
defTex.property(
"name", +[](const pragma::rendering::shader_material::Texture &tex) -> std::string { return tex.name; });
defTex.def_readonly("defaultTexturePath", &pragma::rendering::shader_material::Texture::defaultTexturePath);
defTex.def_readonly("cubemap", &pragma::rendering::shader_material::Texture::cubemap);
defTex.def_readonly("colorMap", &pragma::rendering::shader_material::Texture::colorMap);
defTex.def_readonly("required", &pragma::rendering::shader_material::Texture::required);
defMat.scope[defTex];

modShader[defMat];

auto defMatData = luabind::class_<pragma::rendering::shader_material::ShaderMaterialData>("ShaderMaterialData");
Expand Down Expand Up @@ -423,7 +515,7 @@ void ClientState::RegisterSharedLuaClasses(Lua::Interface &lua, bool bGUI)
auto defShaderTextured3D = luabind::class_<pragma::ShaderGameWorldLightingPass, luabind::bases<pragma::ShaderGameWorld, pragma::ShaderEntity, pragma::ShaderSceneLit, pragma::ShaderScene, prosper::ShaderGraphics, prosper::Shader>>("TexturedLit3D");
defShaderTextured3D.add_static_constant("PUSH_CONSTANTS_SIZE", sizeof(pragma::ShaderGameWorldLightingPass::PushConstants));
defShaderTextured3D.add_static_constant("PUSH_CONSTANTS_USER_DATA_OFFSET", sizeof(pragma::ShaderGameWorldLightingPass::PushConstants));

defShaderTextured3D.def("GetShaderMaterial", &pragma::ShaderGameWorldLightingPass::GetShaderMaterial);
modShader[defShaderTextured3D];

auto defShaderGlow = luabind::class_<pragma::ShaderPPGlow, luabind::bases<pragma::ShaderGameWorldLightingPass, pragma::ShaderEntity, pragma::ShaderSceneLit, pragma::ShaderScene, prosper::ShaderGraphics, prosper::Shader>>("Glow");
Expand Down
Loading