Grass rendering behing water fix
This commit is contained in:
@@ -18,22 +18,27 @@ void ContentBuilder::add(Block* def) {
|
|||||||
|
|
||||||
Content* ContentBuilder::build() {
|
Content* ContentBuilder::build() {
|
||||||
vector<Block*> blockDefsIndices;
|
vector<Block*> blockDefsIndices;
|
||||||
|
DrawGroups* groups = new DrawGroups;
|
||||||
for (const string& name : blockIds) {
|
for (const string& name : blockIds) {
|
||||||
Block* def = blockDefs[name];
|
Block* def = blockDefs[name];
|
||||||
def->id = blockDefsIndices.size();
|
def->id = blockDefsIndices.size();
|
||||||
blockDefsIndices.push_back(def);
|
blockDefsIndices.push_back(def);
|
||||||
|
if (groups->find(def->drawGroup) == groups->end()) {
|
||||||
|
groups->insert(def->drawGroup);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ContentIndices* indices = new ContentIndices(blockDefsIndices);
|
ContentIndices* indices = new ContentIndices(blockDefsIndices);
|
||||||
return new Content(indices, blockDefs);
|
return new Content(indices, groups, blockDefs);
|
||||||
}
|
}
|
||||||
|
|
||||||
ContentIndices::ContentIndices(vector<Block*> blockDefs)
|
ContentIndices::ContentIndices(vector<Block*> blockDefs)
|
||||||
: blockDefs(blockDefs) {
|
: blockDefs(blockDefs) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Content::Content(ContentIndices* indices,
|
Content::Content(ContentIndices* indices, DrawGroups* drawGroups,
|
||||||
unordered_map<string, Block*> blockDefs)
|
unordered_map<string, Block*> blockDefs)
|
||||||
: blockDefs(blockDefs),
|
: blockDefs(blockDefs),
|
||||||
|
drawGroups(drawGroups),
|
||||||
indices(indices) {
|
indices(indices) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,11 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include <set>
|
||||||
#include "../typedefs.h"
|
#include "../typedefs.h"
|
||||||
|
|
||||||
|
typedef std::set<unsigned char> DrawGroups;
|
||||||
|
|
||||||
class Block;
|
class Block;
|
||||||
class Content;
|
class Content;
|
||||||
|
|
||||||
@@ -46,8 +49,9 @@ class Content {
|
|||||||
std::unordered_map<std::string, Block*> blockDefs;
|
std::unordered_map<std::string, Block*> blockDefs;
|
||||||
public:
|
public:
|
||||||
ContentIndices* const indices;
|
ContentIndices* const indices;
|
||||||
|
DrawGroups* const drawGroups;
|
||||||
Content(ContentIndices* indices,
|
|
||||||
|
Content(ContentIndices* indices, DrawGroups* drawGroups,
|
||||||
std::unordered_map<std::string, Block*> blockDefs);
|
std::unordered_map<std::string, Block*> blockDefs);
|
||||||
~Content();
|
~Content();
|
||||||
|
|
||||||
|
|||||||
+3
-4
@@ -9,7 +9,6 @@
|
|||||||
// All in-game definitions (blocks, items, etc..)
|
// All in-game definitions (blocks, items, etc..)
|
||||||
void setup_definitions(ContentBuilder* builder) {
|
void setup_definitions(ContentBuilder* builder) {
|
||||||
Block* block = new Block("core:air", "air");
|
Block* block = new Block("core:air", "air");
|
||||||
block->drawGroup = 1;
|
|
||||||
block->lightPassing = true;
|
block->lightPassing = true;
|
||||||
block->skyLightPassing = true;
|
block->skyLightPassing = true;
|
||||||
block->obstacle = false;
|
block->obstacle = false;
|
||||||
@@ -52,7 +51,7 @@ void setup_definitions(ContentBuilder* builder) {
|
|||||||
builder->add(block);
|
builder->add(block);
|
||||||
|
|
||||||
block = new Block("base:water", "water");
|
block = new Block("base:water", "water");
|
||||||
block->drawGroup = 4;
|
block->drawGroup = 3;
|
||||||
block->lightPassing = true;
|
block->lightPassing = true;
|
||||||
block->skyLightPassing = false;
|
block->skyLightPassing = false;
|
||||||
block->obstacle = false;
|
block->obstacle = false;
|
||||||
@@ -67,7 +66,7 @@ void setup_definitions(ContentBuilder* builder) {
|
|||||||
builder->add(block);
|
builder->add(block);
|
||||||
|
|
||||||
block = new Block("base:grass", "grass");
|
block = new Block("base:grass", "grass");
|
||||||
block->drawGroup = 5;
|
block->drawGroup = 1;
|
||||||
block->lightPassing = true;
|
block->lightPassing = true;
|
||||||
block->obstacle = false;
|
block->obstacle = false;
|
||||||
block->model = BlockModel::xsprite;
|
block->model = BlockModel::xsprite;
|
||||||
@@ -75,7 +74,7 @@ void setup_definitions(ContentBuilder* builder) {
|
|||||||
builder->add(block);
|
builder->add(block);
|
||||||
|
|
||||||
block = new Block("base:flower", "flower");
|
block = new Block("base:flower", "flower");
|
||||||
block->drawGroup = 5;
|
block->drawGroup = 1;
|
||||||
block->lightPassing = true;
|
block->lightPassing = true;
|
||||||
block->obstacle = false;
|
block->obstacle = false;
|
||||||
block->model = BlockModel::xsprite;
|
block->model = BlockModel::xsprite;
|
||||||
|
|||||||
@@ -317,12 +317,12 @@ vec4 BlocksRenderer::pickSoftLight(int x, int y, int z, const ivec3& right, cons
|
|||||||
void BlocksRenderer::render(const voxel* voxels, int atlas_size) {
|
void BlocksRenderer::render(const voxel* voxels, int atlas_size) {
|
||||||
int begin = chunk->bottom * (CHUNK_W * CHUNK_D);
|
int begin = chunk->bottom * (CHUNK_W * CHUNK_D);
|
||||||
int end = chunk->top * (CHUNK_W * CHUNK_D);
|
int end = chunk->top * (CHUNK_W * CHUNK_D);
|
||||||
for (ubyte group = 0; group < 8; group++) {
|
for (const auto drawGroup : *content->drawGroups) {
|
||||||
for (int i = begin; i < end; i++) {
|
for (int i = begin; i < end; i++) {
|
||||||
const voxel& vox = voxels[i];
|
const voxel& vox = voxels[i];
|
||||||
blockid_t id = vox.id;
|
blockid_t id = vox.id;
|
||||||
const Block& def = *blockDefsCache[id];
|
const Block& def = *blockDefsCache[id];
|
||||||
if (!id || def.drawGroup != group)
|
if (!id || def.drawGroup != drawGroup)
|
||||||
continue;
|
continue;
|
||||||
const UVRegion texfaces[6]{ cache->getRegion(id, 0), cache->getRegion(id, 1),
|
const UVRegion texfaces[6]{ cache->getRegion(id, 0), cache->getRegion(id, 1),
|
||||||
cache->getRegion(id, 2), cache->getRegion(id, 3),
|
cache->getRegion(id, 2), cache->getRegion(id, 3),
|
||||||
|
|||||||
Reference in New Issue
Block a user