mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-06-22 02:27:01 +08:00
feat: pbr (#20)
* feat: add pbr texture * feat(rendering): add normal mapping support for blocks * fix: normal map load * feat(scripts): add batch nearest neighbor upscale script
This commit is contained in:
@@ -136,6 +136,50 @@ constexpr float NORMALS[6][6][3] = {
|
||||
{0.0f, -1.0f, 0.0f},
|
||||
{0.0f, -1.0f, 0.0f}}};
|
||||
|
||||
constexpr float TANGENTS[6][6][3] = {
|
||||
// ===== front (z = +1) =====
|
||||
{{1.0f, 0.0f, 0.0f},
|
||||
{1.0f, 0.0f, 0.0f},
|
||||
{1.0f, 0.0f, 0.0f},
|
||||
{1.0f, 0.0f, 0.0f},
|
||||
{1.0f, 0.0f, 0.0f},
|
||||
{1.0f, 0.0f, 0.0f}},
|
||||
// ===== right (x = +1) =====
|
||||
{{0.0f, 0.0f, -1.0f},
|
||||
{0.0f, 0.0f, -1.0f},
|
||||
{0.0f, 0.0f, -1.0f},
|
||||
{0.0f, 0.0f, -1.0f},
|
||||
{0.0f, 0.0f, -1.0f},
|
||||
{0.0f, 0.0f, -1.0f}},
|
||||
// ===== back (z = -1) =====
|
||||
{{-1.0f, 0.0f, 0.0f},
|
||||
{-1.0f, 0.0f, 0.0f},
|
||||
{-1.0f, 0.0f, 0.0f},
|
||||
{-1.0f, 0.0f, 0.0f},
|
||||
{-1.0f, 0.0f, 0.0f},
|
||||
{-1.0f, 0.0f, 0.0f}},
|
||||
// ===== left (x = -1) =====
|
||||
{{0.0f, 0.0f, 1.0f},
|
||||
{0.0f, 0.0f, 1.0f},
|
||||
{0.0f, 0.0f, 1.0f},
|
||||
{0.0f, 0.0f, 1.0f},
|
||||
{0.0f, 0.0f, 1.0f},
|
||||
{0.0f, 0.0f, 1.0f}},
|
||||
// ===== top (y = +1) =====
|
||||
{{1.0f, 0.0f, 0.0f},
|
||||
{1.0f, 0.0f, 0.0f},
|
||||
{1.0f, 0.0f, 0.0f},
|
||||
{1.0f, 0.0f, 0.0f},
|
||||
{1.0f, 0.0f, 0.0f},
|
||||
{1.0f, 0.0f, 0.0f}},
|
||||
// ===== bottom (y = -1) =====
|
||||
{{1.0f, 0.0f, 0.0f},
|
||||
{1.0f, 0.0f, 0.0f},
|
||||
{1.0f, 0.0f, 0.0f},
|
||||
{1.0f, 0.0f, 0.0f},
|
||||
{1.0f, 0.0f, 0.0f},
|
||||
{1.0f, 0.0f, 0.0f}}};
|
||||
|
||||
#pragma endregion
|
||||
constexpr float CUBE_VER[24] = {0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0,
|
||||
0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0,
|
||||
@@ -211,6 +255,22 @@ constexpr float CROSS_NORMALS[2][6][3] = {
|
||||
{0.0f, 1.0f, 0.0f},
|
||||
{0.0f, 1.0f, 0.0f}}};
|
||||
|
||||
constexpr float CROSS_TANGENTS[2][6][3] = {
|
||||
// ===== Plane 1 =====
|
||||
{{0.7071f, 0.0f, 0.7071f},
|
||||
{0.7071f, 0.0f, 0.7071f},
|
||||
{0.7071f, 0.0f, 0.7071f},
|
||||
{0.7071f, 0.0f, 0.7071f},
|
||||
{0.7071f, 0.0f, 0.7071f},
|
||||
{0.7071f, 0.0f, 0.7071f}},
|
||||
// ===== Plane 2 =====
|
||||
{{-0.7071f, 0.0f, 0.7071f},
|
||||
{-0.7071f, 0.0f, 0.7071f},
|
||||
{-0.7071f, 0.0f, 0.7071f},
|
||||
{-0.7071f, 0.0f, 0.7071f},
|
||||
{-0.7071f, 0.0f, 0.7071f},
|
||||
{-0.7071f, 0.0f, 0.7071f}}};
|
||||
|
||||
#pragma endregion
|
||||
// [-1, 1]
|
||||
constexpr float QUAD_VERTICES[] = {
|
||||
@@ -225,6 +285,7 @@ struct Vertex3D {
|
||||
float layer = 0.0f;
|
||||
float nx = 0.0f, ny = 0.0f, nz = 0.0f;
|
||||
float roughness = 1.0f;
|
||||
float tx = 0.0f, ty = 0.0f, tz = 0.0f;
|
||||
};
|
||||
|
||||
struct Vertex2D {
|
||||
|
||||
@@ -34,6 +34,8 @@ public:
|
||||
bool& shader_on();
|
||||
bool& water_perturb();
|
||||
bool& water_depth_fade();
|
||||
bool& pbr();
|
||||
bool& flip_y();
|
||||
int& shadow_mode();
|
||||
int& light_cull_face();
|
||||
int& light_size_uv();
|
||||
@@ -95,6 +97,8 @@ private:
|
||||
bool m_shader_on = true;
|
||||
bool m_water_perturb = true;
|
||||
bool m_water_depth_fade = true;
|
||||
bool m_pbr = true;
|
||||
bool m_flip_y = false;
|
||||
int m_shadow_mode = 0;
|
||||
int m_light_cull_face = 0;
|
||||
float m_aspect = 0.0f;
|
||||
|
||||
@@ -12,7 +12,9 @@ private:
|
||||
GLuint m_texture_array = 0;
|
||||
GLuint m_cross_plane_array = 0;
|
||||
GLuint m_ui_array = 0;
|
||||
GLuint m_pbr_texture_array = 0;
|
||||
GLfloat m_max_aniso = 0.0f;
|
||||
|
||||
int m_aniso = 1;
|
||||
|
||||
std::vector<GLuint> m_item_textures;
|
||||
@@ -22,6 +24,7 @@ private:
|
||||
void load_block_item_texture(unsigned id);
|
||||
void load_cross_plane_texture(unsigned id);
|
||||
void load_ui_texture(unsigned id);
|
||||
void load_pbr_texture(unsigned id);
|
||||
void init_item();
|
||||
void init_block();
|
||||
void init_ui();
|
||||
@@ -36,6 +39,7 @@ public:
|
||||
GLuint get_texture_array() const;
|
||||
GLuint get_cross_plane_array() const;
|
||||
GLuint get_ui_array() const;
|
||||
GLuint get_pbr_texture() const;
|
||||
const std::vector<GLuint>& item_textures() const;
|
||||
// Must call after MapTable::init_map() and glfwMakeContextCurrent(window);
|
||||
void init_texture();
|
||||
|
||||
@@ -14,7 +14,8 @@ void print_program_info(int prog);
|
||||
bool check_opengl_error();
|
||||
std::string read_shader_source(const std::string& file_path);
|
||||
void delete_image_data(unsigned char* data);
|
||||
unsigned char* load_image_data(const std::string& tex_image_path);
|
||||
unsigned char* load_image_data(const std::string& tex_image_path,
|
||||
bool check_exist = true);
|
||||
|
||||
} // namespace Tools
|
||||
|
||||
|
||||
Reference in New Issue
Block a user