Skip to content

Commit

Permalink
Use stored mips in PT
Browse files Browse the repository at this point in the history
  • Loading branch information
sergcpp committed Nov 27, 2024
1 parent 7869086 commit 9a898b8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/actions/test-img/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ runs:
./${{ inputs.bin-name }} ${{ inputs.test-args }} -s scenes/bistro.json -ref references/bistro_night_cycles.uncompressed.png -w 1920 -h 1080 --sun_dir 0 1 0 --exposure 3.25 --preset ultra --psnr 21.85 --freeze-sky --no-postprocess --tex-budget 1024
mv bistro.png bistro_night_ultra.png
cp bistro_night_ultra.png $WORK_DIR/${{ inputs.out-dir }}
./${{ inputs.bin-name }} ${{ inputs.test-args }} -s scenes/bistro.json -ref references/bistro_night_cycles2.uncompressed.png -w 960 -h 540 --sun_dir 0 1 0 --exposure 3.25 --pt --psnr 26.65 --freeze-sky --no-postprocess
./${{ inputs.bin-name }} ${{ inputs.test-args }} -s scenes/bistro.json -ref references/bistro_night_cycles2.uncompressed.png -w 960 -h 540 --sun_dir 0 1 0 --exposure 3.25 --pt --psnr 26.35 --freeze-sky --no-postprocess
mv bistro.png bistro_night_pt.png
cp bistro_night_pt.png $WORK_DIR/${{ inputs.out-dir }}
### Coffee maker
Expand Down
11 changes: 7 additions & 4 deletions src/DummyLib/states/GSBaseState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1375,15 +1375,16 @@ void GSBaseState::InitScene_PT() {
std::map<std::string, Ray::MaterialHandle> loaded_materials;
std::map<std::string, Ray::TextureHandle> loaded_textures;

auto load_texture = [&](const Ren::Texture2D &tex, const bool is_srgb = false, const bool is_YCoCg = false) {
auto load_texture = [&](const Ren::Texture2D &tex, const bool is_srgb = false, const bool is_YCoCg = false,
const bool use_mips = true) {
if (tex.name() == "default_basecolor.dds" || tex.name() == "default_normalmap.dds" ||
tex.name() == "default_roughness.dds" || tex.name() == "default_metallic.dds" ||
tex.name() == "default_opacity.dds") {
return Ray::InvalidTextureHandle;
}
auto tex_it = loaded_textures.find(tex.name().c_str());
if (tex_it == loaded_textures.end()) {
const Ray::TextureHandle new_tex = LoadTexture_PT(tex.name().c_str(), is_srgb, is_YCoCg);
const Ray::TextureHandle new_tex = LoadTexture_PT(tex.name().c_str(), is_srgb, is_YCoCg, use_mips);
tex_it = loaded_textures.emplace(tex.name().c_str(), new_tex).first;
}
return tex_it->second;
Expand Down Expand Up @@ -1470,7 +1471,7 @@ void GSBaseState::InitScene_PT() {
if (front_mat->textures.size() > 5) {
mat_desc.emission_texture = load_texture(*front_mat->textures[5], true, true);
}
mat_desc.normal_map = load_texture(*front_mat->textures[1]);
mat_desc.normal_map = load_texture(*front_mat->textures[1], false, false, false);

const Ray::MaterialHandle new_mat = ray_scene_->AddMaterial(mat_desc);
mat_it = loaded_materials.emplace(mat_name, new_mat).first;
Expand Down Expand Up @@ -1617,7 +1618,8 @@ void GSBaseState::InitScene_PT() {
ray_scene_->Finalize(std::bind(&Sys::ThreadPool::ParallelFor<Ray::ParallelForFunction>, threads_, _1, _2, _3));
}

Ray::TextureHandle GSBaseState::LoadTexture_PT(const std::string_view name, const bool is_srgb, const bool is_YCoCg) {
Ray::TextureHandle GSBaseState::LoadTexture_PT(const std::string_view name, const bool is_srgb, const bool is_YCoCg,
const bool use_mips) {
const std::string tex_path = std::string("assets_pc/textures/") + std::string(name);
std::ifstream in_file(tex_path, std::ios::binary);

Expand Down Expand Up @@ -1646,6 +1648,7 @@ Ray::TextureHandle GSBaseState::LoadTexture_PT(const std::string_view name, cons
}
tex_desc.w = temp_params.w;
tex_desc.h = temp_params.h;
tex_desc.mips_count = use_mips ? temp_params.mip_count : 1;
tex_desc.name = name.data();
tex_desc.is_srgb = is_srgb;
tex_desc.is_YCoCg = is_YCoCg;
Expand Down
2 changes: 1 addition & 1 deletion src/DummyLib/states/GSBaseState.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class GSBaseState : public Eng::ViewerState {

void InitRenderer_PT();
void InitScene_PT();
Ray::TextureHandle LoadTexture_PT(std::string_view name, bool is_srgb, bool is_YCoCg);
Ray::TextureHandle LoadTexture_PT(std::string_view name, bool is_srgb, bool is_YCoCg, bool use_mips);
void SetupView_PT(const Ren::Vec3f &origin, const Ren::Vec3f &fwd, const Ren::Vec3f &up, float fov);
void Clear_PT();
void Draw_PT(const Ren::Tex2DRef &target);
Expand Down

0 comments on commit 9a898b8

Please sign in to comment.