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:
zhenyan121
2026-06-20 15:03:40 +08:00
committed by GitHub
parent a8d2ddbacd
commit 5385876a8a
52 changed files with 462 additions and 65 deletions

View File

@@ -118,16 +118,31 @@ std::string read_shader_source(const std::string& file_path) {
return content;
}
void delete_image_data(unsigned char* data) { SOIL_free_image_data(data); }
void delete_image_data(unsigned char* data) {
if (data == nullptr) {
return;
}
SOIL_free_image_data(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) {
fs::path path = ASSETS_PATH + tex_image_path;
ASSERT_MSG(fs::is_regular_file(path), path.c_str());
if (check_exist) {
ASSERT_MSG(fs::is_regular_file(path), path.c_str());
}
unsigned char* data = nullptr;
int width, height, channels;
data = SOIL_load_image(path.string().c_str(), &width, &height, &channels,
SOIL_LOAD_AUTO);
ASSERT_MSG(data, "Could not load texture" + path.string());
data =
SOIL_load_image(path.string().c_str(), &width, &height, &channels,
SOIL_LOAD_RGBA); // Materials are all RGBA; must force
// RGBA, otherwise sampling will fail.
if (check_exist) {
if (!data) {
ASSERT_MSG(data, "Could not load texture" + path.string());
std::abort();
}
}
return data;
}