emissive items
This commit is contained in:
parent
213eba6072
commit
05fe86e64c
@ -92,9 +92,10 @@ Content* ContentBuilder::build() {
|
||||
std::vector<ItemDef*> itemDefsIndices;
|
||||
for (const std::string& name : itemIds) {
|
||||
ItemDef* def = itemDefs[name];
|
||||
|
||||
|
||||
// Generating runtime info
|
||||
def->rt.id = itemDefsIndices.size();
|
||||
def->rt.emissive = *((uint32_t*)def->emission);
|
||||
itemDefsIndices.push_back(def);
|
||||
}
|
||||
|
||||
|
||||
@ -234,6 +234,14 @@ void ContentLoader::loadItem(ItemDef* def, std::string name, fs::path file) {
|
||||
}
|
||||
root->str("icon", def->icon);
|
||||
root->str("placing-block", def->placingBlock);
|
||||
|
||||
// item light emission [r, g, b] where r,g,b in range [0..15]
|
||||
json::JArray* emissionobj = root->arr("emission");
|
||||
if (emissionobj) {
|
||||
def->emission[0] = emissionobj->num(0);
|
||||
def->emission[1] = emissionobj->num(1);
|
||||
def->emission[2] = emissionobj->num(2);
|
||||
}
|
||||
}
|
||||
|
||||
void ContentLoader::loadBlock(Block* def, std::string full, std::string name) {
|
||||
@ -281,6 +289,10 @@ void ContentLoader::load(ContentBuilder* builder) {
|
||||
item->iconType = item_icon_type::block;
|
||||
item->icon = full;
|
||||
item->placingBlock = full;
|
||||
|
||||
for (uint j = 0; j < 4; j++) {
|
||||
item->emission[j] = def->emission[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,6 +27,7 @@
|
||||
#include "../maths/voxmaths.h"
|
||||
#include "../settings.h"
|
||||
#include "../engine.h"
|
||||
#include "../items/ItemDef.h"
|
||||
#include "LevelFrontend.h"
|
||||
#include "graphics/Skybox.h"
|
||||
|
||||
@ -168,14 +169,14 @@ void WorldRenderer::draw(const GfxContext& pctx, Camera* camera){
|
||||
shader->uniform3f("u_cameraPos", camera->position);
|
||||
shader->uniform1i("u_cubemap", 1);
|
||||
{
|
||||
blockid_t id = level->player->getChosenItem();
|
||||
Block* block = contentIds->getBlockDef(id);
|
||||
assert(block != nullptr);
|
||||
itemid_t id = level->player->getChosenItem();
|
||||
ItemDef* item = contentIds->getItemDef(id);
|
||||
assert(item != nullptr);
|
||||
float multiplier = 0.5f;
|
||||
shader->uniform3f("u_torchlightColor",
|
||||
block->emission[0] / 15.0f * multiplier,
|
||||
block->emission[1] / 15.0f * multiplier,
|
||||
block->emission[2] / 15.0f * multiplier);
|
||||
shader->uniform3f("u_torchlightColor",
|
||||
item->emission[0] / 15.0f * multiplier,
|
||||
item->emission[1] / 15.0f * multiplier,
|
||||
item->emission[2] / 15.0f * multiplier);
|
||||
shader->uniform1f("u_torchlightDistance", 6.0f);
|
||||
}
|
||||
|
||||
|
||||
@ -21,6 +21,7 @@ public:
|
||||
std::string const name;
|
||||
|
||||
bool generated = false;
|
||||
uint8_t emission[4] {0, 0, 0, 0};
|
||||
|
||||
item_icon_type iconType = item_icon_type::sprite;
|
||||
std::string icon = "block:notfound";
|
||||
@ -31,6 +32,7 @@ public:
|
||||
itemid_t id;
|
||||
item_funcs_set funcsset {};
|
||||
blockid_t placingBlock;
|
||||
bool emissive = false;
|
||||
} rt;
|
||||
|
||||
ItemDef(std::string name);
|
||||
|
||||
@ -80,7 +80,7 @@ public:
|
||||
std::vector<BoxModel> modelBoxes = {};
|
||||
std::vector<glm::vec3> modelExtraPoints = {}; //initially made for tetragons
|
||||
std::vector<UVRegion> modelUVs = {}; // boxes' tex-UVs also there
|
||||
unsigned char emission[4] {0, 0, 0, 0};
|
||||
uint8_t emission[4] {0, 0, 0, 0};
|
||||
unsigned char drawGroup = 0;
|
||||
BlockModel model = BlockModel::block;
|
||||
bool lightPassing = false;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user