From 3be76495b46b7c2c286a183fb50b837c7f72cab6 Mon Sep 17 00:00:00 2001 From: Turanszki Janos Date: Tue, 2 Feb 2021 22:07:47 +0100 Subject: [PATCH] big material texture slot refactor --- Editor/MaterialWindow.cpp | 948 +++--------------- Editor/MaterialWindow.h | 51 +- Editor/ModelImporter_GLTF.cpp | 78 +- Editor/ModelImporter_OBJ.cpp | 33 +- Editor/PaintToolWindow.cpp | 95 +- WickedEngine/objectHF.hlsli | 10 +- WickedEngine/wiEmittedParticle.cpp | 9 +- WickedEngine/wiGPUBVH.cpp | 32 +- .../wiGraphicsDevice_SharedInternals.h | 5 +- WickedEngine/wiHairParticle.cpp | 23 +- WickedEngine/wiRenderer.cpp | 92 +- WickedEngine/wiScene.cpp | 210 +--- WickedEngine/wiScene.h | 99 +- WickedEngine/wiScene_Serializers.cpp | 171 +--- WickedEngine/wiVersion.cpp | 2 +- 15 files changed, 425 insertions(+), 1433 deletions(-) diff --git a/Editor/MaterialWindow.cpp b/Editor/MaterialWindow.cpp index c1ed29c20..dd963cb83 100644 --- a/Editor/MaterialWindow.cpp +++ b/Editor/MaterialWindow.cpp @@ -425,7 +425,7 @@ void MaterialWindow::Create(EditorComponent* editor) editor->RefreshSceneGraphView(); } - }); + }); AddWidget(&materialNameField); newMaterialButton.Create("New Material"); @@ -438,750 +438,132 @@ void MaterialWindow::Create(EditorComponent* editor) editor->AddSelected(entity); editor->RefreshSceneGraphView(); SetEntity(entity); - }); + }); AddWidget(&newMaterialButton); - texture_baseColor_Label.Create("BaseColorMap: "); - texture_baseColor_Label.SetPos(XMFLOAT2(x, y += step)); - texture_baseColor_Label.SetSize(XMFLOAT2(120, 20)); - AddWidget(&texture_baseColor_Label); - - texture_baseColor_Button.Create("BaseColor"); - texture_baseColor_Button.SetText(""); - texture_baseColor_Button.SetTooltip("Load the basecolor texture. RGB: Albedo Base Color, A: Opacity"); - texture_baseColor_Button.SetPos(XMFLOAT2(x + 122, y)); - texture_baseColor_Button.SetSize(XMFLOAT2(260, 20)); - texture_baseColor_Button.OnClick([&](wiEventArgs args) { - MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); - if (material == nullptr) - return; - - if (material->baseColorMap != nullptr) - { - material->baseColorMap = nullptr; - material->baseColorMapName = ""; - material->SetDirty(); - texture_baseColor_Button.SetText(""); - } - else - { - wiHelper::FileDialogParams params; - params.type = wiHelper::FileDialogParams::OPEN; - params.description = "Texture"; - params.extensions.push_back("dds"); - params.extensions.push_back("png"); - params.extensions.push_back("jpg"); - params.extensions.push_back("jpeg"); - params.extensions.push_back("tga"); - params.extensions.push_back("bmp"); - wiHelper::FileDialog(params, [this, material](std::string fileName) { - wiEvent::Subscribe_Once(SYSTEM_EVENT_THREAD_SAFE_POINT, [=](uint64_t userdata) { - material->baseColorMap = wiResourceManager::Load(fileName); - material->baseColorMapName = fileName; - material->SetDirty(); - texture_baseColor_Button.SetText(wiHelper::GetFileNameFromPath(fileName)); - }); - }); - } - }); - AddWidget(&texture_baseColor_Button); - - texture_baseColor_uvset_Field.Create("uvset_baseColor"); - texture_baseColor_uvset_Field.SetText(""); - texture_baseColor_uvset_Field.SetTooltip("uv set number"); - texture_baseColor_uvset_Field.SetPos(XMFLOAT2(x + uvset_offset, y)); - texture_baseColor_uvset_Field.SetSize(XMFLOAT2(20, 20)); - texture_baseColor_uvset_Field.OnInputAccepted([&](wiEventArgs args) { - MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); - if (material != nullptr) - { - material->SetUVSet_BaseColorMap(args.iValue); - } - }); - AddWidget(&texture_baseColor_uvset_Field); - texture_normal_Label.Create("NormalMap: "); - texture_normal_Label.SetPos(XMFLOAT2(x, y += step)); - texture_normal_Label.SetSize(XMFLOAT2(120, 20)); - AddWidget(&texture_normal_Label); + auto add_texturemap_controls = [&](MaterialComponent::TEXTURESLOT i) + { + auto& slot = slots[i]; - texture_normal_Button.Create("NormalMap"); - texture_normal_Button.SetText(""); - texture_normal_Button.SetTooltip("Load the normalmap texture. RGB: Normal"); - texture_normal_Button.SetPos(XMFLOAT2(x + 122, y)); - texture_normal_Button.SetSize(XMFLOAT2(260, 20)); - texture_normal_Button.OnClick([&](wiEventArgs args) { - MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); - if (material == nullptr) - return; + slot.label.Create(""); + slot.label.SetPos(XMFLOAT2(x, y += step)); + slot.label.SetSize(XMFLOAT2(120, 20)); + AddWidget(&slot.label); - if (material->normalMap != nullptr) - { - material->normalMap = nullptr; - material->normalMapName = ""; - material->SetDirty(); - texture_normal_Button.SetText(""); - } - else - { - wiHelper::FileDialogParams params; - params.type = wiHelper::FileDialogParams::OPEN; - params.description = "Texture"; - params.extensions.push_back("dds"); - params.extensions.push_back("png"); - params.extensions.push_back("jpg"); - params.extensions.push_back("jpeg"); - params.extensions.push_back("tga"); - params.extensions.push_back("bmp"); - wiHelper::FileDialog(params, [this, material](std::string fileName) { - wiEvent::Subscribe_Once(SYSTEM_EVENT_THREAD_SAFE_POINT, [=](uint64_t userdata) { - material->normalMap = wiResourceManager::Load(fileName); - material->normalMapName = fileName; - material->SetDirty(); - texture_normal_Button.SetText(wiHelper::GetFileNameFromPath(fileName)); - }); - }); - } - }); - AddWidget(&texture_normal_Button); + slot.button.Create(""); + slot.button.SetPos(XMFLOAT2(x + 122, y)); + slot.button.SetSize(XMFLOAT2(260, 20)); + slot.button.OnClick([&](wiEventArgs args) { + MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); + if (material == nullptr) + return; - texture_normal_uvset_Field.Create("uvset_normal"); - texture_normal_uvset_Field.SetText(""); - texture_normal_uvset_Field.SetTooltip("uv set number"); - texture_normal_uvset_Field.SetPos(XMFLOAT2(x + uvset_offset, y)); - texture_normal_uvset_Field.SetSize(XMFLOAT2(20, 20)); - texture_normal_uvset_Field.OnInputAccepted([&](wiEventArgs args) { - MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); - if (material != nullptr) - { - material->SetUVSet_NormalMap(args.iValue); - } - }); - AddWidget(&texture_normal_uvset_Field); - - - - texture_surface_Label.Create("SurfaceMap: "); - texture_surface_Label.SetPos(XMFLOAT2(x, y += step)); - texture_surface_Label.SetSize(XMFLOAT2(120, 20)); - AddWidget(&texture_surface_Label); - - texture_surface_Button.Create("SurfaceMap"); - texture_surface_Button.SetText(""); - texture_surface_Button.SetTooltip("Load the surface property texture.\nDefault workflow: R: Occlusion, G: Roughness, B: Metalness, A: Reflectance\nSpecular-glossiness workflow: RGB: Specular color (f0), A: smoothness"); - texture_surface_Button.SetPos(XMFLOAT2(x + 122, y)); - texture_surface_Button.SetSize(XMFLOAT2(260, 20)); - texture_surface_Button.OnClick([&](wiEventArgs args) { - MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); - if (material == nullptr) - return; - - if (material->surfaceMap != nullptr) - { - material->surfaceMap = nullptr; - material->surfaceMapName = ""; - material->SetDirty(); - texture_surface_Button.SetText(""); - } - else - { - wiHelper::FileDialogParams params; - params.type = wiHelper::FileDialogParams::OPEN; - params.description = "Texture"; - params.extensions.push_back("dds"); - params.extensions.push_back("png"); - params.extensions.push_back("jpg"); - params.extensions.push_back("jpeg"); - params.extensions.push_back("tga"); - params.extensions.push_back("bmp"); - wiHelper::FileDialog(params, [this, material](std::string fileName) { - wiEvent::Subscribe_Once(SYSTEM_EVENT_THREAD_SAFE_POINT, [=](uint64_t userdata) { - material->surfaceMap = wiResourceManager::Load(fileName); - material->surfaceMapName = fileName; - material->SetDirty(); - texture_surface_Button.SetText(wiHelper::GetFileNameFromPath(fileName)); - }); - }); - } - }); - AddWidget(&texture_surface_Button); - - texture_surface_uvset_Field.Create("uvset_surface"); - texture_surface_uvset_Field.SetText(""); - texture_surface_uvset_Field.SetTooltip("uv set number"); - texture_surface_uvset_Field.SetPos(XMFLOAT2(x + uvset_offset, y)); - texture_surface_uvset_Field.SetSize(XMFLOAT2(20, 20)); - texture_surface_uvset_Field.OnInputAccepted([&](wiEventArgs args) { - MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); - if (material != nullptr) - { - material->SetUVSet_SurfaceMap(args.iValue); - } - }); - AddWidget(&texture_surface_uvset_Field); - - - - texture_emissive_Label.Create("EmissiveMap: "); - texture_emissive_Label.SetPos(XMFLOAT2(x, y += step)); - texture_emissive_Label.SetSize(XMFLOAT2(120, 20)); - AddWidget(&texture_emissive_Label); - - texture_emissive_Button.Create("EmissiveMap"); - texture_emissive_Button.SetText(""); - texture_emissive_Button.SetTooltip("Load the emissive map texture."); - texture_emissive_Button.SetPos(XMFLOAT2(x + 122, y)); - texture_emissive_Button.SetSize(XMFLOAT2(260, 20)); - texture_emissive_Button.OnClick([&](wiEventArgs args) { - MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); - if (material == nullptr) - return; - - if (material->emissiveMap != nullptr) - { - material->emissiveMap = nullptr; - material->emissiveMapName = ""; - material->SetDirty(); - texture_emissive_Button.SetText(""); - } - else - { - wiHelper::FileDialogParams params; - params.type = wiHelper::FileDialogParams::OPEN; - params.description = "Texture"; - params.extensions.push_back("dds"); - params.extensions.push_back("png"); - params.extensions.push_back("jpg"); - params.extensions.push_back("jpeg"); - params.extensions.push_back("tga"); - params.extensions.push_back("bmp"); - wiHelper::FileDialog(params, [this, material](std::string fileName) { - wiEvent::Subscribe_Once(SYSTEM_EVENT_THREAD_SAFE_POINT, [=](uint64_t userdata) { - material->emissiveMap = wiResourceManager::Load(fileName); - material->emissiveMapName = fileName; - material->SetDirty(); - texture_emissive_Button.SetText(wiHelper::GetFileNameFromPath(fileName)); - }); - }); - } - }); - AddWidget(&texture_emissive_Button); - - texture_emissive_uvset_Field.Create("uvset_emissive"); - texture_emissive_uvset_Field.SetText(""); - texture_emissive_uvset_Field.SetTooltip("uv set number"); - texture_emissive_uvset_Field.SetPos(XMFLOAT2(x + uvset_offset, y)); - texture_emissive_uvset_Field.SetSize(XMFLOAT2(20, 20)); - texture_emissive_uvset_Field.OnInputAccepted([&](wiEventArgs args) { - MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); - if (material != nullptr) - { - material->SetUVSet_EmissiveMap(args.iValue); - } - }); - AddWidget(&texture_emissive_uvset_Field); - - - - texture_displacement_Label.Create("DisplacementMap: "); - texture_displacement_Label.SetPos(XMFLOAT2(x, y += step)); - texture_displacement_Label.SetSize(XMFLOAT2(120, 20)); - AddWidget(&texture_displacement_Label); - - texture_displacement_Button.Create("DisplacementMap"); - texture_displacement_Button.SetText(""); - texture_displacement_Button.SetTooltip("Load the displacement map texture."); - texture_displacement_Button.SetPos(XMFLOAT2(x + 122, y)); - texture_displacement_Button.SetSize(XMFLOAT2(260, 20)); - texture_displacement_Button.OnClick([&](wiEventArgs args) { - MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); - if (material == nullptr) - return; - - if (material->displacementMap != nullptr) - { - material->displacementMap = nullptr; - material->displacementMapName = ""; - material->SetDirty(); - texture_displacement_Button.SetText(""); - } - else - { - wiHelper::FileDialogParams params; - params.type = wiHelper::FileDialogParams::OPEN; - params.description = "Texture"; - params.extensions.push_back("dds"); - params.extensions.push_back("png"); - params.extensions.push_back("jpg"); - params.extensions.push_back("jpeg"); - params.extensions.push_back("tga"); - params.extensions.push_back("bmp"); - wiHelper::FileDialog(params, [this, material](std::string fileName) { - wiEvent::Subscribe_Once(SYSTEM_EVENT_THREAD_SAFE_POINT, [=](uint64_t userdata) { - material->displacementMap = wiResourceManager::Load(fileName); - material->displacementMapName = fileName; - material->SetDirty(); - texture_displacement_Button.SetText(wiHelper::GetFileNameFromPath(fileName)); - }); - }); - } - }); - AddWidget(&texture_displacement_Button); - - texture_displacement_uvset_Field.Create("uvset_displacement"); - texture_displacement_uvset_Field.SetText(""); - texture_displacement_uvset_Field.SetTooltip("uv set number"); - texture_displacement_uvset_Field.SetPos(XMFLOAT2(x + uvset_offset, y)); - texture_displacement_uvset_Field.SetSize(XMFLOAT2(20, 20)); - texture_displacement_uvset_Field.OnInputAccepted([&](wiEventArgs args) { - MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); - if (material != nullptr) - { - material->SetUVSet_DisplacementMap(args.iValue); - } - }); - AddWidget(&texture_displacement_uvset_Field); - - - - - texture_occlusion_Label.Create("OcclusionMap: "); - texture_occlusion_Label.SetPos(XMFLOAT2(x, y += step)); - texture_occlusion_Label.SetSize(XMFLOAT2(120, 20)); - AddWidget(&texture_occlusion_Label); - - texture_occlusion_Button.Create("OcclusionMap"); - texture_occlusion_Button.SetText(""); - texture_occlusion_Button.SetTooltip("Load the occlusion map texture. R: occlusion factor"); - texture_occlusion_Button.SetPos(XMFLOAT2(x + 122, y)); - texture_occlusion_Button.SetSize(XMFLOAT2(260, 20)); - texture_occlusion_Button.OnClick([&](wiEventArgs args) { - MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); - if (material == nullptr) - return; - - if (material->occlusionMap != nullptr) - { - material->occlusionMap = nullptr; - material->occlusionMapName = ""; - material->SetDirty(); - texture_occlusion_Button.SetText(""); - } - else - { - wiHelper::FileDialogParams params; - params.type = wiHelper::FileDialogParams::OPEN; - params.description = "Texture"; - params.extensions.push_back("dds"); - params.extensions.push_back("png"); - params.extensions.push_back("jpg"); - params.extensions.push_back("jpeg"); - params.extensions.push_back("tga"); - params.extensions.push_back("bmp"); - wiHelper::FileDialog(params, [this, material](std::string fileName) { - wiEvent::Subscribe_Once(SYSTEM_EVENT_THREAD_SAFE_POINT, [=](uint64_t userdata) { - material->occlusionMap = wiResourceManager::Load(fileName); - material->occlusionMapName = fileName; - material->SetDirty(); - texture_occlusion_Button.SetText(wiHelper::GetFileNameFromPath(fileName)); - }); - }); - } - }); - AddWidget(&texture_occlusion_Button); - - texture_occlusion_uvset_Field.Create("uvset_occlusion"); - texture_occlusion_uvset_Field.SetText(""); - texture_occlusion_uvset_Field.SetTooltip("uv set number"); - texture_occlusion_uvset_Field.SetPos(XMFLOAT2(x + uvset_offset, y)); - texture_occlusion_uvset_Field.SetSize(XMFLOAT2(20, 20)); - texture_occlusion_uvset_Field.OnInputAccepted([&](wiEventArgs args) { - MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); - if (material != nullptr) - { - material->SetUVSet_OcclusionMap(args.iValue); - } - }); - AddWidget(&texture_occlusion_uvset_Field); - - - - - texture_transmission_Label.Create("TransmissionMap: "); - texture_transmission_Label.SetPos(XMFLOAT2(x, y += step)); - texture_transmission_Label.SetSize(XMFLOAT2(120, 20)); - AddWidget(&texture_transmission_Label); - - texture_transmission_Button.Create("TransmissionMap"); - texture_transmission_Button.SetText(""); - texture_transmission_Button.SetTooltip("Load the transmission map texture. R: transmission factor"); - texture_transmission_Button.SetPos(XMFLOAT2(x + 122, y)); - texture_transmission_Button.SetSize(XMFLOAT2(260, 20)); - texture_transmission_Button.OnClick([&](wiEventArgs args) { - MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); - if (material == nullptr) - return; - - if (material->transmissionMap != nullptr) - { - material->transmissionMap = nullptr; - material->transmissionMapName = ""; - material->SetDirty(); - texture_transmission_Button.SetText(""); - } - else - { - wiHelper::FileDialogParams params; - params.type = wiHelper::FileDialogParams::OPEN; - params.description = "Texture"; - params.extensions.push_back("dds"); - params.extensions.push_back("png"); - params.extensions.push_back("jpg"); - params.extensions.push_back("jpeg"); - params.extensions.push_back("tga"); - params.extensions.push_back("bmp"); - wiHelper::FileDialog(params, [this, material](std::string fileName) { - wiEvent::Subscribe_Once(SYSTEM_EVENT_THREAD_SAFE_POINT, [=](uint64_t userdata) { - material->transmissionMap = wiResourceManager::Load(fileName); - material->transmissionMapName = fileName; - material->SetDirty(); - texture_transmission_Button.SetText(wiHelper::GetFileNameFromPath(fileName)); + if (material->textures[i].resource != nullptr) + { + material->textures[i].resource = nullptr; + material->textures[i].name = ""; + material->SetDirty(); + slot.button.SetText(""); + } + else + { + wiHelper::FileDialogParams params; + params.type = wiHelper::FileDialogParams::OPEN; + params.description = "Texture"; + params.extensions.push_back("dds"); + params.extensions.push_back("png"); + params.extensions.push_back("jpg"); + params.extensions.push_back("jpeg"); + params.extensions.push_back("tga"); + params.extensions.push_back("bmp"); + wiHelper::FileDialog(params, [this, material, &slot, i](std::string fileName) { + wiEvent::Subscribe_Once(SYSTEM_EVENT_THREAD_SAFE_POINT, [=](uint64_t userdata) { + material->textures[i].resource = wiResourceManager::Load(fileName); + material->textures[i].name = fileName; + material->SetDirty(); + slots[i].button.SetText(wiHelper::GetFileNameFromPath(fileName)); + }); }); - }); - } - }); - AddWidget(&texture_transmission_Button); + } + }); + AddWidget(&slot.button); - texture_transmission_uvset_Field.Create("uvset_transmission"); - texture_transmission_uvset_Field.SetText(""); - texture_transmission_uvset_Field.SetTooltip("uv set number"); - texture_transmission_uvset_Field.SetPos(XMFLOAT2(x + uvset_offset, y)); - texture_transmission_uvset_Field.SetSize(XMFLOAT2(20, 20)); - texture_transmission_uvset_Field.OnInputAccepted([&](wiEventArgs args) { - MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); - if (material != nullptr) + slot.uvsetField.Create("uvset"); + slot.uvsetField.SetText(""); + slot.uvsetField.SetTooltip("uv set number"); + slot.uvsetField.SetPos(XMFLOAT2(x + uvset_offset, y)); + slot.uvsetField.SetSize(XMFLOAT2(20, 20)); + slot.uvsetField.OnInputAccepted([&](wiEventArgs args) { + MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); + if (material != nullptr) + { + material->textures[i].uvset = (uint32_t)args.iValue; + } + }); + AddWidget(&slot.uvsetField); + }; + + for (int i = 0; i < MaterialComponent::TEXTURESLOT_COUNT; ++i) + { + add_texturemap_controls((MaterialComponent::TEXTURESLOT)i); + + switch (i) { - material->SetUVSet_TransmissionMap(args.iValue); + case MaterialComponent::BASECOLORMAP: + slots[i].label.SetText("BaseColorMap:"); + slots[i].button.SetTooltip("RGBA: Basecolor"); + break; + case MaterialComponent::NORMALMAP: + slots[i].label.SetText("NormalMap:"); + slots[i].button.SetTooltip("RGB: Normal"); + break; + case MaterialComponent::SURFACEMAP: + slots[i].label.SetText("SurfaceMap:"); + slots[i].button.SetTooltip("Default workflow: R: Occlusion, G: Roughness, B: Metalness, A: Reflectance\nSpecular-glossiness workflow: RGB: Specular color (f0), A: smoothness"); + break; + case MaterialComponent::EMISSIVEMAP: + slots[i].label.SetText("EmissiveMap:"); + slots[i].button.SetTooltip("RGBA: Emissive"); + break; + case MaterialComponent::OCCLUSIONMAP: + slots[i].label.SetText("OcclusionMap:"); + slots[i].button.SetTooltip("R: Occlusion"); + break; + case MaterialComponent::DISPLACEMENTMAP: + slots[i].label.SetText("DisplacementMap:"); + slots[i].button.SetTooltip("R: Displacement heightmap"); + break; + case MaterialComponent::TRANSMISSIONMAP: + slots[i].label.SetText("TransmissionMap:"); + slots[i].button.SetTooltip("R: Transmission factor"); + break; + case MaterialComponent::SHEENCOLORMAP: + slots[i].label.SetText("SheenColorMap:"); + slots[i].button.SetTooltip("RGB: Sheen color"); + break; + case MaterialComponent::SHEENROUGHNESSMAP: + slots[i].label.SetText("SheenRoughMap:"); + slots[i].button.SetTooltip("A: Roughness"); + break; + case MaterialComponent::CLEARCOATMAP: + slots[i].label.SetText("ClearcoatMap:"); + slots[i].button.SetTooltip("R: Clearcoat factor"); + break; + case MaterialComponent::CLEARCOATROUGHNESSMAP: + slots[i].label.SetText("ClearcoatRoughMap:"); + slots[i].button.SetTooltip("G: Roughness"); + break; + case MaterialComponent::CLEARCOATNORMALMAP: + slots[i].label.SetText("ClearcoatNormMap:"); + slots[i].button.SetTooltip("RGB: Normal"); + break; + default: + break; } - }); - AddWidget(&texture_transmission_uvset_Field); - - - - - texture_sheenColor_Label.Create("SheenColorMap: "); - texture_sheenColor_Label.SetPos(XMFLOAT2(x, y += step)); - texture_sheenColor_Label.SetSize(XMFLOAT2(120, 20)); - AddWidget(&texture_sheenColor_Label); - - texture_sheenColor_Button.Create("SheenColorMap"); - texture_sheenColor_Button.SetText(""); - texture_sheenColor_Button.SetTooltip("Load the sheen color texture (for cloth shader). RGB: sheen color"); - texture_sheenColor_Button.SetPos(XMFLOAT2(x + 122, y)); - texture_sheenColor_Button.SetSize(XMFLOAT2(260, 20)); - texture_sheenColor_Button.OnClick([&](wiEventArgs args) { - MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); - if (material == nullptr) - return; - - if (material->sheenColorMap != nullptr) - { - material->sheenColorMap = nullptr; - material->sheenColorMapName = ""; - material->SetDirty(); - texture_sheenColor_Button.SetText(""); - } - else - { - wiHelper::FileDialogParams params; - params.type = wiHelper::FileDialogParams::OPEN; - params.description = "Texture"; - params.extensions.push_back("dds"); - params.extensions.push_back("png"); - params.extensions.push_back("jpg"); - params.extensions.push_back("jpeg"); - params.extensions.push_back("tga"); - params.extensions.push_back("bmp"); - wiHelper::FileDialog(params, [this, material](std::string fileName) { - wiEvent::Subscribe_Once(SYSTEM_EVENT_THREAD_SAFE_POINT, [=](uint64_t userdata) { - material->sheenColorMap = wiResourceManager::Load(fileName); - material->sheenColorMapName = fileName; - material->SetDirty(); - texture_sheenColor_Button.SetText(wiHelper::GetFileNameFromPath(fileName)); - }); - }); - } - }); - AddWidget(&texture_sheenColor_Button); - - texture_sheenColor_uvset_Field.Create("uvset_sheenColor"); - texture_sheenColor_uvset_Field.SetText(""); - texture_sheenColor_uvset_Field.SetTooltip("uv set number"); - texture_sheenColor_uvset_Field.SetPos(XMFLOAT2(x + uvset_offset, y)); - texture_sheenColor_uvset_Field.SetSize(XMFLOAT2(20, 20)); - texture_sheenColor_uvset_Field.OnInputAccepted([&](wiEventArgs args) { - MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); - if (material != nullptr) - { - material->SetUVSet_SheenColorMap(args.iValue); - } - }); - AddWidget(&texture_sheenColor_uvset_Field); - - - - - texture_sheenRoughness_Label.Create("SheenRoughMap: "); - texture_sheenRoughness_Label.SetPos(XMFLOAT2(x, y += step)); - texture_sheenRoughness_Label.SetSize(XMFLOAT2(120, 20)); - AddWidget(&texture_sheenRoughness_Label); - - texture_sheenRoughness_Button.Create("SheenRoughnessMap"); - texture_sheenRoughness_Button.SetText(""); - texture_sheenRoughness_Button.SetTooltip("Load the sheen roughness texture. A: roughness"); - texture_sheenRoughness_Button.SetPos(XMFLOAT2(x + 122, y)); - texture_sheenRoughness_Button.SetSize(XMFLOAT2(260, 20)); - texture_sheenRoughness_Button.OnClick([&](wiEventArgs args) { - MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); - if (material == nullptr) - return; - - if (material->sheenRoughnessMap != nullptr) - { - material->sheenRoughnessMap = nullptr; - material->sheenRoughnessMapName = ""; - material->SetDirty(); - texture_sheenRoughness_Button.SetText(""); - } - else - { - wiHelper::FileDialogParams params; - params.type = wiHelper::FileDialogParams::OPEN; - params.description = "Texture"; - params.extensions.push_back("dds"); - params.extensions.push_back("png"); - params.extensions.push_back("jpg"); - params.extensions.push_back("jpeg"); - params.extensions.push_back("tga"); - params.extensions.push_back("bmp"); - wiHelper::FileDialog(params, [this, material](std::string fileName) { - wiEvent::Subscribe_Once(SYSTEM_EVENT_THREAD_SAFE_POINT, [=](uint64_t userdata) { - material->sheenRoughnessMap = wiResourceManager::Load(fileName); - material->sheenRoughnessMapName = fileName; - material->SetDirty(); - texture_sheenRoughness_Button.SetText(wiHelper::GetFileNameFromPath(fileName)); - }); - }); - } - }); - AddWidget(&texture_sheenRoughness_Button); - - texture_sheenRoughness_uvset_Field.Create("uvset_sheenRoughness"); - texture_sheenRoughness_uvset_Field.SetText(""); - texture_sheenRoughness_uvset_Field.SetTooltip("uv set number"); - texture_sheenRoughness_uvset_Field.SetPos(XMFLOAT2(x + uvset_offset, y)); - texture_sheenRoughness_uvset_Field.SetSize(XMFLOAT2(20, 20)); - texture_sheenRoughness_uvset_Field.OnInputAccepted([&](wiEventArgs args) { - MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); - if (material != nullptr) - { - material->SetUVSet_SheenRoughnessMap(args.iValue); - } - }); - AddWidget(&texture_sheenRoughness_uvset_Field); - - - - - texture_clearcoat_Label.Create("ClearcoatMap: "); - texture_clearcoat_Label.SetPos(XMFLOAT2(x, y += step)); - texture_clearcoat_Label.SetSize(XMFLOAT2(120, 20)); - AddWidget(&texture_clearcoat_Label); - - texture_clearcoat_Button.Create("ClearcoatMap"); - texture_clearcoat_Button.SetText(""); - texture_clearcoat_Button.SetTooltip("Load the clearcoat factor texture. R: clearcoat factor"); - texture_clearcoat_Button.SetPos(XMFLOAT2(x + 122, y)); - texture_clearcoat_Button.SetSize(XMFLOAT2(260, 20)); - texture_clearcoat_Button.OnClick([&](wiEventArgs args) { - MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); - if (material == nullptr) - return; - - if (material->clearcoatMap != nullptr) - { - material->clearcoatMap = nullptr; - material->clearcoatMapName = ""; - material->SetDirty(); - texture_clearcoat_Button.SetText(""); - } - else - { - wiHelper::FileDialogParams params; - params.type = wiHelper::FileDialogParams::OPEN; - params.description = "Texture"; - params.extensions.push_back("dds"); - params.extensions.push_back("png"); - params.extensions.push_back("jpg"); - params.extensions.push_back("jpeg"); - params.extensions.push_back("tga"); - params.extensions.push_back("bmp"); - wiHelper::FileDialog(params, [this, material](std::string fileName) { - wiEvent::Subscribe_Once(SYSTEM_EVENT_THREAD_SAFE_POINT, [=](uint64_t userdata) { - material->clearcoatMap = wiResourceManager::Load(fileName); - material->clearcoatMapName = fileName; - material->SetDirty(); - texture_clearcoat_Button.SetText(wiHelper::GetFileNameFromPath(fileName)); - }); - }); - } - }); - AddWidget(&texture_clearcoat_Button); - - texture_clearcoat_uvset_Field.Create("uvset_clearcoat"); - texture_clearcoat_uvset_Field.SetText(""); - texture_clearcoat_uvset_Field.SetTooltip("uv set number"); - texture_clearcoat_uvset_Field.SetPos(XMFLOAT2(x + uvset_offset, y)); - texture_clearcoat_uvset_Field.SetSize(XMFLOAT2(20, 20)); - texture_clearcoat_uvset_Field.OnInputAccepted([&](wiEventArgs args) { - MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); - if (material != nullptr) - { - material->SetUVSet_ClearcoatMap(args.iValue); - } - }); - AddWidget(&texture_clearcoat_uvset_Field); - - - - - texture_clearcoatRoughness_Label.Create("ClearcoatRoughMap: "); - texture_clearcoatRoughness_Label.SetPos(XMFLOAT2(x, y += step)); - texture_clearcoatRoughness_Label.SetSize(XMFLOAT2(120, 20)); - AddWidget(&texture_clearcoatRoughness_Label); - - texture_clearcoatRoughness_Button.Create("ClearcoatRoughnessMap"); - texture_clearcoatRoughness_Button.SetText(""); - texture_clearcoatRoughness_Button.SetTooltip("Load the clearcoat roughness texture. G: roughness"); - texture_clearcoatRoughness_Button.SetPos(XMFLOAT2(x + 122, y)); - texture_clearcoatRoughness_Button.SetSize(XMFLOAT2(260, 20)); - texture_clearcoatRoughness_Button.OnClick([&](wiEventArgs args) { - MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); - if (material == nullptr) - return; - - if (material->clearcoatRoughnessMap != nullptr) - { - material->clearcoatRoughnessMap = nullptr; - material->clearcoatRoughnessMapName = ""; - material->SetDirty(); - texture_clearcoatRoughness_Button.SetText(""); - } - else - { - wiHelper::FileDialogParams params; - params.type = wiHelper::FileDialogParams::OPEN; - params.description = "Texture"; - params.extensions.push_back("dds"); - params.extensions.push_back("png"); - params.extensions.push_back("jpg"); - params.extensions.push_back("jpeg"); - params.extensions.push_back("tga"); - params.extensions.push_back("bmp"); - wiHelper::FileDialog(params, [this, material](std::string fileName) { - wiEvent::Subscribe_Once(SYSTEM_EVENT_THREAD_SAFE_POINT, [=](uint64_t userdata) { - material->clearcoatRoughnessMap = wiResourceManager::Load(fileName); - material->clearcoatRoughnessMapName = fileName; - material->SetDirty(); - texture_clearcoatRoughness_Button.SetText(wiHelper::GetFileNameFromPath(fileName)); - }); - }); - } - }); - AddWidget(&texture_clearcoatRoughness_Button); - - texture_clearcoatRoughness_uvset_Field.Create("uvset_clearcoatRoughness"); - texture_clearcoatRoughness_uvset_Field.SetText(""); - texture_clearcoatRoughness_uvset_Field.SetTooltip("uv set number"); - texture_clearcoatRoughness_uvset_Field.SetPos(XMFLOAT2(x + uvset_offset, y)); - texture_clearcoatRoughness_uvset_Field.SetSize(XMFLOAT2(20, 20)); - texture_clearcoatRoughness_uvset_Field.OnInputAccepted([&](wiEventArgs args) { - MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); - if (material != nullptr) - { - material->SetUVSet_ClearcoatRoughnessMap(args.iValue); - } - }); - AddWidget(&texture_clearcoatRoughness_uvset_Field); - - - - - texture_clearcoatNormal_Label.Create("ClearcoatNormMap: "); - texture_clearcoatNormal_Label.SetPos(XMFLOAT2(x, y += step)); - texture_clearcoatNormal_Label.SetSize(XMFLOAT2(120, 20)); - AddWidget(&texture_clearcoatNormal_Label); - - texture_clearcoatNormal_Button.Create("ClearcoatNormalMap"); - texture_clearcoatNormal_Button.SetText(""); - texture_clearcoatNormal_Button.SetTooltip("Load the clearcoat normal map texture. RGB: normal"); - texture_clearcoatNormal_Button.SetPos(XMFLOAT2(x + 122, y)); - texture_clearcoatNormal_Button.SetSize(XMFLOAT2(260, 20)); - texture_clearcoatNormal_Button.OnClick([&](wiEventArgs args) { - MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); - if (material == nullptr) - return; - - if (material->clearcoatNormalMap != nullptr) - { - material->clearcoatNormalMap = nullptr; - material->clearcoatNormalMapName = ""; - material->SetDirty(); - texture_clearcoatNormal_Button.SetText(""); - } - else - { - wiHelper::FileDialogParams params; - params.type = wiHelper::FileDialogParams::OPEN; - params.description = "Texture"; - params.extensions.push_back("dds"); - params.extensions.push_back("png"); - params.extensions.push_back("jpg"); - params.extensions.push_back("jpeg"); - params.extensions.push_back("tga"); - params.extensions.push_back("bmp"); - wiHelper::FileDialog(params, [this, material](std::string fileName) { - wiEvent::Subscribe_Once(SYSTEM_EVENT_THREAD_SAFE_POINT, [=](uint64_t userdata) { - material->clearcoatNormalMap = wiResourceManager::Load(fileName); - material->clearcoatNormalMapName = fileName; - material->SetDirty(); - texture_clearcoatNormal_Button.SetText(wiHelper::GetFileNameFromPath(fileName)); - }); - }); - } - }); - AddWidget(&texture_clearcoatNormal_Button); - - texture_clearcoatNormal_uvset_Field.Create("uvset_clearcoatNormal"); - texture_clearcoatNormal_uvset_Field.SetText(""); - texture_clearcoatNormal_uvset_Field.SetTooltip("uv set number"); - texture_clearcoatNormal_uvset_Field.SetPos(XMFLOAT2(x + uvset_offset, y)); - texture_clearcoatNormal_uvset_Field.SetSize(XMFLOAT2(20, 20)); - texture_clearcoatNormal_uvset_Field.OnInputAccepted([&](wiEventArgs args) { - MaterialComponent* material = wiScene::GetScene().materials.GetComponent(entity); - if (material != nullptr) - { - material->SetUVSet_ClearcoatNormalMap(args.iValue); - } - }); - AddWidget(&texture_clearcoatNormal_uvset_Field); - - - - - + } colorComboBox.Create("Color picker mode: "); colorComboBox.SetSize(XMFLOAT2(120, hei)); @@ -1284,32 +666,11 @@ void MaterialWindow::SetEntity(Entity entity) } shadingRateComboBox.SetSelected((int)material->shadingRate); - texture_baseColor_Button.SetText(wiHelper::GetFileNameFromPath(material->baseColorMapName)); - texture_normal_Button.SetText(wiHelper::GetFileNameFromPath(material->normalMapName)); - texture_surface_Button.SetText(wiHelper::GetFileNameFromPath(material->surfaceMapName)); - texture_displacement_Button.SetText(wiHelper::GetFileNameFromPath(material->displacementMapName)); - texture_emissive_Button.SetText(wiHelper::GetFileNameFromPath(material->emissiveMapName)); - texture_occlusion_Button.SetText(wiHelper::GetFileNameFromPath(material->occlusionMapName)); - texture_transmission_Button.SetText(wiHelper::GetFileNameFromPath(material->transmissionMapName)); - texture_sheenColor_Button.SetText(wiHelper::GetFileNameFromPath(material->sheenColorMapName)); - texture_sheenRoughness_Button.SetText(wiHelper::GetFileNameFromPath(material->sheenRoughnessMapName)); - texture_clearcoat_Button.SetText(wiHelper::GetFileNameFromPath(material->clearcoatMapName)); - texture_clearcoatRoughness_Button.SetText(wiHelper::GetFileNameFromPath(material->clearcoatRoughnessMapName)); - texture_clearcoatNormal_Button.SetText(wiHelper::GetFileNameFromPath(material->clearcoatNormalMapName)); - - texture_baseColor_uvset_Field.SetText(std::to_string(material->uvset_baseColorMap)); - texture_normal_uvset_Field.SetText(std::to_string(material->uvset_normalMap)); - texture_surface_uvset_Field.SetText(std::to_string(material->uvset_surfaceMap)); - texture_displacement_uvset_Field.SetText(std::to_string(material->uvset_displacementMap)); - texture_emissive_uvset_Field.SetText(std::to_string(material->uvset_emissiveMap)); - texture_occlusion_uvset_Field.SetText(std::to_string(material->uvset_occlusionMap)); - texture_transmission_uvset_Field.SetText(std::to_string(material->uvset_transmissionMap)); - texture_sheenColor_uvset_Field.SetText(std::to_string(material->uvset_sheenColorMap)); - texture_sheenRoughness_uvset_Field.SetText(std::to_string(material->uvset_sheenRoughnessMap)); - texture_clearcoat_uvset_Field.SetText(std::to_string(material->uvset_clearcoatMap)); - texture_clearcoatRoughness_uvset_Field.SetText(std::to_string(material->uvset_clearcoatRoughnessMap)); - texture_clearcoatNormal_uvset_Field.SetText(std::to_string(material->uvset_clearcoatNormalMap)); - + for (int i = 0; i < MaterialComponent::TEXTURESLOT_COUNT; ++i) + { + slots[i].button.SetText(material->textures[i].name); + slots[i].uvsetField.SetText(std::to_string(material->textures[i].uvset)); + } colorComboBox.SetEnabled(true); colorPicker.SetEnabled(true); @@ -1354,49 +715,34 @@ void MaterialWindow::SetEntity(Entity entity) sheenRoughnessSlider.SetEnabled(false); clearcoatSlider.SetEnabled(false); clearcoatRoughnessSlider.SetEnabled(false); - texture_sheenColor_Button.SetEnabled(false); - texture_sheenColor_uvset_Field.SetEnabled(false); - texture_sheenRoughness_Button.SetEnabled(false); - texture_sheenRoughness_uvset_Field.SetEnabled(false); - texture_clearcoat_Button.SetEnabled(false); - texture_clearcoat_uvset_Field.SetEnabled(false); - texture_clearcoatRoughness_Button.SetEnabled(false); - texture_clearcoatRoughness_uvset_Field.SetEnabled(false); - texture_clearcoatNormal_Button.SetEnabled(false); - texture_clearcoatNormal_uvset_Field.SetEnabled(false); + slots[MaterialComponent::SHEENCOLORMAP].SetEnabled(false); + slots[MaterialComponent::SHEENROUGHNESSMAP].SetEnabled(false); + slots[MaterialComponent::CLEARCOATMAP].SetEnabled(false); + slots[MaterialComponent::CLEARCOATROUGHNESSMAP].SetEnabled(false); + slots[MaterialComponent::CLEARCOATNORMALMAP].SetEnabled(false); switch (material->shaderType) { case MaterialComponent::SHADERTYPE_PBR_CLOTH: sheenRoughnessSlider.SetEnabled(true); - texture_sheenColor_Button.SetEnabled(true); - texture_sheenColor_uvset_Field.SetEnabled(true); - texture_sheenRoughness_Button.SetEnabled(true); - texture_sheenRoughness_uvset_Field.SetEnabled(true); + slots[MaterialComponent::SHEENCOLORMAP].SetEnabled(true); + slots[MaterialComponent::SHEENROUGHNESSMAP].SetEnabled(true); break; case MaterialComponent::SHADERTYPE_PBR_CLEARCOAT: clearcoatSlider.SetEnabled(true); clearcoatRoughnessSlider.SetEnabled(true); - texture_clearcoat_Button.SetEnabled(true); - texture_clearcoat_uvset_Field.SetEnabled(true); - texture_clearcoatRoughness_Button.SetEnabled(true); - texture_clearcoatRoughness_uvset_Field.SetEnabled(true); - texture_clearcoatNormal_Button.SetEnabled(true); - texture_clearcoatNormal_uvset_Field.SetEnabled(true); + slots[MaterialComponent::CLEARCOATMAP].SetEnabled(true); + slots[MaterialComponent::CLEARCOATROUGHNESSMAP].SetEnabled(true); + slots[MaterialComponent::CLEARCOATNORMALMAP].SetEnabled(true); break; case MaterialComponent::SHADERTYPE_PBR_CLOTH_CLEARCOAT: sheenRoughnessSlider.SetEnabled(true); clearcoatSlider.SetEnabled(true); clearcoatRoughnessSlider.SetEnabled(true); - texture_sheenColor_Button.SetEnabled(true); - texture_sheenColor_uvset_Field.SetEnabled(true); - texture_sheenRoughness_Button.SetEnabled(true); - texture_sheenRoughness_uvset_Field.SetEnabled(true); - texture_clearcoat_Button.SetEnabled(true); - texture_clearcoat_uvset_Field.SetEnabled(true); - texture_clearcoatRoughness_Button.SetEnabled(true); - texture_clearcoatRoughness_uvset_Field.SetEnabled(true); - texture_clearcoatNormal_Button.SetEnabled(true); - texture_clearcoatNormal_uvset_Field.SetEnabled(true); + slots[MaterialComponent::SHEENCOLORMAP].SetEnabled(true); + slots[MaterialComponent::SHEENROUGHNESSMAP].SetEnabled(true); + slots[MaterialComponent::CLEARCOATMAP].SetEnabled(true); + slots[MaterialComponent::CLEARCOATROUGHNESSMAP].SetEnabled(true); + slots[MaterialComponent::CLEARCOATNORMALMAP].SetEnabled(true); break; } sheenRoughnessSlider.SetValue(material->sheenRoughness); @@ -1418,25 +764,11 @@ void MaterialWindow::SetEntity(Entity entity) colorComboBox.SetEnabled(false); colorPicker.SetEnabled(false); - texture_baseColor_Button.SetText(""); - texture_normal_Button.SetText(""); - texture_surface_Button.SetText(""); - texture_displacement_Button.SetText(""); - texture_emissive_Button.SetText(""); - texture_occlusion_Button.SetText(""); - - texture_baseColor_uvset_Field.SetText(""); - texture_normal_uvset_Field.SetText(""); - texture_surface_uvset_Field.SetText(""); - texture_displacement_uvset_Field.SetText(""); - texture_emissive_uvset_Field.SetText(""); - texture_occlusion_uvset_Field.SetText(""); - texture_transmission_uvset_Field.SetText(""); - texture_sheenColor_uvset_Field.SetText(""); - texture_sheenRoughness_uvset_Field.SetText(""); - texture_clearcoat_uvset_Field.SetText(""); - texture_clearcoatRoughness_uvset_Field.SetText(""); - texture_clearcoatNormal_uvset_Field.SetText(""); + for (int i = 0; i < MaterialComponent::TEXTURESLOT_COUNT; ++i) + { + slots[i].button.SetText(""); + slots[i].uvsetField.SetText(""); + } } newMaterialButton.SetEnabled(true); diff --git a/Editor/MaterialWindow.h b/Editor/MaterialWindow.h index faa388e4f..101a450fc 100644 --- a/Editor/MaterialWindow.h +++ b/Editor/MaterialWindow.h @@ -42,44 +42,21 @@ public: wiSlider clearcoatSlider; wiSlider clearcoatRoughnessSlider; - wiLabel texture_baseColor_Label; - wiLabel texture_normal_Label; - wiLabel texture_surface_Label; - wiLabel texture_displacement_Label; - wiLabel texture_emissive_Label; - wiLabel texture_occlusion_Label; - wiLabel texture_transmission_Label; - wiLabel texture_sheenColor_Label; - wiLabel texture_sheenRoughness_Label; - wiLabel texture_clearcoat_Label; - wiLabel texture_clearcoatRoughness_Label; - wiLabel texture_clearcoatNormal_Label; + struct TextureSlotControls + { + std::string name; + wiLabel label; + wiButton button; + wiTextInputField uvsetField; - wiButton texture_baseColor_Button; - wiButton texture_normal_Button; - wiButton texture_surface_Button; - wiButton texture_displacement_Button; - wiButton texture_emissive_Button; - wiButton texture_occlusion_Button; - wiButton texture_transmission_Button; - wiButton texture_sheenColor_Button; - wiButton texture_sheenRoughness_Button; - wiButton texture_clearcoat_Button; - wiButton texture_clearcoatRoughness_Button; - wiButton texture_clearcoatNormal_Button; - - wiTextInputField texture_baseColor_uvset_Field; - wiTextInputField texture_normal_uvset_Field; - wiTextInputField texture_surface_uvset_Field; - wiTextInputField texture_displacement_uvset_Field; - wiTextInputField texture_emissive_uvset_Field; - wiTextInputField texture_occlusion_uvset_Field; - wiTextInputField texture_transmission_uvset_Field; - wiTextInputField texture_sheenColor_uvset_Field; - wiTextInputField texture_sheenRoughness_uvset_Field; - wiTextInputField texture_clearcoat_uvset_Field; - wiTextInputField texture_clearcoatRoughness_uvset_Field; - wiTextInputField texture_clearcoatNormal_uvset_Field; + void SetEnabled(bool value) + { + label.SetEnabled(value); + button.SetEnabled(value); + uvsetField.SetEnabled(value); + } + }; + TextureSlotControls slots[wiScene::MaterialComponent::TEXTURESLOT_COUNT]; wiComboBox colorComboBox; wiColorPicker colorPicker; diff --git a/Editor/ModelImporter_GLTF.cpp b/Editor/ModelImporter_GLTF.cpp index 85cdb1ffa..aae0a9d91 100644 --- a/Editor/ModelImporter_GLTF.cpp +++ b/Editor/ModelImporter_GLTF.cpp @@ -438,41 +438,41 @@ void ImportModel_GLTF(const std::string& fileName, Scene& scene) { auto& tex = state.gltfModel.textures[baseColorTexture->second.TextureIndex()]; auto& img = state.gltfModel.images[tex.source]; - material.baseColorMap = RegisterTexture(&img, "basecolor"); - material.baseColorMapName = img.uri; - material.uvset_baseColorMap = baseColorTexture->second.TextureTexCoord(); + material.textures[MaterialComponent::BASECOLORMAP].resource = RegisterTexture(&img, "basecolor"); + material.textures[MaterialComponent::BASECOLORMAP].name = img.uri; + material.textures[MaterialComponent::BASECOLORMAP].uvset = baseColorTexture->second.TextureTexCoord(); } if (normalTexture != x.additionalValues.end()) { auto& tex = state.gltfModel.textures[normalTexture->second.TextureIndex()]; auto& img = state.gltfModel.images[tex.source]; - material.normalMap = RegisterTexture(&img, "normal"); - material.normalMapName = img.uri; - material.uvset_normalMap = normalTexture->second.TextureTexCoord(); + material.textures[MaterialComponent::NORMALMAP].resource = RegisterTexture(&img, "normal"); + material.textures[MaterialComponent::NORMALMAP].name = img.uri; + material.textures[MaterialComponent::NORMALMAP].uvset = normalTexture->second.TextureTexCoord(); } if (metallicRoughnessTexture != x.values.end()) { auto& tex = state.gltfModel.textures[metallicRoughnessTexture->second.TextureIndex()]; auto& img = state.gltfModel.images[tex.source]; - material.surfaceMap = RegisterTexture(&img, "roughness_metallic"); - material.surfaceMapName = img.uri; - material.uvset_surfaceMap = metallicRoughnessTexture->second.TextureTexCoord(); + material.textures[MaterialComponent::SURFACEMAP].resource = RegisterTexture(&img, "roughness_metallic"); + material.textures[MaterialComponent::SURFACEMAP].name = img.uri; + material.textures[MaterialComponent::SURFACEMAP].uvset = metallicRoughnessTexture->second.TextureTexCoord(); } if (emissiveTexture != x.additionalValues.end()) { auto& tex = state.gltfModel.textures[emissiveTexture->second.TextureIndex()]; auto& img = state.gltfModel.images[tex.source]; - material.emissiveMap = RegisterTexture(&img, "emissive"); - material.emissiveMapName = img.uri; - material.uvset_emissiveMap = emissiveTexture->second.TextureTexCoord(); + material.textures[MaterialComponent::EMISSIVEMAP].resource = RegisterTexture(&img, "emissive"); + material.textures[MaterialComponent::EMISSIVEMAP].name = img.uri; + material.textures[MaterialComponent::EMISSIVEMAP].uvset = emissiveTexture->second.TextureTexCoord(); } if (occlusionTexture != x.additionalValues.end()) { auto& tex = state.gltfModel.textures[occlusionTexture->second.TextureIndex()]; auto& img = state.gltfModel.images[tex.source]; - material.occlusionMap = RegisterTexture(&img, "occlusion"); - material.occlusionMapName = img.uri; - material.uvset_occlusionMap = occlusionTexture->second.TextureTexCoord(); + material.textures[MaterialComponent::OCCLUSIONMAP].resource = RegisterTexture(&img, "occlusion"); + material.textures[MaterialComponent::OCCLUSIONMAP].name = img.uri; + material.textures[MaterialComponent::OCCLUSIONMAP].uvset = occlusionTexture->second.TextureTexCoord(); material.SetOcclusionEnabled_Secondary(true); } @@ -529,9 +529,9 @@ void ImportModel_GLTF(const std::string& fileName, Scene& scene) int index = ext_transmission->second.Get("transmissionTexture").Get("index").Get(); auto& tex = state.gltfModel.textures[index]; auto& img = state.gltfModel.images[tex.source]; - material.transmissionMap = RegisterTexture(&img, "transmission"); - material.transmissionMapName = img.uri; - material.uvset_transmissionMap = (uint32_t)ext_transmission->second.Get("transmissionTexture").Get("texCoord").Get(); + material.textures[MaterialComponent::TRANSMISSIONMAP].resource = RegisterTexture(&img, "transmission"); + material.textures[MaterialComponent::TRANSMISSIONMAP].name = img.uri; + material.textures[MaterialComponent::TRANSMISSIONMAP].uvset = (uint32_t)ext_transmission->second.Get("transmissionTexture").Get("texCoord").Get(); } } @@ -546,18 +546,18 @@ void ImportModel_GLTF(const std::string& fileName, Scene& scene) int index = specularGlossinessWorkflow->second.Get("diffuseTexture").Get("index").Get(); auto& tex = state.gltfModel.textures[index]; auto& img = state.gltfModel.images[tex.source]; - material.baseColorMap = RegisterTexture(&img, "diffuse"); - material.baseColorMapName = img.uri; - material.uvset_baseColorMap = (uint32_t)specularGlossinessWorkflow->second.Get("diffuseTexture").Get("texCoord").Get(); + material.textures[MaterialComponent::BASECOLORMAP].resource = RegisterTexture(&img, "diffuse"); + material.textures[MaterialComponent::BASECOLORMAP].name = img.uri; + material.textures[MaterialComponent::BASECOLORMAP].uvset = (uint32_t)specularGlossinessWorkflow->second.Get("diffuseTexture").Get("texCoord").Get(); } if (specularGlossinessWorkflow->second.Has("specularGlossinessTexture")) { int index = specularGlossinessWorkflow->second.Get("specularGlossinessTexture").Get("index").Get(); auto& tex = state.gltfModel.textures[index]; auto& img = state.gltfModel.images[tex.source]; - material.surfaceMap = RegisterTexture(&img, "specular_glossiness"); - material.surfaceMapName = img.uri; - material.uvset_surfaceMap = (uint32_t)specularGlossinessWorkflow->second.Get("specularGlossinessTexture").Get("texCoord").Get(); + material.textures[MaterialComponent::SURFACEMAP].resource = RegisterTexture(&img, "specular_glossiness"); + material.textures[MaterialComponent::SURFACEMAP].name = img.uri; + material.textures[MaterialComponent::SURFACEMAP].uvset = (uint32_t)specularGlossinessWorkflow->second.Get("specularGlossinessTexture").Get("texCoord").Get(); } if (specularGlossinessWorkflow->second.Has("diffuseFactor")) @@ -602,9 +602,9 @@ void ImportModel_GLTF(const std::string& fileName, Scene& scene) int index = param.Get("index").Get(); auto& tex = state.gltfModel.textures[index]; auto& img = state.gltfModel.images[tex.source]; - material.sheenColorMap = RegisterTexture(&img, "sheenColor"); - material.sheenColorMapName = img.uri; - material.uvset_sheenColorMap = (uint32_t)param.Get("texCoord").Get(); + material.textures[MaterialComponent::SHEENCOLORMAP].resource = RegisterTexture(&img, "sheenColor"); + material.textures[MaterialComponent::SHEENCOLORMAP].name = img.uri; + material.textures[MaterialComponent::SHEENCOLORMAP].uvset = (uint32_t)param.Get("texCoord").Get(); } if (ext_sheen->second.Has("sheenRoughnessFactor")) { @@ -617,9 +617,9 @@ void ImportModel_GLTF(const std::string& fileName, Scene& scene) int index = param.Get("index").Get(); auto& tex = state.gltfModel.textures[index]; auto& img = state.gltfModel.images[tex.source]; - material.sheenRoughnessMap = RegisterTexture(&img, "sheenRoughness"); - material.sheenRoughnessMapName = img.uri; - material.uvset_sheenRoughnessMap = (uint32_t)param.Get("texCoord").Get(); + material.textures[MaterialComponent::SHEENROUGHNESSMAP].resource = RegisterTexture(&img, "sheenRoughness"); + material.textures[MaterialComponent::SHEENROUGHNESSMAP].name = img.uri; + material.textures[MaterialComponent::SHEENROUGHNESSMAP].uvset = (uint32_t)param.Get("texCoord").Get(); } } @@ -646,9 +646,9 @@ void ImportModel_GLTF(const std::string& fileName, Scene& scene) int index = param.Get("index").Get(); auto& tex = state.gltfModel.textures[index]; auto& img = state.gltfModel.images[tex.source]; - material.clearcoatMap = RegisterTexture(&img, "clearcoat"); - material.clearcoatMapName = img.uri; - material.uvset_clearcoatMap = (uint32_t)param.Get("texCoord").Get(); + material.textures[MaterialComponent::CLEARCOATMAP].resource = RegisterTexture(&img, "clearcoat"); + material.textures[MaterialComponent::CLEARCOATMAP].name = img.uri; + material.textures[MaterialComponent::CLEARCOATMAP].uvset = (uint32_t)param.Get("texCoord").Get(); } if (ext_clearcoat->second.Has("clearcoatRoughnessFactor")) { @@ -661,9 +661,9 @@ void ImportModel_GLTF(const std::string& fileName, Scene& scene) int index = param.Get("index").Get(); auto& tex = state.gltfModel.textures[index]; auto& img = state.gltfModel.images[tex.source]; - material.clearcoatRoughnessMap = RegisterTexture(&img, "clearcoatRoughness"); - material.clearcoatRoughnessMapName = img.uri; - material.uvset_clearcoatRoughnessMap = (uint32_t)param.Get("texCoord").Get(); + material.textures[MaterialComponent::CLEARCOATROUGHNESSMAP].resource = RegisterTexture(&img, "clearcoatRoughness"); + material.textures[MaterialComponent::CLEARCOATROUGHNESSMAP].name = img.uri; + material.textures[MaterialComponent::CLEARCOATROUGHNESSMAP].uvset = (uint32_t)param.Get("texCoord").Get(); } if (ext_clearcoat->second.Has("clearcoatNormalTexture")) { @@ -671,9 +671,9 @@ void ImportModel_GLTF(const std::string& fileName, Scene& scene) int index = param.Get("index").Get(); auto& tex = state.gltfModel.textures[index]; auto& img = state.gltfModel.images[tex.source]; - material.clearcoatNormalMap = RegisterTexture(&img, "clearcoatNormal"); - material.clearcoatNormalMapName = img.uri; - material.uvset_clearcoatNormalMap = (uint32_t)param.Get("texCoord").Get(); + material.textures[MaterialComponent::CLEARCOATNORMALMAP].resource = RegisterTexture(&img, "clearcoatNormal"); + material.textures[MaterialComponent::CLEARCOATNORMALMAP].name = img.uri; + material.textures[MaterialComponent::CLEARCOATNORMALMAP].uvset = (uint32_t)param.Get("texCoord").Get(); } } diff --git a/Editor/ModelImporter_OBJ.cpp b/Editor/ModelImporter_OBJ.cpp index 977417408..4860dca11 100644 --- a/Editor/ModelImporter_OBJ.cpp +++ b/Editor/ModelImporter_OBJ.cpp @@ -112,43 +112,28 @@ void ImportModel_OBJ(const std::string& fileName, Scene& scene) MaterialComponent& material = *scene.materials.GetComponent(materialEntity); material.baseColor = XMFLOAT4(obj_material.diffuse[0], obj_material.diffuse[1], obj_material.diffuse[2], 1); - material.baseColorMapName = obj_material.diffuse_texname; - material.displacementMapName = obj_material.displacement_texname; + material.textures[MaterialComponent::BASECOLORMAP].name = obj_material.diffuse_texname; + material.textures[MaterialComponent::DISPLACEMENTMAP].name = obj_material.displacement_texname; material.emissiveColor.x = obj_material.emission[0]; material.emissiveColor.y = obj_material.emission[1]; material.emissiveColor.z = obj_material.emission[2]; material.emissiveColor.w = max(obj_material.emission[0], max(obj_material.emission[1], obj_material.emission[2])); //material.refractionIndex = obj_material.ior; material.metalness = obj_material.metallic; - material.normalMapName = obj_material.normal_texname; - material.surfaceMapName = obj_material.specular_texname; + material.textures[MaterialComponent::NORMALMAP].name = obj_material.normal_texname; + material.textures[MaterialComponent::SURFACEMAP].name = obj_material.specular_texname; material.roughness = obj_material.roughness; - if (material.normalMapName.empty()) + if (material.textures[MaterialComponent::NORMALMAP].name.empty()) { - material.normalMapName = obj_material.bump_texname; + material.textures[MaterialComponent::NORMALMAP].name = obj_material.bump_texname; } - if (material.surfaceMapName.empty()) + if (material.textures[MaterialComponent::SURFACEMAP].name.empty()) { - material.surfaceMapName = obj_material.specular_highlight_texname; + material.textures[MaterialComponent::SURFACEMAP].name = obj_material.specular_highlight_texname; } - if (!material.surfaceMapName.empty()) - { - material.surfaceMap = wiResourceManager::Load(directory + material.surfaceMapName); - } - if (!material.baseColorMapName.empty()) - { - material.baseColorMap = wiResourceManager::Load(directory + material.baseColorMapName); - } - if (!material.normalMapName.empty()) - { - material.normalMap = wiResourceManager::Load(directory + material.normalMapName); - } - if (!material.displacementMapName.empty()) - { - material.displacementMap = wiResourceManager::Load(directory + material.displacementMapName); - } + material.CreateRenderData(directory); materialLibrary.push_back(materialEntity); // for subset-indexing... } diff --git a/Editor/PaintToolWindow.cpp b/Editor/PaintToolWindow.cpp index 679dee6e2..fd8b86852 100644 --- a/Editor/PaintToolWindow.cpp +++ b/Editor/PaintToolWindow.cpp @@ -132,12 +132,18 @@ void PaintToolWindow::Create(EditorComponent* editor) textureSlotComboBox.SetTooltip("Choose texture slot of the selected material to paint (texture paint mode only)"); textureSlotComboBox.SetPos(XMFLOAT2(x, y += step)); textureSlotComboBox.SetSize(XMFLOAT2(200, hei)); - textureSlotComboBox.AddItem("BaseColor (RGBA)"); - textureSlotComboBox.AddItem("Normal (RGB)"); - textureSlotComboBox.AddItem("SurfaceMap (RGBA)"); - textureSlotComboBox.AddItem("DisplacementMap (R)"); - textureSlotComboBox.AddItem("EmissiveMap (RGBA)"); - textureSlotComboBox.AddItem("OcclusionMap (R)"); + textureSlotComboBox.AddItem("BaseColor (RGBA)", MaterialComponent::BASECOLORMAP); + textureSlotComboBox.AddItem("Normal (RGB)", MaterialComponent::NORMALMAP); + textureSlotComboBox.AddItem("SurfaceMap (RGBA)", MaterialComponent::SURFACEMAP); + textureSlotComboBox.AddItem("DisplacementMap (R)", MaterialComponent::DISPLACEMENTMAP); + textureSlotComboBox.AddItem("EmissiveMap (RGBA)", MaterialComponent::EMISSIVEMAP); + textureSlotComboBox.AddItem("OcclusionMap (R)", MaterialComponent::OCCLUSIONMAP); + textureSlotComboBox.AddItem("TransmissionMap (R)", MaterialComponent::TRANSMISSIONMAP); + textureSlotComboBox.AddItem("SheenColorMap (R)", MaterialComponent::SHEENCOLORMAP); + textureSlotComboBox.AddItem("SheenRoughMap (R)", MaterialComponent::SHEENROUGHNESSMAP); + textureSlotComboBox.AddItem("ClearcoatMap (R)", MaterialComponent::CLEARCOATMAP); + textureSlotComboBox.AddItem("ClearcoatRoughMap (R)", MaterialComponent::CLEARCOATROUGHNESSMAP); + textureSlotComboBox.AddItem("ClearcoatNormMap (R)", MaterialComponent::CLEARCOATNORMALMAP); textureSlotComboBox.SetSelected(0); textureSlotComboBox.SetEnabled(false); AddWidget(&textureSlotComboBox); @@ -166,29 +172,8 @@ void PaintToolWindow::Create(EditorComponent* editor) std::string* slotname = nullptr; - int sel = textureSlotComboBox.GetSelected(); - switch (sel) - { - default: - case 0: - slotname = &material->baseColorMapName; - break; - case 1: - slotname = &material->normalMapName; - break; - case 2: - slotname = &material->surfaceMapName; - break; - case 3: - slotname = &material->displacementMapName; - break; - case 4: - slotname = &material->emissiveMapName; - break; - case 5: - slotname = &material->occlusionMapName; - break; - } + uint64_t sel = textureSlotComboBox.GetItemUserData(textureSlotComboBox.GetSelected()); + slotname = &material->textures[sel].name; wiHelper::RemoveExtensionFromFileName(*slotname); *slotname = *slotname + "_0.png"; @@ -1259,53 +1244,13 @@ void PaintToolWindow::ConsumeHistoryOperation(wiArchive& archive, bool undo) } std::shared_ptr PaintToolWindow::GetEditTextureSlot(const MaterialComponent& material, int* uvset) { - int sel = textureSlotComboBox.GetSelected(); - switch (sel) - { - default: - case 0: - if (uvset) *uvset = material.uvset_baseColorMap; - return material.baseColorMap; - case 1: - if (uvset) *uvset = material.uvset_normalMap; - return material.normalMap; - case 2: - if (uvset) *uvset = material.uvset_surfaceMap; - return material.surfaceMap; - case 3: - if (uvset) *uvset = material.uvset_displacementMap; - return material.displacementMap; - case 4: - if (uvset) *uvset = material.uvset_emissiveMap; - return material.emissiveMap; - case 5: - if (uvset) *uvset = material.uvset_occlusionMap; - return material.occlusionMap; - } + uint64_t sel = textureSlotComboBox.GetItemUserData(textureSlotComboBox.GetSelected()); + if (uvset) + *uvset = material.textures[sel].uvset; + return material.textures[sel].resource; } void PaintToolWindow::ReplaceEditTextureSlot(wiScene::MaterialComponent& material, std::shared_ptr resource) { - int sel = textureSlotComboBox.GetSelected(); - switch (sel) - { - default: - case 0: - material.baseColorMap = resource; - break; - case 1: - material.normalMap = resource; - break; - case 2: - material.surfaceMap = resource; - break; - case 3: - material.displacementMap = resource; - break; - case 4: - material.emissiveMap = resource; - break; - case 5: - material.occlusionMap = resource; - break; - } + uint64_t sel = textureSlotComboBox.GetItemUserData(textureSlotComboBox.GetSelected()); + material.textures[sel].resource = resource; } diff --git a/WickedEngine/objectHF.hlsli b/WickedEngine/objectHF.hlsli index 64e0e17a9..9f1cfe95f 100644 --- a/WickedEngine/objectHF.hlsli +++ b/WickedEngine/objectHF.hlsli @@ -243,9 +243,9 @@ struct VertexSurface uint normal_wind = asuint(input.pos.w); - normal.x = (float)((normal_wind >> 0) & 0xFF) / 255.0f * 2.0f - 1.0f; - normal.y = (float)((normal_wind >> 8) & 0xFF) / 255.0f * 2.0f - 1.0f; - normal.z = (float)((normal_wind >> 16) & 0xFF) / 255.0f * 2.0f - 1.0f; + normal.x = (float)((normal_wind >> 0) & 0xFF) / 255.0 * 2 - 1; + normal.y = (float)((normal_wind >> 8) & 0xFF) / 255.0 * 2 - 1; + normal.z = (float)((normal_wind >> 16) & 0xFF) / 255.0 * 2 - 1; normal = normalize(mul((float3x3)WORLD, normal)); #ifdef OBJECTSHADER_INPUT_TAN @@ -256,7 +256,7 @@ struct VertexSurface #ifdef OBJECTSHADER_USE_WIND if (material.IsUsingWind()) { - const float windweight = ((normal_wind >> 24) & 0xFF) / 255.0f; + const float windweight = ((normal_wind >> 24) & 0xFF) / 255.0; const float waveoffset = dot(position.xyz, g_xFrame_WindDirection) * g_xFrame_WindWaveSize + (position.x + position.y + position.z) * g_xFrame_WindRandomness; const float waveoffsetPrev = dot(positionPrev.xyz, g_xFrame_WindDirection) * g_xFrame_WindWaveSize + (positionPrev.x + positionPrev.y + positionPrev.z) * g_xFrame_WindRandomness; const float3 wavedir = g_xFrame_WindDirection * windweight; @@ -287,7 +287,7 @@ struct VertexSurface struct PixelInput { - float4 pos : SV_POSITION; + precise float4 pos : SV_POSITION; #ifdef OBJECTSHADER_USE_CLIPPLANE float clip : SV_ClipDistance0; diff --git a/WickedEngine/wiEmittedParticle.cpp b/WickedEngine/wiEmittedParticle.cpp index f4d51f63a..c7b062f6e 100644 --- a/WickedEngine/wiEmittedParticle.cpp +++ b/WickedEngine/wiEmittedParticle.cpp @@ -541,7 +541,14 @@ void wiEmittedParticle::Draw(const CameraComponent& camera, const MaterialCompon { const BLENDMODE blendMode = material.GetBlendMode(); device->BindPipelineState(&PSO[blendMode][shaderType], cmd); - device->BindResource(PS, material.GetBaseColorMap(), TEXSLOT_ONDEMAND0, cmd); + if (material.textures[MaterialComponent::BASECOLORMAP].resource == nullptr) + { + device->BindResource(PS, wiTextureHelper::getWhite(), TEXSLOT_ONDEMAND0, cmd); + } + else + { + device->BindResource(PS, material.textures[MaterialComponent::BASECOLORMAP].GetGPUResource(), TEXSLOT_ONDEMAND0, cmd); + } device->BindShadingRate(material.shadingRate, cmd); } diff --git a/WickedEngine/wiGPUBVH.cpp b/WickedEngine/wiGPUBVH.cpp index 3d162cae4..a3eee934e 100644 --- a/WickedEngine/wiGPUBVH.cpp +++ b/WickedEngine/wiGPUBVH.cpp @@ -48,21 +48,21 @@ void wiGPUBVH::UpdateGlobalMaterialResources(const Scene& scene, CommandList cmd { const MaterialComponent& material = *scene.materials.GetComponent(subset.materialID); - if (material.baseColorMap != nullptr) + if (material.textures[MaterialComponent::BASECOLORMAP].resource != nullptr) { - sceneTextures.insert(material.baseColorMap); + sceneTextures.insert(material.textures[MaterialComponent::BASECOLORMAP].resource); } - if (material.surfaceMap != nullptr) + if (material.textures[MaterialComponent::SURFACEMAP].resource != nullptr) { - sceneTextures.insert(material.surfaceMap); + sceneTextures.insert(material.textures[MaterialComponent::SURFACEMAP].resource); } - if (material.emissiveMap != nullptr) + if (material.textures[MaterialComponent::EMISSIVEMAP].resource != nullptr) { - sceneTextures.insert(material.emissiveMap); + sceneTextures.insert(material.textures[MaterialComponent::EMISSIVEMAP].resource); } - if (material.normalMap != nullptr) + if (material.textures[MaterialComponent::NORMALMAP].resource != nullptr) { - sceneTextures.insert(material.normalMap); + sceneTextures.insert(material.textures[MaterialComponent::NORMALMAP].resource); } } } @@ -150,9 +150,9 @@ void wiGPUBVH::UpdateGlobalMaterialResources(const Scene& scene, CommandList cmd // Add extended properties: const TextureDesc& desc = globalMaterialAtlas.GetDesc(); - if (material.baseColorMap != nullptr) + if (material.textures[MaterialComponent::BASECOLORMAP].resource != nullptr) { - rect_xywh rect = storedTextures[material.baseColorMap]; + rect_xywh rect = storedTextures[material.textures[MaterialComponent::BASECOLORMAP].resource]; // eliminate border expansion: rect.x += atlasWrapBorder; rect.y += atlasWrapBorder; @@ -162,9 +162,9 @@ void wiGPUBVH::UpdateGlobalMaterialResources(const Scene& scene, CommandList cmd (float)rect.x / (float)desc.Width, (float)rect.y / (float)desc.Height); } - if (material.surfaceMap != nullptr) + if (material.textures[MaterialComponent::SURFACEMAP].resource != nullptr) { - rect_xywh rect = storedTextures[material.surfaceMap]; + rect_xywh rect = storedTextures[material.textures[MaterialComponent::SURFACEMAP].resource]; // eliminate border expansion: rect.x += atlasWrapBorder; rect.y += atlasWrapBorder; @@ -174,9 +174,9 @@ void wiGPUBVH::UpdateGlobalMaterialResources(const Scene& scene, CommandList cmd (float)rect.x / (float)desc.Width, (float)rect.y / (float)desc.Height); } - if (material.emissiveMap != nullptr) + if (material.textures[MaterialComponent::EMISSIVEMAP].resource != nullptr) { - rect_xywh rect = storedTextures[material.emissiveMap]; + rect_xywh rect = storedTextures[material.textures[MaterialComponent::EMISSIVEMAP].resource]; // eliminate border expansion: rect.x += atlasWrapBorder; rect.y += atlasWrapBorder; @@ -186,9 +186,9 @@ void wiGPUBVH::UpdateGlobalMaterialResources(const Scene& scene, CommandList cmd (float)rect.x / (float)desc.Width, (float)rect.y / (float)desc.Height); } - if (material.normalMap != nullptr) + if (material.textures[MaterialComponent::NORMALMAP].resource != nullptr) { - rect_xywh rect = storedTextures[material.normalMap]; + rect_xywh rect = storedTextures[material.textures[MaterialComponent::NORMALMAP].resource]; // eliminate border expansion: rect.x += atlasWrapBorder; rect.y += atlasWrapBorder; diff --git a/WickedEngine/wiGraphicsDevice_SharedInternals.h b/WickedEngine/wiGraphicsDevice_SharedInternals.h index 30be4267d..8a91f265f 100644 --- a/WickedEngine/wiGraphicsDevice_SharedInternals.h +++ b/WickedEngine/wiGraphicsDevice_SharedInternals.h @@ -2,9 +2,8 @@ #define WI_GRAPHICSDEVICE_SHAREDINTERNALS_H // Descriptor layout counts per shader stage: -// Rebuilding shaders and graphics devices are necessary after changing these values -#define GPU_RESOURCE_HEAP_CBV_COUNT 12 -#define GPU_RESOURCE_HEAP_SRV_COUNT 48 +#define GPU_RESOURCE_HEAP_CBV_COUNT 15 +#define GPU_RESOURCE_HEAP_SRV_COUNT 64 #define GPU_RESOURCE_HEAP_UAV_COUNT 8 #define GPU_SAMPLER_HEAP_COUNT 16 diff --git a/WickedEngine/wiHairParticle.cpp b/WickedEngine/wiHairParticle.cpp index a2bd12b12..700d7433a 100644 --- a/WickedEngine/wiHairParticle.cpp +++ b/WickedEngine/wiHairParticle.cpp @@ -162,7 +162,11 @@ void wiHairParticle::UpdateGPU(const MeshComponent& mesh, const MaterialComponen GraphicsDevice* device = wiRenderer::GetDevice(); device->EventBegin("HairParticle - UpdateRenderData", cmd); - const TextureDesc& desc = material.GetBaseColorMap()->GetDesc(); + TextureDesc desc; + if (material.textures[MaterialComponent::BASECOLORMAP].resource != nullptr) + { + desc = material.textures[MaterialComponent::BASECOLORMAP].resource->texture->GetDesc(); + } HairParticleCB hcb; hcb.xWorld = world; @@ -184,7 +188,7 @@ void wiHairParticle::UpdateGPU(const MeshComponent& mesh, const MaterialComponen hcb.xHairFrameCount = std::max(1u, frameCount); hcb.xHairFrameStart = frameStart; hcb.xHairTexMul = float2(1.0f / (float)hcb.xHairFramesXY.x, 1.0f / (float)hcb.xHairFramesXY.y); - hcb.xHairAspect = (float)desc.Width / (float)desc.Height; + hcb.xHairAspect = (float)std::max(1u, desc.Width) / (float)std::max(1u, desc.Height); device->UpdateBuffer(&cb, &hcb, cmd); // Simulate: @@ -265,11 +269,16 @@ void wiHairParticle::Draw(const CameraComponent& camera, const MaterialComponent { device->BindPipelineState(&PSO[renderPass], cmd); - const GPUResource* res[] = { - material.GetBaseColorMap() - }; - device->BindResources(PS, res, TEXSLOT_ONDEMAND0, arraysize(res), cmd); - device->BindResources(VS, res, TEXSLOT_ONDEMAND0, arraysize(res), cmd); + if (material.textures[MaterialComponent::BASECOLORMAP].resource == nullptr) + { + device->BindResource(PS, wiTextureHelper::getWhite(), TEXSLOT_ONDEMAND0, cmd); + device->BindResource(VS, wiTextureHelper::getWhite(), TEXSLOT_ONDEMAND0, cmd); + } + else + { + device->BindResource(PS, material.textures[MaterialComponent::BASECOLORMAP].GetGPUResource(), TEXSLOT_ONDEMAND0, cmd); + device->BindResource(VS, material.textures[MaterialComponent::BASECOLORMAP].GetGPUResource(), TEXSLOT_ONDEMAND0, cmd); + } if (renderPass != RENDERPASS_PREPASS) // depth only alpha test will be full res { diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 720095759..3609db742 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -2903,30 +2903,13 @@ void RenderMeshes( device->BindConstantBuffer(PS, &material.constantBuffer, CB_GETBINDSLOT(MaterialCB), cmd); // Bind all material textures: - { - const GPUResource* res[] = { - material.GetBaseColorMap(), - material.GetNormalMap(), - material.GetSurfaceMap(), - material.GetEmissiveMap(), - material.GetDisplacementMap(), - material.GetOcclusionMap(), - material.GetTransmissionMap(), - material.GetSheenColorMap(), - material.GetSheenRoughnessMap(), - material.GetClearcoatMap(), - material.GetClearcoatRoughnessMap(), - material.GetClearcoatNormalMap(), - }; - device->BindResources(PS, res, TEXSLOT_RENDERER_BASECOLORMAP, arraysize(res), cmd); - } + const GPUResource* materialtextures[MaterialComponent::TEXTURESLOT_COUNT]; + material.WriteTextures(materialtextures, arraysize(materialtextures)); + device->BindResources(PS, materialtextures, TEXSLOT_RENDERER_BASECOLORMAP, arraysize(materialtextures), cmd); if (tessellatorRequested) { - const GPUResource* res[] = { - material.GetDisplacementMap(), - }; - device->BindResources(DS, res, TEXSLOT_RENDERER_DISPLACEMENTMAP, arraysize(res), cmd); + device->BindResources(DS, materialtextures, TEXSLOT_RENDERER_BASECOLORMAP, arraysize(materialtextures), cmd); device->BindConstantBuffer(DS, &material.constantBuffer, CB_GETBINDSLOT(MaterialCB), cmd); } @@ -2934,72 +2917,42 @@ void RenderMeshes( { if (mesh.terrain_material1 == INVALID_ENTITY || !vis.scene->materials.Contains(mesh.terrain_material1)) { - const GPUResource* res[] = { - material.GetBaseColorMap(), - material.GetNormalMap(), - material.GetSurfaceMap(), - material.GetEmissiveMap(), - }; - device->BindResources(PS, res, TEXSLOT_RENDERER_BLEND1_BASECOLORMAP, arraysize(res), cmd); + device->BindResources(PS, materialtextures, TEXSLOT_RENDERER_BLEND1_BASECOLORMAP, 4, cmd); device->BindConstantBuffer(PS, &material.constantBuffer, CB_GETBINDSLOT(MaterialCB_Blend1), cmd); } else { const MaterialComponent& blendmat = *vis.scene->materials.GetComponent(mesh.terrain_material1); - const GPUResource* res[] = { - blendmat.GetBaseColorMap(), - blendmat.GetNormalMap(), - blendmat.GetSurfaceMap(), - blendmat.GetEmissiveMap(), - }; + const GPUResource* res[4]; + blendmat.WriteTextures(res, arraysize(res)); device->BindResources(PS, res, TEXSLOT_RENDERER_BLEND1_BASECOLORMAP, arraysize(res), cmd); device->BindConstantBuffer(PS, &blendmat.constantBuffer, CB_GETBINDSLOT(MaterialCB_Blend1), cmd); } if (mesh.terrain_material2 == INVALID_ENTITY || !vis.scene->materials.Contains(mesh.terrain_material2)) { - const GPUResource* res[] = { - material.GetBaseColorMap(), - material.GetNormalMap(), - material.GetSurfaceMap(), - material.GetEmissiveMap(), - }; - device->BindResources(PS, res, TEXSLOT_RENDERER_BLEND2_BASECOLORMAP, arraysize(res), cmd); + device->BindResources(PS, materialtextures, TEXSLOT_RENDERER_BLEND2_BASECOLORMAP, 4, cmd); device->BindConstantBuffer(PS, &material.constantBuffer, CB_GETBINDSLOT(MaterialCB_Blend2), cmd); } else { const MaterialComponent& blendmat = *vis.scene->materials.GetComponent(mesh.terrain_material2); - const GPUResource* res[] = { - blendmat.GetBaseColorMap(), - blendmat.GetNormalMap(), - blendmat.GetSurfaceMap(), - blendmat.GetEmissiveMap(), - }; + const GPUResource* res[4]; + blendmat.WriteTextures(res, arraysize(res)); device->BindResources(PS, res, TEXSLOT_RENDERER_BLEND2_BASECOLORMAP, arraysize(res), cmd); device->BindConstantBuffer(PS, &blendmat.constantBuffer, CB_GETBINDSLOT(MaterialCB_Blend2), cmd); } if (mesh.terrain_material3 == INVALID_ENTITY || !vis.scene->materials.Contains(mesh.terrain_material3)) { - const GPUResource* res[] = { - material.GetBaseColorMap(), - material.GetNormalMap(), - material.GetSurfaceMap(), - material.GetEmissiveMap(), - }; - device->BindResources(PS, res, TEXSLOT_RENDERER_BLEND3_BASECOLORMAP, arraysize(res), cmd); + device->BindResources(PS, materialtextures, TEXSLOT_RENDERER_BLEND3_BASECOLORMAP, 4, cmd); device->BindConstantBuffer(PS, &material.constantBuffer, CB_GETBINDSLOT(MaterialCB_Blend3), cmd); } else { const MaterialComponent& blendmat = *vis.scene->materials.GetComponent(mesh.terrain_material3); - const GPUResource* res[] = { - blendmat.GetBaseColorMap(), - blendmat.GetNormalMap(), - blendmat.GetSurfaceMap(), - blendmat.GetEmissiveMap(), - }; + const GPUResource* res[4]; + blendmat.WriteTextures(res, arraysize(res)); device->BindResources(PS, res, TEXSLOT_RENDERER_BLEND3_BASECOLORMAP, arraysize(res), cmd); device->BindConstantBuffer(PS, &blendmat.constantBuffer, CB_GETBINDSLOT(MaterialCB_Blend3), cmd); } @@ -6192,17 +6145,29 @@ void DrawDebugWorld( const GPUBuffer* vbs[] = { mesh.streamoutBuffer_POS.IsValid() ? &mesh.streamoutBuffer_POS : &mesh.vertexBuffer_POS, + nullptr, &mesh.vertexBuffer_UV0, &mesh.vertexBuffer_UV1, + nullptr, + nullptr, + nullptr, mem.buffer }; uint32_t strides[] = { + sizeof(MeshComponent::Vertex_POS), sizeof(MeshComponent::Vertex_POS), sizeof(MeshComponent::Vertex_TEX), sizeof(MeshComponent::Vertex_TEX), + sizeof(MeshComponent::Vertex_TEX), + sizeof(MeshComponent::Vertex_COL), + sizeof(MeshComponent::Vertex_TAN), sizeof(Instance) }; uint32_t offsets[] = { + 0, + 0, + 0, + 0, 0, 0, 0, @@ -6993,11 +6958,8 @@ void RefreshImpostors(const Scene& scene, CommandList cmd) device->BindConstantBuffer(VS, &material.constantBuffer, CB_GETBINDSLOT(MaterialCB), cmd); device->BindConstantBuffer(PS, &material.constantBuffer, CB_GETBINDSLOT(MaterialCB), cmd); - const GPUResource* res[] = { - material.GetBaseColorMap(), - material.GetNormalMap(), - material.GetSurfaceMap(), - }; + const GPUResource* res[4]; + material.WriteTextures(res, arraysize(res)); device->BindResources(PS, res, TEXSLOT_ONDEMAND0, arraysize(res), cmd); device->DrawIndexedInstanced(subset.indexCount, 1, subset.indexOffset, 0, 0, cmd); diff --git a/WickedEngine/wiScene.cpp b/WickedEngine/wiScene.cpp index 756f73981..cdec0c245 100644 --- a/WickedEngine/wiScene.cpp +++ b/WickedEngine/wiScene.cpp @@ -224,102 +224,6 @@ namespace wiScene XMStoreFloat3(&scale_local, S); } - const Texture* MaterialComponent::GetBaseColorMap() const - { - if (baseColorMap != nullptr) - { - return baseColorMap->texture; - } - return wiTextureHelper::getWhite(); - } - const Texture* MaterialComponent::GetNormalMap() const - { - if (normalMap != nullptr) - { - return normalMap->texture; - } - return nullptr; - } - const Texture* MaterialComponent::GetSurfaceMap() const - { - if (surfaceMap != nullptr) - { - return surfaceMap->texture; - } - return wiTextureHelper::getWhite(); - } - const Texture* MaterialComponent::GetDisplacementMap() const - { - if (displacementMap != nullptr) - { - return displacementMap->texture; - } - return wiTextureHelper::getWhite(); - } - const Texture* MaterialComponent::GetEmissiveMap() const - { - if (emissiveMap != nullptr) - { - return emissiveMap->texture; - } - return wiTextureHelper::getWhite(); - } - const Texture* MaterialComponent::GetOcclusionMap() const - { - if (occlusionMap != nullptr) - { - return occlusionMap->texture; - } - return wiTextureHelper::getWhite(); - } - const Texture* MaterialComponent::GetTransmissionMap() const - { - if (transmissionMap != nullptr) - { - return transmissionMap->texture; - } - return wiTextureHelper::getWhite(); - } - const Texture* MaterialComponent::GetSheenColorMap() const - { - if (sheenColorMap != nullptr) - { - return sheenColorMap->texture; - } - return wiTextureHelper::getWhite(); - } - const Texture* MaterialComponent::GetSheenRoughnessMap() const - { - if (sheenRoughnessMap != nullptr) - { - return sheenRoughnessMap->texture; - } - return wiTextureHelper::getWhite(); - } - const Texture* MaterialComponent::GetClearcoatMap() const - { - if (clearcoatMap != nullptr) - { - return clearcoatMap->texture; - } - return nullptr; - } - const Texture* MaterialComponent::GetClearcoatRoughnessMap() const - { - if (clearcoatRoughnessMap != nullptr) - { - return clearcoatRoughnessMap->texture; - } - return nullptr; - } - const Texture* MaterialComponent::GetClearcoatNormalMap() const - { - if (clearcoatNormalMap != nullptr) - { - return clearcoatNormalMap->texture; - } - return nullptr; - } void MaterialComponent::WriteShaderMaterial(ShaderMaterial* dest) const { dest->baseColor = baseColor; @@ -330,7 +234,7 @@ namespace wiScene dest->reflectance = reflectance; dest->metalness = metalness; dest->refraction = refraction; - dest->normalMapStrength = (normalMap == nullptr ? 0 : normalMapStrength); + dest->normalMapStrength = (textures[NORMALMAP].resource == nullptr ? 0 : normalMapStrength); dest->parallaxOcclusionMapping = parallaxOcclusionMapping; dest->displacementMapping = displacementMapping; dest->subsurfaceScattering = subsurfaceScattering; @@ -341,18 +245,18 @@ namespace wiScene dest->subsurfaceScattering_inv.y = 1.0f / ((1 + dest->subsurfaceScattering.y) * (1 + dest->subsurfaceScattering.y)); dest->subsurfaceScattering_inv.z = 1.0f / ((1 + dest->subsurfaceScattering.z) * (1 + dest->subsurfaceScattering.z)); dest->subsurfaceScattering_inv.w = 1.0f / ((1 + dest->subsurfaceScattering.w) * (1 + dest->subsurfaceScattering.w)); - dest->uvset_baseColorMap = baseColorMap == nullptr ? -1 : (int)uvset_baseColorMap; - dest->uvset_surfaceMap = surfaceMap == nullptr ? -1 : (int)uvset_surfaceMap; - dest->uvset_normalMap = normalMap == nullptr ? -1 : (int)uvset_normalMap; - dest->uvset_displacementMap = displacementMap == nullptr ? -1 : (int)uvset_displacementMap; - dest->uvset_emissiveMap = emissiveMap == nullptr ? -1 : (int)uvset_emissiveMap; - dest->uvset_occlusionMap = occlusionMap == nullptr ? -1 : (int)uvset_occlusionMap; - dest->uvset_transmissionMap = transmissionMap == nullptr ? -1 : (int)uvset_transmissionMap; - dest->uvset_sheenColorMap = sheenColorMap == nullptr ? -1 : (int)uvset_sheenColorMap; - dest->uvset_sheenRoughnessMap = sheenRoughnessMap == nullptr ? -1 : (int)uvset_sheenRoughnessMap; - dest->uvset_clearcoatMap = clearcoatMap == nullptr ? -1 : (int)uvset_clearcoatMap; - dest->uvset_clearcoatRoughnessMap = clearcoatRoughnessMap == nullptr ? -1 : (int)uvset_clearcoatRoughnessMap; - dest->uvset_clearcoatNormalMap = clearcoatNormalMap == nullptr ? -1 : (int)uvset_clearcoatNormalMap; + dest->uvset_baseColorMap = textures[BASECOLORMAP].GetUVSet(); + dest->uvset_surfaceMap = textures[SURFACEMAP].GetUVSet(); + dest->uvset_normalMap = textures[NORMALMAP].GetUVSet(); + dest->uvset_displacementMap = textures[DISPLACEMENTMAP].GetUVSet(); + dest->uvset_emissiveMap = textures[EMISSIVEMAP].GetUVSet(); + dest->uvset_occlusionMap = textures[OCCLUSIONMAP].GetUVSet(); + dest->uvset_transmissionMap = textures[TRANSMISSIONMAP].GetUVSet(); + dest->uvset_sheenColorMap = textures[SHEENCOLORMAP].GetUVSet(); + dest->uvset_sheenRoughnessMap = textures[SHEENROUGHNESSMAP].GetUVSet(); + dest->uvset_clearcoatMap = textures[CLEARCOATMAP].GetUVSet(); + dest->uvset_clearcoatRoughnessMap = textures[CLEARCOATROUGHNESSMAP].GetUVSet(); + dest->uvset_clearcoatNormalMap = textures[CLEARCOATNORMALMAP].GetUVSet(); dest->sheenColor = sheenColor; dest->sheenRoughness = sheenRoughness; dest->clearcoat = clearcoat; @@ -387,6 +291,14 @@ namespace wiScene dest->emissiveMapAtlasMulAdd = XMFLOAT4(0, 0, 0, 0); dest->normalMapAtlasMulAdd = XMFLOAT4(0, 0, 0, 0); } + void MaterialComponent::WriteTextures(const wiGraphics::GPUResource** dest, int count) const + { + count = std::min(count, (int)TEXTURESLOT_COUNT); + for (int i = 0; i < count; ++i) + { + dest[i] = textures[i].GetGPUResource(); + } + } uint32_t MaterialComponent::GetRenderTypes() const { if (IsCustomShader() && customShaderID < (int)wiRenderer::GetCustomShaders().size()) @@ -410,55 +322,13 @@ namespace wiScene } void MaterialComponent::CreateRenderData(const std::string& content_dir) { - if (!baseColorMapName.empty()) + for (auto& x : textures) { - baseColorMap = wiResourceManager::Load(content_dir + baseColorMapName); + if (!x.name.empty()) + { + x.resource = wiResourceManager::Load(content_dir + x.name); + } } - if (!surfaceMapName.empty()) - { - surfaceMap = wiResourceManager::Load(content_dir + surfaceMapName); - } - if (!normalMapName.empty()) - { - normalMap = wiResourceManager::Load(content_dir + normalMapName); - } - if (!displacementMapName.empty()) - { - displacementMap = wiResourceManager::Load(content_dir + displacementMapName); - } - if (!emissiveMapName.empty()) - { - emissiveMap = wiResourceManager::Load(content_dir + emissiveMapName); - } - if (!occlusionMapName.empty()) - { - occlusionMap = wiResourceManager::Load(content_dir + occlusionMapName); - } - if (!transmissionMapName.empty()) - { - transmissionMap = wiResourceManager::Load(content_dir + transmissionMapName); - } - if (!sheenColorMapName.empty()) - { - sheenColorMap = wiResourceManager::Load(content_dir + sheenColorMapName); - } - if (!sheenRoughnessMapName.empty()) - { - sheenRoughnessMap = wiResourceManager::Load(content_dir + sheenRoughnessMapName); - } - if (!clearcoatMapName.empty()) - { - clearcoatMap = wiResourceManager::Load(content_dir + clearcoatMapName); - } - if (!clearcoatRoughnessMapName.empty()) - { - clearcoatRoughnessMap = wiResourceManager::Load(content_dir + clearcoatRoughnessMapName); - } - if (!clearcoatNormalMapName.empty()) - { - clearcoatNormalMap = wiResourceManager::Load(content_dir + clearcoatNormalMapName); - } - ShaderMaterial shadermat; WriteShaderMaterial(&shadermat); @@ -1820,17 +1690,9 @@ namespace wiScene decals.Create(entity); MaterialComponent& material = materials.Create(entity); - - if (!textureName.empty()) - { - material.baseColorMapName = textureName; - material.baseColorMap = wiResourceManager::Load(material.baseColorMapName); - } - if (!normalMapName.empty()) - { - material.normalMapName = normalMapName; - material.normalMap = wiResourceManager::Load(material.normalMapName); - } + material.textures[MaterialComponent::BASECOLORMAP].name = textureName; + material.textures[MaterialComponent::NORMALMAP].name = normalMapName; + material.CreateRenderData(); return entity; } @@ -2632,31 +2494,31 @@ namespace wiScene &descriptorTables[DESCRIPTORTABLE_SUBSETS_TEXTURES], 0, global_geometryIndex * MATERIAL_TEXTURE_SLOT_DESCRIPTOR_COUNT + MATERIAL_TEXTURE_SLOT_DESCRIPTOR_BASECOLOR, - material->baseColorMap ? material->baseColorMap->texture : nullptr + material->textures[MaterialComponent::BASECOLORMAP].GetGPUResource() ); device->WriteDescriptor( &descriptorTables[DESCRIPTORTABLE_SUBSETS_TEXTURES], 0, global_geometryIndex * MATERIAL_TEXTURE_SLOT_DESCRIPTOR_COUNT + MATERIAL_TEXTURE_SLOT_DESCRIPTOR_NORMAL, - material->normalMap ? material->normalMap->texture : nullptr + material->textures[MaterialComponent::NORMALMAP].GetGPUResource() ); device->WriteDescriptor( &descriptorTables[DESCRIPTORTABLE_SUBSETS_TEXTURES], 0, global_geometryIndex * MATERIAL_TEXTURE_SLOT_DESCRIPTOR_COUNT + MATERIAL_TEXTURE_SLOT_DESCRIPTOR_SURFACE, - material->surfaceMap ? material->surfaceMap->texture : nullptr + material->textures[MaterialComponent::SURFACEMAP].GetGPUResource() ); device->WriteDescriptor( &descriptorTables[DESCRIPTORTABLE_SUBSETS_TEXTURES], 0, global_geometryIndex * MATERIAL_TEXTURE_SLOT_DESCRIPTOR_COUNT + MATERIAL_TEXTURE_SLOT_DESCRIPTOR_OCCLUSION, - material->occlusionMap ? material->occlusionMap->texture : nullptr + material->textures[MaterialComponent::OCCLUSIONMAP].GetGPUResource() ); device->WriteDescriptor( &descriptorTables[DESCRIPTORTABLE_SUBSETS_TEXTURES], 0, global_geometryIndex * MATERIAL_TEXTURE_SLOT_DESCRIPTOR_COUNT + MATERIAL_TEXTURE_SLOT_DESCRIPTOR_EMISSIVE, - material->emissiveMap ? material->emissiveMap->texture : nullptr + material->textures[MaterialComponent::EMISSIVEMAP].GetGPUResource() ); device->WriteDescriptor( &descriptorTables[DESCRIPTORTABLE_SUBSETS_INDEXBUFFER], @@ -2994,8 +2856,8 @@ namespace wiScene const MaterialComponent& material = *materials.GetComponent(entity); decal.color = material.baseColor; decal.emissive = material.GetEmissiveStrength(); - decal.texture = material.baseColorMap; - decal.normal = material.normalMap; + decal.texture = material.textures[MaterialComponent::BASECOLORMAP].resource; + decal.normal = material.textures[MaterialComponent::NORMALMAP].resource; }); } void Scene::RunProbeUpdateSystem(wiJobSystem::context& ctx) diff --git a/WickedEngine/wiScene.h b/WickedEngine/wiScene.h index 3abe63f79..ec59d1d24 100644 --- a/WickedEngine/wiScene.h +++ b/WickedEngine/wiScene.h @@ -177,47 +177,46 @@ namespace wiScene float texAnimFrameRate = 0.0f; float texAnimElapsedTime = 0.0f; - std::string baseColorMapName; - std::string surfaceMapName; - std::string normalMapName; - std::string displacementMapName; - std::string emissiveMapName; - std::string occlusionMapName; - std::string transmissionMapName; - std::string sheenColorMapName; - std::string sheenRoughnessMapName; - std::string clearcoatMapName; - std::string clearcoatRoughnessMapName; - std::string clearcoatNormalMapName; + enum TEXTURESLOT + { + BASECOLORMAP, + NORMALMAP, + SURFACEMAP, + EMISSIVEMAP, + DISPLACEMENTMAP, + OCCLUSIONMAP, + TRANSMISSIONMAP, + SHEENCOLORMAP, + SHEENROUGHNESSMAP, + CLEARCOATMAP, + CLEARCOATROUGHNESSMAP, + CLEARCOATNORMALMAP, - uint32_t uvset_baseColorMap = 0; - uint32_t uvset_surfaceMap = 0; - uint32_t uvset_normalMap = 0; - uint32_t uvset_displacementMap = 0; - uint32_t uvset_emissiveMap = 0; - uint32_t uvset_occlusionMap = 0; - uint32_t uvset_transmissionMap = 0; - uint32_t uvset_sheenColorMap = 0; - uint32_t uvset_sheenRoughnessMap = 0; - uint32_t uvset_clearcoatMap = 0; - uint32_t uvset_clearcoatRoughnessMap = 0; - uint32_t uvset_clearcoatNormalMap = 0; + TEXTURESLOT_COUNT + }; + struct TextureMap + { + std::string name; + uint32_t uvset = 0; + std::shared_ptr resource; + const wiGraphics::GPUResource* GetGPUResource() const + { + if (resource == nullptr) + return nullptr; + return resource->texture; + } + int GetUVSet() const + { + if (resource == nullptr) + return -1; + return (int)uvset; + } + }; + TextureMap textures[TEXTURESLOT_COUNT]; int customShaderID = -1; // Non-serialized attributes: - std::shared_ptr baseColorMap; - std::shared_ptr surfaceMap; - std::shared_ptr normalMap; - std::shared_ptr displacementMap; - std::shared_ptr emissiveMap; - std::shared_ptr occlusionMap; - std::shared_ptr transmissionMap; - std::shared_ptr sheenColorMap; - std::shared_ptr sheenRoughnessMap; - std::shared_ptr clearcoatMap; - std::shared_ptr clearcoatRoughnessMap; - std::shared_ptr clearcoatNormalMap; wiGraphics::GPUBuffer constantBuffer; uint32_t layerMask = ~0u; @@ -229,19 +228,6 @@ namespace wiScene } uint32_t GetStencilRef() const; - const wiGraphics::Texture* GetBaseColorMap() const; - const wiGraphics::Texture* GetNormalMap() const; - const wiGraphics::Texture* GetSurfaceMap() const; - const wiGraphics::Texture* GetDisplacementMap() const; - const wiGraphics::Texture* GetEmissiveMap() const; - const wiGraphics::Texture* GetOcclusionMap() const; - const wiGraphics::Texture* GetTransmissionMap() const; - const wiGraphics::Texture* GetSheenColorMap() const; - const wiGraphics::Texture* GetSheenRoughnessMap() const; - const wiGraphics::Texture* GetClearcoatMap() const; - const wiGraphics::Texture* GetClearcoatRoughnessMap() const; - const wiGraphics::Texture* GetClearcoatNormalMap() const; - inline float GetOpacity() const { return baseColor.w; } inline float GetEmissiveStrength() const { return emissiveColor.w; } inline int GetCustomShaderID() const { return customShaderID; } @@ -300,22 +286,13 @@ namespace wiScene inline void SetClearcoatRoughness(float value) { clearcoatRoughness = value; SetDirty(); } inline void SetCustomShaderID(int id) { customShaderID = id; } inline void DisableCustomShader() { customShaderID = -1; } - inline void SetUVSet_BaseColorMap(uint32_t value) { uvset_baseColorMap = value; SetDirty(); } - inline void SetUVSet_NormalMap(uint32_t value) { uvset_normalMap = value; SetDirty(); } - inline void SetUVSet_SurfaceMap(uint32_t value) { uvset_surfaceMap = value; SetDirty(); } - inline void SetUVSet_DisplacementMap(uint32_t value) { uvset_displacementMap = value; SetDirty(); } - inline void SetUVSet_EmissiveMap(uint32_t value) { uvset_emissiveMap = value; SetDirty(); } - inline void SetUVSet_OcclusionMap(uint32_t value) { uvset_occlusionMap = value; SetDirty(); } - inline void SetUVSet_TransmissionMap(uint32_t value) { uvset_transmissionMap = value; SetDirty(); } - inline void SetUVSet_SheenColorMap(uint32_t value) { uvset_sheenColorMap = value; SetDirty(); } - inline void SetUVSet_SheenRoughnessMap(uint32_t value) { uvset_sheenRoughnessMap = value; SetDirty(); } - inline void SetUVSet_ClearcoatMap(uint32_t value) { uvset_clearcoatMap = value; SetDirty(); } - inline void SetUVSet_ClearcoatRoughnessMap(uint32_t value) { uvset_clearcoatRoughnessMap = value; SetDirty(); } - inline void SetUVSet_ClearcoatNormalMap(uint32_t value) { uvset_clearcoatNormalMap = value; SetDirty(); } // The MaterialComponent will be written to ShaderMaterial (a struct that is optimized for GPU use) void WriteShaderMaterial(ShaderMaterial* dest) const; + // Retrieve the array of textures from the material + void WriteTextures(const wiGraphics::GPUResource** dest, int count) const; + // Returns the bitwise OR of all the RENDERTYPE flags applicable to this material uint32_t GetRenderTypes() const; diff --git a/WickedEngine/wiScene_Serializers.cpp b/WickedEngine/wiScene_Serializers.cpp index e67e9a22d..6a2d5ce63 100644 --- a/WickedEngine/wiScene_Serializers.cpp +++ b/WickedEngine/wiScene_Serializers.cpp @@ -113,26 +113,26 @@ namespace wiScene archive >> texAnimFrameRate; archive >> texAnimElapsedTime; - archive >> baseColorMapName; - archive >> surfaceMapName; - archive >> normalMapName; - archive >> displacementMapName; + archive >> textures[BASECOLORMAP].name; + archive >> textures[SURFACEMAP].name; + archive >> textures[NORMALMAP].name; + archive >> textures[DISPLACEMENTMAP].name; if (archive.GetVersion() >= 24) { - archive >> emissiveMapName; + archive >> textures[EMISSIVEMAP].name; } if (archive.GetVersion() >= 28) { - archive >> occlusionMapName; + archive >> textures[OCCLUSIONMAP].name; - archive >> uvset_baseColorMap; - archive >> uvset_surfaceMap; - archive >> uvset_normalMap; - archive >> uvset_displacementMap; - archive >> uvset_emissiveMap; - archive >> uvset_occlusionMap; + archive >> textures[BASECOLORMAP].uvset; + archive >> textures[SURFACEMAP].uvset; + archive >> textures[NORMALMAP].uvset; + archive >> textures[DISPLACEMENTMAP].uvset; + archive >> textures[EMISSIVEMAP].uvset; + archive >> textures[OCCLUSIONMAP].uvset; archive >> displacementMapping; } @@ -182,27 +182,27 @@ namespace wiScene if (archive.GetVersion() >= 59) { archive >> transmission; - archive >> transmissionMapName; - archive >> uvset_transmissionMap; + archive >> textures[TRANSMISSIONMAP].name; + archive >> textures[TRANSMISSIONMAP].uvset; } if (archive.GetVersion() >= 61) { archive >> sheenColor; archive >> sheenRoughness; - archive >> sheenColorMapName; - archive >> sheenRoughnessMapName; - archive >> uvset_sheenColorMap; - archive >> uvset_sheenRoughnessMap; + archive >> textures[SHEENCOLORMAP].name; + archive >> textures[SHEENROUGHNESSMAP].name; + archive >> textures[SHEENCOLORMAP].uvset; + archive >> textures[SHEENROUGHNESSMAP].uvset; archive >> clearcoat; archive >> clearcoatRoughness; - archive >> clearcoatMapName; - archive >> clearcoatRoughnessMapName; - archive >> clearcoatNormalMapName; - archive >> uvset_clearcoatMap; - archive >> uvset_clearcoatRoughnessMap; - archive >> uvset_clearcoatNormalMap; + archive >> textures[CLEARCOATMAP].name; + archive >> textures[CLEARCOATROUGHNESSMAP].name; + archive >> textures[CLEARCOATNORMALMAP].name; + archive >> textures[CLEARCOATMAP].uvset; + archive >> textures[CLEARCOATROUGHNESSMAP].uvset; + archive >> textures[CLEARCOATNORMALMAP].uvset; } wiJobSystem::Execute(seri.ctx, [&](wiJobArgs args) { @@ -244,99 +244,36 @@ namespace wiScene // If detecting an absolute path in textures, remove it and convert to relative: if(!dir.empty()) { - size_t found = baseColorMapName.rfind(dir); - if (found != std::string::npos) + for (auto& x : textures) { - baseColorMapName = baseColorMapName.substr(found + dir.length()); - } - - found = surfaceMapName.rfind(dir); - if (found != std::string::npos) - { - surfaceMapName = surfaceMapName.substr(found + dir.length()); - } - - found = normalMapName.rfind(dir); - if (found != std::string::npos) - { - normalMapName = normalMapName.substr(found + dir.length()); - } - - found = displacementMapName.rfind(dir); - if (found != std::string::npos) - { - displacementMapName = displacementMapName.substr(found + dir.length()); - } - - found = emissiveMapName.rfind(dir); - if (found != std::string::npos) - { - emissiveMapName = emissiveMapName.substr(found + dir.length()); - } - - found = occlusionMapName.rfind(dir); - if (found != std::string::npos) - { - occlusionMapName = occlusionMapName.substr(found + dir.length()); - } - - found = transmissionMapName.rfind(dir); - if (found != std::string::npos) - { - transmissionMapName = transmissionMapName.substr(found + dir.length()); - } - - found = sheenColorMapName.rfind(dir); - if (found != std::string::npos) - { - sheenColorMapName = sheenColorMapName.substr(found + dir.length()); - } - - found = sheenRoughnessMapName.rfind(dir); - if (found != std::string::npos) - { - sheenRoughnessMapName = sheenRoughnessMapName.substr(found + dir.length()); - } - - found = clearcoatMapName.rfind(dir); - if (found != std::string::npos) - { - clearcoatMapName = clearcoatMapName.substr(found + dir.length()); - } - - found = clearcoatRoughnessMapName.rfind(dir); - if (found != std::string::npos) - { - clearcoatRoughnessMapName = clearcoatRoughnessMapName.substr(found + dir.length()); - } - - found = clearcoatNormalMapName.rfind(dir); - if (found != std::string::npos) - { - clearcoatNormalMapName = clearcoatNormalMapName.substr(found + dir.length()); + size_t found = x.name.rfind(dir); + if (found != std::string::npos) + { + x.name = x.name.substr(found + dir.length()); + } } } - archive << baseColorMapName; - archive << surfaceMapName; - archive << normalMapName; - archive << displacementMapName; + archive << textures[BASECOLORMAP].name; + archive << textures[SURFACEMAP].name; + archive << textures[NORMALMAP].name; + archive << textures[DISPLACEMENTMAP].name; if (archive.GetVersion() >= 24) { - archive << emissiveMapName; + archive << textures[EMISSIVEMAP].name; } if (archive.GetVersion() >= 28) { - archive << occlusionMapName; + archive << textures[OCCLUSIONMAP].name; - archive << uvset_baseColorMap; - archive << uvset_surfaceMap; - archive << uvset_normalMap; - archive << uvset_displacementMap; - archive << uvset_emissiveMap; - archive << uvset_occlusionMap; + archive << textures[BASECOLORMAP].uvset; + archive << textures[SURFACEMAP].uvset; + archive << textures[NORMALMAP].uvset; + archive << textures[DISPLACEMENTMAP].uvset; + archive << textures[EMISSIVEMAP].uvset; + archive << textures[OCCLUSIONMAP].uvset; archive << displacementMapping; } @@ -365,27 +302,27 @@ namespace wiScene if (archive.GetVersion() >= 59) { archive << transmission; - archive << transmissionMapName; - archive << uvset_transmissionMap; + archive << textures[TRANSMISSIONMAP].name; + archive << textures[TRANSMISSIONMAP].uvset; } if (archive.GetVersion() >= 61) { archive << sheenColor; archive << sheenRoughness; - archive << sheenColorMapName; - archive << sheenRoughnessMapName; - archive << uvset_sheenColorMap; - archive << uvset_sheenRoughnessMap; + archive << textures[SHEENCOLORMAP].name; + archive << textures[SHEENROUGHNESSMAP].name; + archive << textures[SHEENCOLORMAP].uvset; + archive << textures[SHEENROUGHNESSMAP].uvset; archive << clearcoat; archive << clearcoatRoughness; - archive << clearcoatMapName; - archive << clearcoatRoughnessMapName; - archive << clearcoatNormalMapName; - archive << uvset_clearcoatMap; - archive << uvset_clearcoatRoughnessMap; - archive << uvset_clearcoatNormalMap; + archive << textures[CLEARCOATMAP].name; + archive << textures[CLEARCOATROUGHNESSMAP].name; + archive << textures[CLEARCOATNORMALMAP].name; + archive << textures[CLEARCOATMAP].uvset; + archive << textures[CLEARCOATROUGHNESSMAP].uvset; + archive << textures[CLEARCOATNORMALMAP].uvset; } } } diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 3e6943ecf..c1042b891 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wiVersion // minor features, major updates, breaking compatibility changes const int minor = 52; // minor bug fixes, alterations, refactors, updates - const int revision = 19; + const int revision = 20; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);