Skip to content

Commit

Permalink
[material] some more work towards texture packing
Browse files Browse the repository at this point in the history
  • Loading branch information
PanosK92 committed Nov 13, 2024
1 parent f10fcd6 commit 1ad054b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
1 change: 1 addition & 0 deletions data/shaders/common_textures_storage.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ static const uint material_texture_index_occlusion = 4 * material_texture_type_s
static const uint material_texture_index_emission = 5 * material_texture_type_slots_max;
static const uint material_texture_index_height = 6 * material_texture_type_slots_max;
static const uint material_texture_index_mask = 7 * material_texture_type_slots_max;
static const uint material_texture_index_packed = 8 * material_texture_type_slots_max;

// easy access macro
#define GET_TEXTURE(index_texture) tex_materials[pass_get_material_index() + index_texture]
Expand Down
45 changes: 33 additions & 12 deletions runtime/Rendering/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "../Resource/ResourceCache.h"
#include "../RHI/RHI_Texture.h"
#include "../World/World.h"
#include "../Core/ThreadPool.h"
SP_WARNINGS_OFF
#include "../IO/pugixml.hpp"
SP_WARNINGS_ON
Expand Down Expand Up @@ -85,14 +84,13 @@ namespace Spartan
namespace texture_packing
{
void pack_occlusion_roughness_metalness_height(
vector<byte>& occlusion,
const vector<byte>& occlusion,
const vector<byte>& roughness,
const vector<byte>& metalness,
const vector<byte>& height
const vector<byte>& height,
vector<byte>& output
)
{
vector<byte>& output = occlusion;

size_t size = max(max(occlusion.size(), roughness.size()), max(metalness.size(), height.size()));
for (size_t i = 0; i < size; i += 4)
{
Expand Down Expand Up @@ -349,16 +347,39 @@ namespace Spartan

// step 2: pack occlusion, roughness, metalness, and height into a single texture
{
//vector<byte> empty;
//RHI_Texture* texture = nullptr;
//// try to get the texture (in case it's already packed)
//const string tex_name = GetObjectName() + "_packed";
//shared_ptr<RHI_Texture> texture = ResourceCache::GetByName<RHI_Texture>(tex_name);
//
//texture_packing::pack_occlusion_roughness_metalness_height(
// texture_occlusion ? texture_occlusion->GetMip(0, 0).bytes : empty,
// texture_roughness ? texture_roughness->GetMip(0, 0).bytes : empty,
// texture_metalness ? texture_metalness->GetMip(0, 0).bytes : empty,
// texture_height ? texture_height->GetMip(0, 0).bytes : empty
//if (!texture)
//{
// // create packed texture
// texture = make_shared<RHI_Texture>
// (
// RHI_Texture_Type::Type2D,
// texture_color->GetWidth(),
// texture_color->GetHeight(),
// texture_color->GetDepth(),
// texture_color->GetMipCount(),
// texture_color->GetFormat(),
// RHI_Texture_Srv | RHI_Texture_Compress | RHI_Texture_DontPrepareForGpu,
// "packed"
// );
// texture->AllocateMip();
// ResourceCache::Cache<RHI_Texture>(texture);
//
// // create packed data
// vector<byte> empty;
// texture_packing::pack_occlusion_roughness_metalness_height(
// texture_occlusion ? texture_occlusion->GetMip(0, 0).bytes : empty,
// texture_roughness ? texture_roughness->GetMip(0, 0).bytes : empty,
// texture_metalness ? texture_metalness->GetMip(0, 0).bytes : empty,
// texture_height ? texture_height->GetMip(0, 0).bytes : empty,
// texture->GetMip(0, 0).bytes
// );
//}
//
//// set the packed texture
//SetTexture(MaterialTextureType::Packed, texture);
//SetTexture(MaterialTextureType::Occlusion, nullptr);
//SetTexture(MaterialTextureType::Roughness, nullptr);
Expand Down

0 comments on commit 1ad054b

Please sign in to comment.