Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor global render resource config #145

Merged
merged 2 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ CMakeSettings.json

# Visual Studio Code
.vscode/
*.code-workspace

# CLion
.idea/
Expand Down
3 changes: 2 additions & 1 deletion engine/PilotEditor.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ SchemaFolder=schema
BigIconFile=resource/PilotEditorBigIcon.png
SmallIconFile=resource/PilotEditorSmallIcon.png
FontFile=resource/PilotEditorFont.TTF
DefaultWorld=world/hello.world.json
DefaultWorld=world/hello.world.json
GlobalRenderingRes=global/rendering.global.json
66 changes: 66 additions & 0 deletions engine/asset/global/rendering.global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"skybox_irradiance_map": {
"negative_x_map": "asset/texture/sky/skybox_irradiance_X-.hdr",
"positive_x_map": "asset/texture/sky/skybox_irradiance_X+.hdr",
"negative_y_map": "asset/texture/sky/skybox_irradiance_Y-.hdr",
"positive_y_map": "asset/texture/sky/skybox_irradiance_Y+.hdr",
"negative_z_map": "asset/texture/sky/skybox_irradiance_Z-.hdr",
"positive_z_map": "asset/texture/sky/skybox_irradiance_Z+.hdr"
},
"skybox_specular_map": {
"negative_x_map": "asset/texture/sky/skybox_specular_X-.hdr",
"positive_x_map": "asset/texture/sky/skybox_specular_X+.hdr",
"negative_y_map": "asset/texture/sky/skybox_specular_Y-.hdr",
"positive_y_map": "asset/texture/sky/skybox_specular_Y+.hdr",
"negative_z_map": "asset/texture/sky/skybox_specular_Z-.hdr",
"positive_z_map": "asset/texture/sky/skybox_specular_Z+.hdr"
},
"brdf_map": "asset/texture/global/brdf_schilk.hdr",
"sky_color": {
"r": 0.53,
"g": 0.81,
"b": 0.98
},
"ambient_light": {
"r": 0.03,
"g": 0.03,
"b": 0.03
},
"camera_config": {
"pose": {
"position": {
"x": -5.0,
"y": 0.0,
"z": 3.0
},
"target": {
"x": -4.0,
"y": 0.0,
"z": 3.0
},
"up": {
"x": 0.0,
"y": 0.0,
"z": 1.0
}
},
"z_far": 1000.0,
"z_near": 0.1,
"aspect": {
"x": 1280.0,
"y": 768.0
}
},
"directional_light": {
"direction": {
"x": 0.5,
"y": -0.5,
"z": 0.5
},
"color": {
"r": 1.0,
"g": 1.0,
"b": 1.0
}
}
}
20 changes: 20 additions & 0 deletions engine/source/runtime/core/color/color.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once
#include "runtime/core/meta/reflection/reflection.h"

#include "runtime/core/math/vector3.h"

