Skip to content

Commit

Permalink
Initial working version with new mesh import/loading/saving
Browse files Browse the repository at this point in the history
  • Loading branch information
tippesi committed Aug 7, 2024
1 parent 194486e commit ac5886d
Show file tree
Hide file tree
Showing 39 changed files with 571 additions and 486 deletions.
8 changes: 4 additions & 4 deletions libs/ImguiExtension/panels/MaterialPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ namespace Atlas::ImguiExtension {
auto padding = 8.0f;
auto widthAfterImage = availableWidth - padding - ImGui::GetTextLineHeight();

auto renderWithImagePreview = [&](Ref<Texture::Texture2D>& texture, std::function<void(void)> element) {
if (texture != nullptr) {
UIElements::TexturePreview(wrapper, *texture);
auto renderWithImagePreview = [&](ResourceHandle<Texture::Texture2D>& texture, std::function<void(void)> element) {
if (texture.IsLoaded()) {
UIElements::TexturePreview(wrapper, *texture.Get());
ImGui::SameLine();
// Calculate next item width and push a width with the image elements width substracted from it
auto width = ImGui::CalcItemWidth();
ImGui::PushItemWidth(width - padding - ImGui::GetTextLineHeightWithSpacing());
}
element();
if (texture != nullptr)
if (texture.IsLoaded())
ImGui::PopItemWidth();
};

Expand Down
2 changes: 1 addition & 1 deletion src/demo/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <input/Keyboard.h>
#include <input/Controller.h>
#include <input/Touch.h>
#include <loader/ModelLoader.h>
#include <loader/ModelImporter.h>

#include <ImguiExtension/ImguiWrapper.h>
#include <ImguiExtension/Panels.h>
Expand Down
2 changes: 1 addition & 1 deletion src/editor/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <input/Keyboard.h>
#include <input/Controller.h>
#include <input/Touch.h>
#include <loader/ModelLoader.h>
#include <loader/ModelImporter.h>
#include <ImguiExtension/ImguiWrapper.h>

#include <renderer/PathTracingRenderer.h>
Expand Down
2 changes: 1 addition & 1 deletion src/editor/DataCreator.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "DataCreator.h"

#include "loader/ModelLoader.h"
#include "loader/ModelImporter.h"
#include "volume/AABB.h"

namespace Atlas::Editor {
Expand Down
2 changes: 1 addition & 1 deletion src/editor/FileImporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "scripting/Script.h"
#include "Font.h"

#include "loader/ModelLoader.h"
#include "loader/ModelImporter.h"

#include "Content.h"
#include "Serializer.h"
Expand Down
14 changes: 7 additions & 7 deletions src/engine/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,43 @@ namespace Atlas {

bool Material::HasBaseColorMap() const {

return baseColorMap ? true : false;
return baseColorMap.IsValid();

}

bool Material::HasOpacityMap() const {

return opacityMap ? true : false;
return opacityMap.IsValid();

}

bool Material::HasNormalMap() const {

return normalMap ? true : false;
return normalMap.IsValid();

}

bool Material::HasRoughnessMap() const {

return roughnessMap ? true : false;
return roughnessMap.IsValid();

}

bool Material::HasMetalnessMap() const {

return metalnessMap ? true : false;
return metalnessMap.IsValid();

}

bool Material::HasAoMap() const {

return aoMap ? true : false;
return aoMap.IsValid();

}

bool Material::HasDisplacementMap() const {

return displacementMap ? true : false;
return displacementMap.IsValid();

}

Expand Down
23 changes: 8 additions & 15 deletions src/engine/Material.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "texture/Texture2DArray.h"
#include "loader/ImageLoader.h"
#include "pipeline/PipelineConfig.h"
#include "resource/Resource.h"
#include "common/Ref.h"

#include <string>
Expand All @@ -29,13 +30,13 @@ namespace Atlas {

std::string name;

Ref<Texture::Texture2D> baseColorMap = nullptr;
Ref<Texture::Texture2D> opacityMap = nullptr;
Ref<Texture::Texture2D> normalMap = nullptr;
Ref<Texture::Texture2D> roughnessMap = nullptr;
Ref<Texture::Texture2D> metalnessMap = nullptr;
Ref<Texture::Texture2D> aoMap = nullptr;
Ref<Texture::Texture2D> displacementMap = nullptr;
ResourceHandle<Texture::Texture2D> baseColorMap;
ResourceHandle<Texture::Texture2D> opacityMap;
ResourceHandle<Texture::Texture2D> normalMap;
ResourceHandle<Texture::Texture2D> roughnessMap;
ResourceHandle<Texture::Texture2D> metalnessMap;
ResourceHandle<Texture::Texture2D> aoMap;
ResourceHandle<Texture::Texture2D> displacementMap;

vec3 baseColor = vec3(1.0f);
vec3 transmissiveColor = vec3(0.0f);
Expand All @@ -56,14 +57,6 @@ namespace Atlas {

float tiling = 1.0f;

std::string baseColorMapPath;
std::string opacityMapPath;
std::string normalMapPath;
std::string roughnessMapPath;
std::string metalnessMapPath;
std::string aoMapPath;
std::string displacementMapPath;

bool twoSided = false;
bool vertexColors = false;

Expand Down
24 changes: 24 additions & 0 deletions src/engine/Serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

#include "loader/AssetLoader.h"
#include "loader/TerrainLoader.h"
#include "loader/MeshLoader.h"
#include "loader/MaterialLoader.h"

#include <map>

namespace Atlas {

Expand All @@ -31,6 +35,26 @@ namespace Atlas {
fileStream << (formatJson ? j.dump(2) : j.dump());
}

if (saveDependencies) {
auto meshes = scene->GetMeshes();
std::map<Hash, ResourceHandle<Material>> materials;

for (const auto& mesh : meshes) {
if (!mesh.IsLoaded()) continue;

Loader::MeshLoader::SaveMesh(mesh.Get(), mesh.GetResource()->path);

for (const auto& material : mesh->data.materials)
materials[material.GetID()] = material;
}

for (const auto& [_, material] : materials) {
if (!material.IsLoaded()) continue;

Loader::MaterialLoader::SaveMaterial(material.Get(), material.GetResource()->path);
}
}

fileStream.close();

}
Expand Down
30 changes: 30 additions & 0 deletions src/engine/common/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ namespace Atlas {
*/
void GammaToLinear();

/**
* Converts the image data from linear to gamma color space.
* @note Converting the image data will result in a loss of data
* of the mipmap chain. Call GenerateMipmap() to generate it again.
*/
void LinearToGamma();

/**
* Flips image data horizontally.
* @note Flipping the image data will result in a loss of data
Expand Down Expand Up @@ -394,6 +401,8 @@ namespace Atlas {
ImageFormat fileFormat = ImageFormat::PNG;
std::string fileName = "";

bool srgbConversion = false;

private:
std::vector<MipLevel<T>> mipLevels;

Expand Down Expand Up @@ -758,6 +767,27 @@ namespace Atlas {

}

template<typename T>
void Image<T>::LinearToGamma() {

auto& data = mipLevels[0].data;
int32_t size = int32_t(data.size());

auto invMaxPixelValue = 1.0f / MaxPixelValue();
bool hasAlpha = channels == 4;

for (int32_t i = 0; i < size; i++) {
// Don't correct the alpha values
if (hasAlpha && (i + 1) % 4 == 0) continue;

float value = float(data[i]) * invMaxPixelValue;
value = powf(value, 1.0f / 2.2f);

data[i] = T(value * MaxPixelValue());
}

}

template<typename T>
void Image<T>::FlipHorizontally() {

Expand Down
36 changes: 36 additions & 0 deletions src/engine/lighting/LightingSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ namespace Atlas::Lighting {
{"rt", p.rt},
{"ddgi", p.ddgi},
{"useShadowMap", p.useShadowMap},
{"useNormalMaps", p.useNormalMaps},
{"opacityCheck", p.opacityCheck},
{"halfResolution", p.halfResolution}
};
Expand All @@ -153,11 +154,46 @@ namespace Atlas::Lighting {
j.at("rt").get_to(p.rt);
j.at("ddgi").get_to(p.ddgi);
j.at("useShadowMap").get_to(p.useShadowMap);
j.at("useNormalMaps").get_to(p.useNormalMaps);
j.at("opacityCheck").get_to(p.opacityCheck);
try_get_json(j, "halfResolution", p.halfResolution);
try_get_json(j, "roughnessCutoff", p.roughnessCutoff);
}

void to_json(json& j, const RTGI& p) {
j = json{
{"textureLevel", p.textureLevel},
{"radianceLimit", p.radianceLimit},
{"bias", p.bias},
{"spatialFilterStrength", p.spatialFilterStrength},
{"temporalWeight", p.temporalWeight},
{"historyClipMax", p.historyClipMax},
{"currentClipFactor", p.currentClipFactor},
{"enable", p.enable},
{"ddgi", p.ddgi},
{"useShadowMap", p.useShadowMap},
{"useNormalMap", p.useNormalMaps},
{"opacityCheck", p.opacityCheck},
{"halfResolution", p.halfResolution}
};
}

void from_json(const json& j, RTGI& p) {
j.at("textureLevel").get_to(p.textureLevel);
j.at("radianceLimit").get_to(p.radianceLimit);
j.at("bias").get_to(p.bias);
j.at("spatialFilterStrength").get_to(p.spatialFilterStrength);
j.at("temporalWeight").get_to(p.temporalWeight);
j.at("historyClipMax").get_to(p.historyClipMax);
j.at("currentClipFactor").get_to(p.currentClipFactor);
j.at("enable").get_to(p.enable);
j.at("ddgi").get_to(p.ddgi);
j.at("useShadowMap").get_to(p.useShadowMap);
j.at("useNormalMap").get_to(p.useNormalMaps);
j.at("opacityCheck").get_to(p.opacityCheck);
try_get_json(j, "halfResolution", p.halfResolution);
}

void to_json(json& j, const ShadowView& p) {
j = json {
{"nearDistance", p.nearDistance},
Expand Down
5 changes: 5 additions & 0 deletions src/engine/lighting/LightingSerializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "Shadow.h"
#include "AO.h"
#include "SSGI.h"
#include "RTGI.h"
#include "EnvironmentProbe.h"
#include "SSS.h"
#include "IrradianceVolume.h"
Expand Down Expand Up @@ -40,6 +41,10 @@ namespace Atlas::Lighting {

void from_json(const json& j, Reflection& p);

void to_json(json& j, const RTGI& p);

void from_json(const json& j, RTGI& p);

void to_json(json& j, const ShadowView& p);

void from_json(const json& j, ShadowView& p);
Expand Down
7 changes: 7 additions & 0 deletions src/engine/loader/ImageLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ namespace Atlas {
}

image.fileName = normalizedFileName;
image.srgbConversion = colorSpaceConversion;

Log::Message("Loaded image " + normalizedFileName);

Expand All @@ -128,6 +129,12 @@ namespace Atlas {
return;
}

/*
if (image->srgbConversion) {
image->LinearToGamma();
}
*/

auto lambda = [](void* context, void* data, int32_t size) {
auto imageStream = (std::ofstream*)context;

Expand Down
Loading

0 comments on commit ac5886d

Please sign in to comment.