Skip to content

Commit

Permalink
Some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tippesi committed Aug 9, 2024
1 parent d37a683 commit a9e7d08
Show file tree
Hide file tree
Showing 33 changed files with 118 additions and 59 deletions.
Binary file added data/editor/icons/material.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions data/editor/icons/material.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/editor/icons/material_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/editor/icons/meshSource.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions data/editor/icons/meshSource.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/editor/icons/meshSource_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion data/shader/globals.hsh
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ layout(set = 0, binding = 3) uniform texture2D bindlessTextures[TEXTURE_COUNT];

layout(set = 1, binding = 12) uniform sampler2D dfgTexture;

// Binding 2 is taken by materials buffer in common/material.hsh
layout(set = 1, binding = 13) uniform sampler bindlessSampler;
layout(set = 1, binding = 15) uniform sampler bindlessNearestSampler;
10 changes: 7 additions & 3 deletions data/shader/reflection/rtreflection.csh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ layout(std140, set = 3, binding = 9) uniform UniformBuffer {
float bias;
int textureLevel;
float roughnessCutoff;
float padding;
int halfRes;
ivec2 resolution;
Shadow shadow;
} uniforms;
Expand All @@ -74,8 +74,12 @@ void main() {

float depth = texelFetch(depthTexture, pixel, 0).r;

vec2 recontructTexCoord = (2.0 * (vec2(pixel)) + offset + 0.5) / (2.0 * vec2(resolution));
//vec2 recontructTexCoord = (2.0 * vec2(pixel) + 0.5) / (2.0 * vec2(resolution));
vec2 recontructTexCoord;
if (uniforms.halfRes > 0)
recontructTexCoord = (2.0 * (vec2(pixel)) + offset + 0.5) / (2.0 * vec2(resolution));
else
recontructTexCoord = (vec2(pixel) + 0.5) / (vec2(resolution));

vec3 viewPos = ConvertDepthToViewSpace(depth, recontructTexCoord);
vec3 worldPos = vec3(globalData.ivMatrix * vec4(viewPos, 1.0));
vec3 viewVec = vec3(globalData.ivMatrix * vec4(viewPos, 0.0));
Expand Down
13 changes: 7 additions & 6 deletions data/shader/rtgi/rtgi.csh
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ layout(set = 3, binding = 6) uniform sampler2DArrayShadow cascadeMaps;
layout(set = 3, binding = 7) uniform sampler2D scramblingRankingTexture;
layout(set = 3, binding = 8) uniform sampler2D sobolSequenceTexture;

#undef USE_SHADOW_MAP
#define OPACITY_CHECK

const ivec2 offsets[4] = ivec2[4](
ivec2(0, 0),
ivec2(1, 0),
Expand All @@ -51,7 +48,7 @@ layout(std140, set = 3, binding = 9) uniform UniformBuffer {
float bias;
int textureLevel;
float roughnessCutoff;
float padding;
int halfRes;
ivec2 resolution;
Shadow shadow;
} uniforms;
Expand All @@ -77,8 +74,12 @@ void main() {

float depth = texelFetch(depthTexture, pixel, 0).r;

// vec2 recontructTexCoord = (2.0 * (vec2(pixel) - 0.25 * globalData.jitterCurrent * vec2(resolution)) + offset + 0.5) / (2.0 * vec2(resolution));
vec2 recontructTexCoord = (2.0 * vec2(pixel) + 0.5) / (2.0 * vec2(resolution));
vec2 recontructTexCoord;
if (uniforms.halfRes > 0)
recontructTexCoord = (2.0 * (vec2(pixel)) + offset + 0.5) / (2.0 * vec2(resolution));
else
recontructTexCoord = (vec2(pixel) + 0.5) / (vec2(resolution));

vec3 viewPos = ConvertDepthToViewSpace(depth, recontructTexCoord);
vec3 worldPos = vec3(globalData.ivMatrix * vec4(viewPos, 1.0));
vec3 viewVec = vec3(globalData.ivMatrix * vec4(viewPos, 0.0));
Expand Down
4 changes: 2 additions & 2 deletions src/demo/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,13 @@ void App::Update(float deltaTime) {
if (!meshComponent.mesh.IsLoaded())
continue;

if (meshComponent.mesh->name == "chromesphere.gltf") {
if (meshComponent.mesh->name == "chromesphere") {
float height = (sinf(Atlas::Clock::Get() / 5.0f) + 1.0f) * 20.0f;
auto matrix = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, height, .0f));

transformComponent.Set(matrix);
}
else if (meshComponent.mesh->name == "metallicwall.gltf") {
else if (meshComponent.mesh->name == "metallicwall") {
auto matrix = glm::translate(glm::mat4(1.0f), glm::vec3(-50.0f, 0.0f, -2.0f));
matrix = glm::rotate(matrix, Atlas::Clock::Get() / 2.0f, glm::vec3(0.0f, 1.0f, 0.0f));

Expand Down
2 changes: 1 addition & 1 deletion src/editor/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ namespace Atlas::Editor {
ImGui::DockBuilderAddNode(dsID);

ImGuiID dsIdUp, dsIdDown;
ImGui::DockBuilderSplitNode(dsID, ImGuiDir_Up, 0.8f, &dsIdUp, &dsIdDown);
ImGui::DockBuilderSplitNode(dsID, ImGuiDir_Up, 0.7f, &dsIdUp, &dsIdDown);

for (auto& sceneWindow : sceneWindows) {
ImGui::DockBuilderDockWindow(sceneWindow->GetNameID(), dsIdUp);
Expand Down
14 changes: 8 additions & 6 deletions src/editor/Content.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ namespace Atlas::Editor {

const std::map<const std::string, ContentType> Content::contentTypeMapping = {
{ "wav", ContentType::Audio },
{ "gltf", ContentType::Mesh },
{ "glb", ContentType::Mesh },
{ "obj", ContentType::Mesh },
{ "fbx", ContentType::Mesh },
{ "usd", ContentType::Mesh },
{ "usda", ContentType::Mesh },
{ "aemesh", ContentType::Mesh },
{ "gltf", ContentType::MeshSource },
{ "glb", ContentType::MeshSource },
{ "obj", ContentType::MeshSource },
{ "fbx", ContentType::MeshSource },
{ "usd", ContentType::MeshSource },
{ "usda", ContentType::MeshSource },
{ "aematerial", ContentType::Material },
{ "aeterrain", ContentType::Terrain },
{ "aescene", ContentType::Scene },
{ "lua", ContentType::Script },
Expand Down
2 changes: 2 additions & 0 deletions src/editor/Content.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace Atlas::Editor {
enum class ContentType {
Audio = 0,
Mesh,
MeshSource,
Material,
Terrain,
Scene,
Script,
Expand Down
11 changes: 2 additions & 9 deletions src/editor/DataCreator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ namespace Atlas::Editor {
}

Ref<Scene::Scene> DataCreator::CreateSceneFromMesh(const std::string& filename, vec3 min, vec3 max,
int32_t depth, bool invertUVs, bool addRigidBodies, bool combineMeshes, bool makeMeshesStatic) {
int32_t depth, bool invertUVs, bool addRigidBodies, bool makeMeshesStatic) {

auto scene = Loader::ModelImporter::ImportScene(filename, min, max, depth,
combineMeshes, makeMeshesStatic, false, 2048);
true, makeMeshesStatic, invertUVs, 2048);

auto rootEntity = scene->GetEntityByName("Root");
auto& mainHierarchy = rootEntity.GetComponent<HierarchyComponent>();
Expand Down Expand Up @@ -142,13 +142,6 @@ namespace Atlas::Editor {

aabb.Grow(meshComponent.aabb);
}

if (invertUVs) {
auto meshes = scene->GetMeshes();

for (const auto& mesh : meshes)
mesh->invertUVs = true;
}

if (addRigidBodies) {
for (auto entity : meshSubset) {
Expand Down
2 changes: 1 addition & 1 deletion src/editor/DataCreator.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Atlas::Editor {
static Ref<Scene::Scene> CreateScene(const std::string& name, vec3 min, vec3 max, int32_t depth);

static Ref<Scene::Scene> CreateSceneFromMesh(const std::string& filename,vec3 min, vec3 max, int32_t depth,
bool invertUVs, bool addRigidBodies, bool combineMeshes, bool makeMeshesStatic);
bool invertUVs, bool addRigidBodies, bool makeMeshesStatic);

};

Expand Down
29 changes: 23 additions & 6 deletions src/editor/FileImporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
#include "Font.h"

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

#include "Content.h"
#include "Serializer.h"

namespace Atlas::Editor {


namespace Atlas::Editor {

class FileImporter {

Expand All @@ -42,13 +41,31 @@ namespace Atlas::Editor {

ResourceHandle<T> handle;

std::string fileType = Common::Path::GetFileType(filename);
std::transform(fileType.begin(), fileType.end(), fileType.begin(), ::tolower);

if (!Content::contentTypeMapping.contains(fileType))
return handle;

auto type = Content::contentTypeMapping.at(fileType);

if constexpr (std::is_same_v<T, Audio::AudioData>) {
handle = ResourceManager<Audio::AudioData>::GetOrLoadResourceAsync(
filename, ResourceOrigin::User);
}
else if constexpr (std::is_same_v<T, Mesh::Mesh>) {
handle = ResourceManager<Mesh::Mesh>::GetOrLoadResourceWithLoaderAsync(filename,
ResourceOrigin::User, Loader::ModelImporter::ImportMesh, false, 2048);
if (type == ContentType::MeshSource) {
auto resourcePath = Common::Path::GetFileNameWithoutExtension(filename) + ".aemesh";
auto loader = [filename](const std::string& resourcePath) -> auto {
return Loader::ModelImporter::ImportMesh(filename, true);
};
handle = ResourceManager<Mesh::Mesh>::GetOrLoadResourceWithLoaderAsync(resourcePath,
ResourceOrigin::User, std::function(loader));
}
else {
handle = ResourceManager<Mesh::Mesh>::GetOrLoadResourceWithLoaderAsync(filename,
ResourceOrigin::User, Loader::MeshLoader::LoadMesh, true);
}
}
else if constexpr (std::is_same_v<T, Scene::Scene>) {
handle = ResourceManager<Scene::Scene>::GetOrLoadResourceWithLoaderAsync(filename,
Expand Down Expand Up @@ -82,7 +99,7 @@ namespace Atlas::Editor {
return type == ContentType::Audio;
}
else if constexpr (std::is_same_v<T, Mesh::Mesh>) {
return type == ContentType::Mesh;
return type == ContentType::Mesh || type == ContentType::MeshSource;
}
else if constexpr (std::is_same_v<T, Scene::Scene>) {
return type == ContentType::Scene;
Expand Down
4 changes: 4 additions & 0 deletions src/editor/Icons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ namespace Atlas::Editor {
{ IconType::Scale, Texture::Texture2D("editor/icons/scale.png") },
{ IconType::Rotate, Texture::Texture2D("editor/icons/rotate.png") },
{ IconType::MoreHorizontal, Texture::Texture2D("editor/icons/more_horiz.png") },
{ IconType::Material, Texture::Texture2D("editor/icons/material.png") },
{ IconType::MeshSource, Texture::Texture2D("editor/icons/meshSource.png") },
};
}
else {
Expand All @@ -75,6 +77,8 @@ namespace Atlas::Editor {
{ IconType::Scale, Texture::Texture2D("editor/icons/scale_light.png") },
{ IconType::Rotate, Texture::Texture2D("editor/icons/rotate_light.png") },
{ IconType::MoreHorizontal, Texture::Texture2D("editor/icons/more_horiz_light.png") },
{ IconType::Material, Texture::Texture2D("editor/icons/material_light.png") },
{ IconType::MeshSource, Texture::Texture2D("editor/icons/meshSource_light.png") },
};
}

Expand Down
4 changes: 3 additions & 1 deletion src/editor/Icons.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ namespace Atlas::Editor {
Move,
Scale,
Rotate,
MoreHorizontal
MoreHorizontal,
Material,
MeshSource
};

class Icons {
Expand Down
2 changes: 2 additions & 0 deletions src/editor/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ namespace Atlas::Editor {
{ "scaleSnap", sceneWindow->scaleSnap },
{ "cameraMovementSpeed", sceneWindow->cameraMovementSpeed },
{ "cameraRotationSpeed", sceneWindow->cameraRotationSpeed },
{ "depthTestBoundingVolumes", sceneWindow->depthTestBoundingVolumes },
{ "camera", camera }
};

Expand Down Expand Up @@ -111,6 +112,7 @@ namespace Atlas::Editor {
try_get_json(j, "scaleSnap", sceneWindow->scaleSnap);
try_get_json(j, "cameraMovementSpeed", sceneWindow->cameraMovementSpeed);
try_get_json(j, "cameraRotationSpeed", sceneWindow->cameraRotationSpeed);
try_get_json(j, "depthTestBoundingVolumes", sceneWindow->depthTestBoundingVolumes);
try_get_json(j, "camera", camera);

sceneWindow->cameraEntity = sceneWindow->scene->CreateEntity();
Expand Down
4 changes: 1 addition & 3 deletions src/editor/ui/panels/PopupPanels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ namespace Atlas::Editor::UI {
static int32_t octreeDepth = 5;
static bool invertUVs = true;
static bool addRigidBodies = true;
static bool combineMeshes = false;
static bool makeMeshesStatic = false;

SetupPopupSize(0.6f, 0.3f);
Expand Down Expand Up @@ -121,7 +120,6 @@ namespace Atlas::Editor::UI {
ImGui::Text("Import properties");
ImGui::Checkbox("Invert UVs", &invertUVs);
ImGui::Checkbox("Attach mesh rigid body components", &addRigidBodies);
ImGui::Checkbox("Combine meshes", &combineMeshes);
ImGui::Checkbox("Make meshes static", &makeMeshesStatic);

if (ImGui::Button("Cancel")) {
Expand All @@ -135,7 +133,7 @@ namespace Atlas::Editor::UI {
Singletons::blockingOperation->Block("Importing scene. Please wait...",
[&]() {
auto scene = DataCreator::CreateSceneFromMesh(filename, minSize, maxSize,
octreeDepth, invertUVs, addRigidBodies, combineMeshes, makeMeshesStatic);
octreeDepth, invertUVs, addRigidBodies, makeMeshesStatic);
scene->name = name;

bool alreadyExisted;
Expand Down
4 changes: 3 additions & 1 deletion src/editor/ui/windows/ContentBrowserWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace Atlas::Editor::UI {

ImGui::Separator();

const char *items[] = {"Audio", "Mesh", "Terrain", "Scene", "Script", "Font", "Prefab"};
const char *items[] = {"Audio", "Mesh", "Mesh source", "Material", "Terrain", "Scene", "Script", "Font", "Prefab"};
for (int i = 0; i < IM_ARRAYSIZE(items); i++) {
bool isSelected = selectedFilter == i;
ImGui::Selectable(items[i], &isSelected, ImGuiSelectableFlags_SpanAvailWidth);
Expand Down Expand Up @@ -350,6 +350,8 @@ namespace Atlas::Editor::UI {
switch (contentType) {
case ContentType::Audio: return icons->Get(IconType::Audio);
case ContentType::Mesh: return icons->Get(IconType::Mesh);
case ContentType::MeshSource: return icons->Get(IconType::MeshSource);
case ContentType::Material: return icons->Get(IconType::Material);
case ContentType::Scene: return icons->Get(IconType::Scene);
case ContentType::Font: return icons->Get(IconType::Font);
case ContentType::Prefab: return icons->Get(IconType::Prefab);
Expand Down
5 changes: 5 additions & 0 deletions src/editor/ui/windows/SceneWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ namespace Atlas::Editor::UI {
ImGui::DragFloat("Rotation snap", &rotationSnap, 0.1f, 0.1f, 10.0f);
ImGui::DragFloat("Scale snap", &scaleSnap, 0.01f, 0.1f, 10.0f);

ImGui::Text("Bounding volumes");
ImGui::Checkbox("Test depth", &depthTestBoundingVolumes);

ImGui::EndPopup();
}
}
Expand Down Expand Up @@ -505,6 +508,8 @@ namespace Atlas::Editor::UI {
if (!entity.IsValid())
return;

viewportPanel.primitiveBatchWrapper.primitiveBatch->testDepth = depthTestBoundingVolumes;

if (entity.HasComponent<MeshComponent>()) {
const auto& meshComponent = entity.GetComponent<MeshComponent>();
auto aabb = meshComponent.aabb;
Expand Down
2 changes: 2 additions & 0 deletions src/editor/ui/windows/SceneWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ namespace Atlas::Editor::UI {
int32_t guizmoMode = 7;
bool needGuizmoEnabled = false;

bool depthTestBoundingVolumes = false;

bool hasMainCamera = false;
bool hasPlayer = false;
bool isPlaying = false;
Expand Down
4 changes: 2 additions & 2 deletions src/engine/loader/MeshLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Atlas::Loader {
auto data = Loader::AssetLoader::GetFileContent(fileStream);
// We don't want to keep the file stream open longer than we need
fileStream.close();
j = json::from_bjdata(data);
j = json::from_msgpack(data);
}
else {
std::string serialized((std::istreambuf_iterator<char>(fileStream)),
Expand Down Expand Up @@ -50,7 +50,7 @@ namespace Atlas::Loader {
to_json(j, *mesh);

if (binaryJson) {
auto data = json::to_bjdata(j);
auto data = json::to_msgpack(j);
fileStream.write(reinterpret_cast<const char*>(data.data()), data.size());
}
else {
Expand Down
Loading

0 comments on commit a9e7d08

Please sign in to comment.