namespace Pilot
{
REFLECTION_TYPE(Color)
CLASS(Color, Fields)
{
REFLECTION_BODY(Color);

public:
float r;
float g;
float b;

Vector3 toVector3() const { return Vector3(r, g, b); }
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ namespace Pilot
TextureHandle m_irradiance_texture_handle[6];
TextureHandle m_specular_texture_handle[6];

Vector3 m_skyColor;
PAmbientLight m_ambientLight;
PDirectionalLight m_directionalLight;
Vector3 m_sky_color;
PAmbientLight m_ambient_light;
PDirectionalLight m_directional_light;
PPointLightList m_pointLights;

void lock() { m_scene_mutex.lock(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ namespace Pilot
(frustum_bounding_box.max_bound.z - frustum_bounding_box.min_bound.z) * 0.5);

glm::vec3 eye =
box_center + GLMUtil::fromVec3(scene.m_directionalLight.m_direction) * glm::length(box_extents);
box_center + GLMUtil::fromVec3(scene.m_directional_light.m_direction) * glm::length(box_extents);
glm::vec3 center = box_center;
light_view = glm::lookAtRH(eye, center, glm::vec3(0.0, 0.0, 1.0));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void Pilot::PVulkanManager::syncScene(class Scene& scene,
proj_view_matrix = GLMUtil::fromMat4x4(proj_matrix * view_matrix);

// ambient light
Vector3 ambient_light = scene.m_ambientLight.m_irradiance;
Vector3 ambient_light = scene.m_ambient_light.m_irradiance;
uint32_t point_light_num = static_cast<uint32_t>(scene.m_pointLights.m_lights.size());

// set ubo data
Expand Down Expand Up @@ -45,8 +45,8 @@ void Pilot::PVulkanManager::syncScene(class Scene& scene,

// directional light
m_mesh_perframe_storage_buffer_object.scene_directional_light.direction =
scene.m_directionalLight.m_direction.normalisedCopy();
m_mesh_perframe_storage_buffer_object.scene_directional_light.color = scene.m_directionalLight.m_color;
scene.m_directional_light.m_direction.normalisedCopy();
m_mesh_perframe_storage_buffer_object.scene_directional_light.color = scene.m_directional_light.m_color;

m_mesh_inefficient_pick_perframe_storage_buffer_object.proj_view_matrix = proj_view_matrix;
m_mesh_inefficient_pick_perframe_storage_buffer_object.rt_width = m_vulkan_context._swapchain_extent.width;
Expand Down
75 changes: 40 additions & 35 deletions engine/source/runtime/function/scene/scene_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#include "runtime/core/base/macro.h"

#include "runtime/function/render/include/render/framebuffer.h"

#include "runtime/resource/asset_manager/asset_manager.h"
#include "runtime/resource/config_manager/config_manager.h"
#include "runtime/resource/res_type/data/mesh_data.h"

#define STB_IMAGE_IMPLEMENTATION
Expand Down Expand Up @@ -307,7 +309,14 @@ namespace Pilot
return SceneBuffers::createTexture(texture);
}

void SceneManager::initialize() { setSceneOnce(); }
void SceneManager::initialize()
{
GlobalRenderingRes global_rendering_res;

const auto& global_rendering_res_path = ConfigManager::getInstance().getGlobalRenderingResPath();
AssetManager::getInstance().loadAsset(global_rendering_res_path, global_rendering_res);
setSceneOnce(global_rendering_res);
}

int SceneManager::tick(FrameBuffer* buffer)
{
Expand Down Expand Up @@ -777,92 +786,88 @@ namespace Pilot
SceneBuffers::destroy(image_handle);
}
}
void SceneManager::setSceneOnce()
void SceneManager::setSceneOnce(const GlobalRenderingRes& global_res)
{
if (m_scene && m_scene->m_loaded == false)
{
m_scene->m_brdfLUT_texture_handle =
SceneBuilder::loadTextureHDR(AssetManager::getInstance()
.getFullPath("asset/texture/default/brdf_schilk.hdr")
.generic_string()
.c_str());
m_scene->m_brdfLUT_texture_handle = SceneBuilder::loadTextureHDR(
AssetManager::getInstance().getFullPath(global_res.m_brdf_map).generic_string().c_str());
m_scene->m_irradiance_texture_handle[0] =
SceneBuilder::loadTextureHDR(AssetManager::getInstance()
.getFullPath("asset/texture/sky/skybox_irradiance_X+.hdr")
.getFullPath(global_res.m_skybox_irradiance_map.m_positive_x_map)
.generic_string()
.c_str());
m_scene->m_irradiance_texture_handle[1] =
SceneBuilder::loadTextureHDR(AssetManager::getInstance()
.getFullPath("asset/texture/sky/skybox_irradiance_X-.hdr")
.getFullPath(global_res.m_skybox_irradiance_map.m_negative_x_map)
.generic_string()
.c_str());
m_scene->m_irradiance_texture_handle[2] =
SceneBuilder::loadTextureHDR(AssetManager::getInstance()
.getFullPath("asset/texture/sky/skybox_irradiance_Z+.hdr")
.getFullPath(global_res.m_skybox_irradiance_map.m_positive_z_map)
.generic_string()
.c_str());
m_scene->m_irradiance_texture_handle[3] =
SceneBuilder::loadTextureHDR(AssetManager::getInstance()
.getFullPath("asset/texture/sky/skybox_irradiance_Z-.hdr")
.getFullPath(global_res.m_skybox_irradiance_map.m_negative_z_map)
.generic_string()
.c_str());
m_scene->m_irradiance_texture_handle[4] =
SceneBuilder::loadTextureHDR(AssetManager::getInstance()
.getFullPath("asset/texture/sky/skybox_irradiance_Y+.hdr")
.getFullPath(global_res.m_skybox_irradiance_map.m_positive_y_map)
.generic_string()
.c_str());
m_scene->m_irradiance_texture_handle[5] =
SceneBuilder::loadTextureHDR(AssetManager::getInstance()
.getFullPath("asset/texture/sky/skybox_irradiance_Y-.hdr")
.getFullPath(global_res.m_skybox_irradiance_map.m_negative_y_map)
.generic_string()
.c_str());
m_scene->m_specular_texture_handle[0] =
SceneBuilder::loadTextureHDR(AssetManager::getInstance()
.getFullPath("asset/texture/sky/skybox_specular_X+.hdr")
.getFullPath(global_res.m_skybox_specular_map.m_positive_x_map)
.generic_string()
.c_str());
m_scene->m_specular_texture_handle[1] =
SceneBuilder::loadTextureHDR(AssetManager::getInstance()
.getFullPath("asset/texture/sky/skybox_specular_X-.hdr")
.getFullPath(global_res.m_skybox_specular_map.m_negative_x_map)
.generic_string()
.c_str());
m_scene->m_specular_texture_handle[2] =
SceneBuilder::loadTextureHDR(AssetManager::getInstance()
.getFullPath("asset/texture/sky/skybox_specular_Z+.hdr")
.getFullPath(global_res.m_skybox_specular_map.m_positive_z_map)
.generic_string()
.c_str());
m_scene->m_specular_texture_handle[3] =
SceneBuilder::loadTextureHDR(AssetManager::getInstance()
.getFullPath("asset/texture/sky/skybox_specular_Z-.hdr")
.getFullPath(global_res.m_skybox_specular_map.m_negative_z_map)
.generic_string()
.c_str());
m_scene->m_specular_texture_handle[4] =
SceneBuilder::loadTextureHDR(AssetManager::getInstance()
.getFullPath("asset/texture/sky/skybox_specular_Y+.hdr")
.getFullPath(global_res.m_skybox_specular_map.m_positive_y_map)
.generic_string()
.c_str());
m_scene->m_specular_texture_handle[5] =
SceneBuilder::loadTextureHDR(AssetManager::getInstance()
.getFullPath("asset/texture/sky/skybox_specular_Y-.hdr")
.getFullPath(global_res.m_skybox_specular_map.m_negative_y_map)
.generic_string()
.c_str());

m_scene->m_skyColor = {0.53f, 0.81f, 0.98f};
m_scene->m_ambientLight = {{0.03f, 0.03f, 0.03f}};
m_scene->m_camera = std::make_shared<PCamera>();
m_scene->m_camera->lookAt({-5.0f, 0.0f, 3.0f}, {-4.0f, 0.0f, 3.0f}, Vector3(0.0f, 0.0f, 1.0f));
m_scene->m_camera->m_zfar = 1000.0f;
m_scene->m_camera->m_znear = 0.1f;
m_scene->m_camera->setAspect(1280.0f / 768.0f);
/*
m_scene->m_pointLights.m_lights = {// pos, power
{{-3.0f, 5.3f, 2.0f}, {500.0f, 0.0f, 0.0f}},
{{5.0f, 0.3f, 2.0f}, {0.0f, 500.0f, 0.0f}},
{{0.0f, 0.3f, 2.0f}, {0.0f, 0.0f, 500.0f}}};
*/
m_scene->m_directionalLight.m_direction = Vector3(0.5, -0.5, 0.5).normalisedCopy();
m_scene->m_directionalLight.m_color = Vector3(1.0, 1.0, 1.0);
m_scene->m_loaded = true;
m_scene->m_sky_color = global_res.m_sky_color.toVector3();
m_scene->m_ambient_light = {global_res.m_ambient_light.toVector3()};

const CameraPose& camera_pose = global_res.m_camera_config.m_pose;

m_scene->m_camera = std::make_shared<PCamera>();
m_scene->m_camera->lookAt(camera_pose.m_position, camera_pose.m_target, camera_pose.m_up);
m_scene->m_camera->m_zfar = global_res.m_camera_config.m_z_far;
m_scene->m_camera->m_znear = global_res.m_camera_config.m_z_near;
m_scene->m_camera->setAspect(global_res.m_camera_config.m_aspect.x / global_res.m_camera_config.m_aspect.y);

m_scene->m_directional_light.m_direction = global_res.m_directional_light.m_direction.normalisedCopy();
m_scene->m_directional_light.m_color = global_res.m_directional_light.m_color.toVector3();

m_scene->m_loaded = true;
}
}

Expand Down
4 changes: 3 additions & 1 deletion engine/source/runtime/function/scene/scene_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "runtime/core/base/public_singleton.h"
#include "runtime/core/math/math_headers.h"

#include "runtime/resource/res_type/global/global_rendering.h"

#include "runtime/function/render/include/render/framebuffer.h"
#include "runtime/function/scene/scene_allocator.h"
#include "runtime/function/scene/scene_object.h"
Expand Down Expand Up @@ -105,6 +107,6 @@ namespace Pilot
void releaseSkeletonBindingHandles();
void releaseImageHandle(TextureHandle& image_handle);

void setSceneOnce();
void setSceneOnce(const GlobalRenderingRes& global_res);
};
} // namespace Pilot
1 change: 0 additions & 1 deletion engine/source/runtime/function/scene/scene_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ namespace Pilot
size_t m_go_id;
std::vector<GameObjectComponentDesc> m_components;
};

} // namespace Pilot

