Skip to content

Commit

Permalink
fix(lua): Material:SetShader not resetting material state properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Silverlan committed Nov 1, 2024
1 parent 7edaed0 commit 857a5e8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ namespace pragma {
virtual bool IsUsingLightmaps() const override { return true; }
bool IsDepthPrepassEnabled() const;
void SetDepthPrepassEnabled(bool enabled) { m_depthPrepassEnabled = enabled; }
static std::shared_ptr<Texture> GetTexture(const std::string &texName);
static std::shared_ptr<Texture> GetTexture(const std::string &texName, bool load = false);
protected:
using ShaderEntity::RecordDraw;
GameShaderSpecializationConstantFlag GetStaticSpecializationConstantFlags(GameShaderSpecialization specialization) const;
Expand Down
18 changes: 14 additions & 4 deletions core/client/src/lua/c_luaclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,15 @@ static void reload_textures(CMaterial &mat)

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);
return std::visit(
[l](const auto &val) {
using T = util::base_type<decltype(val)>;
if constexpr(std::is_same_v<T, udm::Half>)
return luabind::object {l, static_cast<float>(val)};
else
return luabind::object {l, val};
},
val);
}

void ClientState::RegisterSharedLuaClasses(Lua::Interface &lua, bool bGUI)
Expand Down Expand Up @@ -224,11 +232,12 @@ void ClientState::RegisterSharedLuaClasses(Lua::Interface &lua, bool bGUI)
if(db == nullptr)
return;
auto shaderInfo = c_engine->GetShaderManager().PreRegisterShader(shader);
static_cast<CMaterial &>(mat).ClearDescriptorSets();
mat.Initialize(shaderInfo, db);
mat.SetUserData2(nullptr);
mat.SetLoaded(true);
auto shaderHandler = static_cast<msys::CMaterialManager &>(client->GetMaterialManager()).GetShaderHandler();
if(shaderHandler)
shaderHandler(&mat);
mat.UpdateTextures(true);
c_game->ReloadMaterialShader(static_cast<CMaterial *>(&mat));
}));
materialClassDef.def(
"GetPrimaryShader", +[](lua_State *l, ::Material &mat) -> luabind::object {
Expand Down Expand Up @@ -546,6 +555,7 @@ void ClientState::RegisterSharedLuaClasses(Lua::Interface &lua, bool bGUI)
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);
defShaderTextured3D.def("GetShaderMaterialName", &pragma::ShaderGameWorldLightingPass::GetShaderMaterialName);
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

0 comments on commit 857a5e8

Please sign in to comment.