mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-09 02:07:04 +08:00
feat: water rendering (#13)
* refactor: update water texture * feat(gameplay): implement transparent block rendering with depth sorting * fix(world): use camera pos for distance calculations, make water passable * refactor(player): use ivec3 for block pass check * feat(camera): add underwater detection * feat(renderer): add underwater effect with framebuffer post-processing * feat(block): add gas property and refactor solid block check * fix(assets): set leaf block transparency to false * fix(block): set leaf as transparent
This commit is contained in:
@@ -42,14 +42,16 @@ struct BlockData {
|
||||
BlockType id = 0;
|
||||
|
||||
bool is_liquid = false;
|
||||
bool is_gas = false;
|
||||
|
||||
bool is_passable = false;
|
||||
bool is_cross_plane = false;
|
||||
bool is_transparent = false;
|
||||
BlockData(BlockType b_id, std::string_view b_name, bool liquid,
|
||||
bool passable, bool cross_plane, bool transparent)
|
||||
: name(b_name), id(b_id), is_liquid(liquid), is_passable(passable),
|
||||
is_cross_plane(cross_plane), is_transparent(transparent) {}
|
||||
bool passable, bool cross_plane, bool transparent, bool gas)
|
||||
: name(b_name), id(b_id), is_liquid(liquid), is_gas(gas),
|
||||
is_passable(passable), is_cross_plane(cross_plane),
|
||||
is_transparent(transparent) {}
|
||||
};
|
||||
|
||||
class BlockManager {
|
||||
@@ -61,6 +63,9 @@ public:
|
||||
static unsigned cross_plane_sum();
|
||||
static const std::string& name_form_id(BlockType id);
|
||||
|
||||
static bool is_gas(BlockType id);
|
||||
static bool is_liquid(BlockType id);
|
||||
|
||||
static bool is_cross_plane(BlockType id);
|
||||
static bool is_transparent(BlockType id);
|
||||
static bool is_passable(BlockType id);
|
||||
|
||||
@@ -23,6 +23,7 @@ private:
|
||||
std::atomic<bool> m_is_on_gen_vertex_data{false};
|
||||
std::atomic<size_t> m_normal_vertices_sum = 0;
|
||||
std::atomic<size_t> m_cross_vertices_sum = 0;
|
||||
std::atomic<size_t> m_transparent_vertices_sum = 0;
|
||||
std::atomic<BiomeType> m_biome = BiomeType::PLAIN;
|
||||
std::mutex m_vertexs_data_mutex;
|
||||
|
||||
@@ -35,8 +36,10 @@ private:
|
||||
std::vector<BlockType> m_blocks;
|
||||
GLuint m_normal_vbo = 0;
|
||||
GLuint m_cross_plane_vbo = 0;
|
||||
GLuint m_transparent_normal_vbo = 0;
|
||||
std::vector<Vertex> m_normal_vertices;
|
||||
std::vector<Vertex> m_cross_plane_vertices;
|
||||
std::vector<Vertex> m_transparent_normal_vertices;
|
||||
float frequency = 0.01f;
|
||||
float height = 80;
|
||||
unsigned m_seed = 0;
|
||||
@@ -100,9 +103,13 @@ public:
|
||||
|
||||
GLuint get_normal_vbo() const;
|
||||
size_t get_normal_vertices_sum() const;
|
||||
|
||||
GLuint get_cross_vbo() const;
|
||||
size_t get_cross_vertices_sum() const;
|
||||
|
||||
GLuint get_transparent_vbo() const;
|
||||
size_t get_transparent_vertices_sum() const;
|
||||
|
||||
bool is_dirty() const;
|
||||
void mark_dirty();
|
||||
|
||||
|
||||
@@ -104,6 +104,7 @@ public:
|
||||
|
||||
Gait& gait();
|
||||
GameMode& game_mode();
|
||||
const World& get_world() const;
|
||||
};
|
||||
|
||||
} // namespace Cubed
|
||||
|
||||
@@ -19,6 +19,8 @@ struct ChunkRenderSnapshot {
|
||||
size_t normal_vertices_count;
|
||||
GLuint cross_vbo;
|
||||
size_t cross_vertices_count;
|
||||
GLuint transparent_vbo;
|
||||
size_t transparent_vertices_count;
|
||||
glm::vec3 center;
|
||||
glm::vec3 half_extents;
|
||||
};
|
||||
@@ -92,14 +94,15 @@ public:
|
||||
const glm::vec3& half_extents);
|
||||
|
||||
int get_block(const glm::ivec3& block_pos) const;
|
||||
bool is_block(const glm::ivec3& block_pos) const;
|
||||
bool is_solid(const glm::ivec3& block_pos) const;
|
||||
bool can_pass_block(const glm::ivec3& block_pos) const;
|
||||
|
||||
BlockType get_block_tpye(const glm::ivec3& block_pos) const;
|
||||
static ChunkPos chunk_pos(int world_x, int world_z);
|
||||
|
||||
void need_gen();
|
||||
void render(const glm::mat4& mvp_matrix,
|
||||
const TextureManager& texture_manager);
|
||||
const TextureManager& texture_manager,
|
||||
const glm::vec3& camera_pos);
|
||||
|
||||
void set_block(const glm::ivec3& pos, unsigned id);
|
||||
void update(float delta_time);
|
||||
|
||||
Reference in New Issue
Block a user