template<>
Expand Down
23 changes: 16 additions & 7 deletions engine/source/runtime/resource/config_manager/config_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,34 @@ namespace Pilot
{
std::string name = config_line.substr(0, seperate_pos);
std::string value = config_line.substr(seperate_pos + 1, config_line.length() - seperate_pos - 1);
if (name.compare("AssetFolder") == 0)
if (name == "AssetFolder")
{
m_asset_folder = m_root_folder / value;
}
else if (name.compare("SchemaFolder") == 0)
else if (name == "SchemaFolder")
{
m_schema_folder = m_root_folder / value;
}
else if (name.compare("DefaultWorld") == 0)
else if (name == "DefaultWorld")
{
m_default_world_path = value;
m_default_world_path = m_asset_folder / value;
}
else if (name.compare("BigIconFile") == 0)
else if (name == "BigIconFile")
{
m_editor_big_icon_path = m_root_folder / value;
}
else if (name.compare("SmallIconFile") == 0)
else if (name == "SmallIconFile")
{
m_editor_small_icon_path = m_root_folder / value;
}
else if (name.compare("FontFile") == 0)
else if (name == "FontFile")
{
m_editor_font_path = m_root_folder / value;
}
else if (name == "GlobalRenderingRes")
{
m_global_rendering_res_path = m_asset_folder / value;
}
}
}
}
Expand All @@ -67,4 +71,9 @@ namespace Pilot
const std::filesystem::path& ConfigManager::getEditorSmallIconPath() const { return m_editor_small_icon_path; }

const std::filesystem::path& ConfigManager::getEditorFontPath() const { return m_editor_font_path; }

const std::filesystem::path& ConfigManager::getGlobalRenderingResPath() const
{
return m_global_rendering_res_path;
}
} // namespace Pilot
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace Pilot
std::filesystem::path m_editor_big_icon_path;
std::filesystem::path m_editor_small_icon_path;
std::filesystem::path m_editor_font_path;
std::filesystem::path m_global_rendering_res_path;

public:
void initialize(const EngineInitParams& init_param);
Expand All @@ -37,5 +38,6 @@ namespace Pilot
const std::filesystem::path& getEditorBigIconPath() const;
const std::filesystem::path& getEditorSmallIconPath() const;
const std::filesystem::path& getEditorFontPath() const;
const std::filesystem::path& getGlobalRenderingResPath() const;
};
} // namespace Pilot
Loading