add 'emission' argument to gfx.blockwraps.wrap

This commit is contained in:
MihailRis 2025-12-21 00:28:41 +03:00
parent dfdc7ebf6b
commit 4d950c974e
3 changed files with 13 additions and 6 deletions

View file

@ -57,7 +57,9 @@ void BlockWrapsRenderer::draw(BlockWrapper& wrapper, const Texture* texture) {
glm::vec4 light(1, 1, 1, 0); glm::vec4 light(1, 1, 1, 0);
if (wrapper.emission < 1.0f) { if (wrapper.emission < 1.0f) {
light = Lightmap::extractNormalized(chunks.getLight(wrapper.position)); light = Lightmap::extractNormalized(chunks.getLight(wrapper.position));
light = wrapper.emission + (1.0f - light); light.r += wrapper.emission;
light.g += wrapper.emission;
light.b += wrapper.emission;
} }
switch (wrapper.modelType) { switch (wrapper.modelType) {
case BlockModelType::BLOCK: case BlockModelType::BLOCK:
@ -150,11 +152,13 @@ void BlockWrapsRenderer::draw(const DrawContext& pctx, const Player& player) {
} }
u64id_t BlockWrapsRenderer::add( u64id_t BlockWrapsRenderer::add(
const glm::ivec3& position, const std::string& texture const glm::ivec3& position, const std::string& texture, float emission
) { ) {
u64id_t id = nextWrapper++; u64id_t id = nextWrapper++;
wrappers[id] = std::make_unique<BlockWrapper>(BlockWrapper { wrappers[id] = std::make_unique<BlockWrapper>(BlockWrapper {
position, {texture, texture, texture, texture, texture, texture}}); position,
{texture, texture, texture, texture, texture, texture},
emission});
return id; return id;
} }

View file

@ -22,7 +22,7 @@ class DrawContext;
struct BlockWrapper { struct BlockWrapper {
glm::ivec3 position; glm::ivec3 position;
std::array<std::string, 6> textureFaces {}; std::array<std::string, 6> textureFaces {};
float emission = 1.0f; float emission = 0.0f;
// --- render cache --- // --- render cache ---
util::TextureRegion texRegions[6] {}; util::TextureRegion texRegions[6] {};
@ -53,7 +53,9 @@ public:
void draw(const DrawContext& ctx, const Player& player); void draw(const DrawContext& ctx, const Player& player);
u64id_t add(const glm::ivec3& position, const std::string& texture); u64id_t add(
const glm::ivec3& position, const std::string& texture, float emission
);
BlockWrapper* get(u64id_t id) const; BlockWrapper* get(u64id_t id) const;

View file

@ -9,9 +9,10 @@ using namespace scripting;
static int l_wrap(lua::State* L) { static int l_wrap(lua::State* L) {
auto position = lua::tovec3(L, 1); auto position = lua::tovec3(L, 1);
std::string texture = lua::require_string(L, 2); std::string texture = lua::require_string(L, 2);
float emission = lua::isnumber(L, 3) ? lua::tonumber(L, 3) : 1.0f;
return lua::pushinteger( return lua::pushinteger(
L, renderer->blockWraps->add(position, std::move(texture)) L, renderer->blockWraps->add(position, std::move(texture), emission)
); );
} }