Skip to content

Commit e8ad02b

Browse files
committed
-Dev: working on scene XML specification and serialization
1 parent bf494af commit e8ad02b

File tree

17 files changed

+5860
-82
lines changed

17 files changed

+5860
-82
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ add_subdirectory(thirdparty/imgui)
4848
add_subdirectory(thirdparty/stb_image)
4949
add_subdirectory(thirdparty/tiny_obj_loader)
5050
add_subdirectory(thirdparty/tinyply)
51+
add_subdirectory(thirdparty/tinyxml)
5152
add_subdirectory(thirdparty/optick-1.4.0)
5253
add_subdirectory(thirdparty/ImGuiFileDialog)
5354
target_link_libraries(ImGuiFileDialog PUBLIC imgui )
@@ -82,6 +83,7 @@ target_link_libraries(VulkanEngine PUBLIC
8283
imgui
8384
tiny_obj_loader
8485
tinyply
86+
tinyxml
8587
optick
8688
ImGuiFileDialog)
8789

examples/raytracing/application.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ void Application::setup() {
9292
toriiMat->set_albedo_texture(toriiT);
9393

9494
Texture* toriiN = new Texture();
95-
Tools::Loaders::load_texture(toriiN, TEXTURE_PATH + "torii_normal.png", TEXTURE_FORMAT_TYPE_NORMAL);
95+
Tools::Loaders::load_texture(toriiN, TEXTURE_PATH + "torii_normal.png", TEXTURE_FORMAT_UNORM);
9696
toriiMat->set_normal_texture(toriiN);
9797

9898
Texture* toriiM = new Texture();
@@ -116,7 +116,7 @@ void Application::setup() {
116116
Texture* floorText = new Texture();
117117
Tools::Loaders::load_texture(floorText, TEXTURE_PATH + "floor_diffuse.jpg");
118118
Texture* floorNormalText = new Texture();
119-
Tools::Loaders::load_texture(floorNormalText, TEXTURE_PATH + "floor_normal.jpg", TEXTURE_FORMAT_TYPE_NORMAL);
119+
Tools::Loaders::load_texture(floorNormalText, TEXTURE_PATH + "floor_normal.jpg", TEXTURE_FORMAT_UNORM);
120120
Texture* floorRoughText = new Texture();
121121
Tools::Loaders::load_texture(floorRoughText, TEXTURE_PATH + "floor_roughness.jpg");
122122
terrainMat->set_albedo({0.43f, 0.28f, 0.23f});
@@ -139,7 +139,7 @@ void Application::setup() {
139139
Tools::Loaders::load_texture(stonelanternT, TEXTURE_PATH + "moisturizer_color.png");
140140
stoneMat->set_albedo_texture(stonelanternT);
141141
Texture* stonelanternN = new Texture();
142-
Tools::Loaders::load_texture(stonelanternN, TEXTURE_PATH + "moisturizer_normal.png", TEXTURE_FORMAT_TYPE_NORMAL);
142+
Tools::Loaders::load_texture(stonelanternN, TEXTURE_PATH + "moisturizer_normal.png", TEXTURE_FORMAT_UNORM);
143143
stoneMat->set_normal_texture(stonelanternN);
144144
stoneMesh->push_material(stoneMat);
145145
stoneMesh->set_name("Tower");
@@ -160,7 +160,7 @@ void Application::setup() {
160160
Tools::Loaders::load_texture(droidText1, TEXTURE_PATH + "DROID_Body_Emissive.jpg");
161161
droidMat->set_emissive_texture(droidText1);
162162
Texture* droidText2 = new Texture();
163-
Tools::Loaders::load_texture(droidText2, TEXTURE_PATH + "DROID_Body_Normal.jpg", TEXTURE_FORMAT_TYPE_NORMAL);
163+
Tools::Loaders::load_texture(droidText2, TEXTURE_PATH + "DROID_Body_Normal.jpg", TEXTURE_FORMAT_UNORM);
164164
droidMat->set_normal_texture(droidText2);
165165
droidMesh->push_material(droidMat);
166166
droidMesh->set_name("Droid");
@@ -184,11 +184,10 @@ void Application::setup() {
184184
Tools::Loaders::load_texture(stormtrooperText, TEXTURE_PATH + "stormtrooper_color.png");
185185
stormtrooperMat->set_albedo_texture(stormtrooperText);
186186
Texture* stormtrooperText1 = new Texture();
187-
Tools::Loaders::load_texture(
188-
stormtrooperText1, TEXTURE_PATH + "stormtrooper_normal.png", TEXTURE_FORMAT_TYPE_NORMAL);
187+
Tools::Loaders::load_texture(stormtrooperText1, TEXTURE_PATH + "stormtrooper_normal.png", TEXTURE_FORMAT_UNORM);
189188
stormtrooperMat->set_normal_texture(stormtrooperText1);
190189
Texture* stormtrooperText2 = new Texture();
191-
Tools::Loaders::load_texture(stormtrooperText2, TEXTURE_PATH + "stormtrooper_mask.png", TEXTURE_FORMAT_TYPE_NORMAL);
190+
Tools::Loaders::load_texture(stormtrooperText2, TEXTURE_PATH + "stormtrooper_mask.png", TEXTURE_FORMAT_UNORM);
192191
stormtrooperMat->set_mask_texture(stormtrooperText2, MaskType::UNREAL_ENGINE);
193192
stormtrooper->push_material(stormtrooperMat);
194193
stormtrooper->set_name("Trooper");
@@ -203,11 +202,10 @@ void Application::setup() {
203202
stormtrooperMat1->set_albedo_texture(stormtrooperText11);
204203
Texture* stormtrooperText12 = new Texture();
205204
Tools::Loaders::load_texture(
206-
stormtrooperText12, TEXTURE_PATH + "stormtrooper_head_normal.png", TEXTURE_FORMAT_TYPE_NORMAL);
205+
stormtrooperText12, TEXTURE_PATH + "stormtrooper_head_normal.png", TEXTURE_FORMAT_UNORM);
207206
stormtrooperMat1->set_normal_texture(stormtrooperText12);
208207
Texture* stormtrooperText13 = new Texture();
209-
Tools::Loaders::load_texture(
210-
stormtrooperText13, TEXTURE_PATH + "stormtrooper_head_mask.png", TEXTURE_FORMAT_TYPE_NORMAL);
208+
Tools::Loaders::load_texture(stormtrooperText13, TEXTURE_PATH + "stormtrooper_head_mask.png", TEXTURE_FORMAT_UNORM);
211209
stormtrooperMat1->set_mask_texture(stormtrooperText13, MaskType::UNREAL_ENGINE);
212210
stormtrooperHead->push_material(stormtrooperMat1);
213211
stormtrooperHead->set_name("Head");
@@ -233,7 +231,7 @@ void Application::setup() {
233231
spheremat->set_albedo(Vec3(0.0));
234232
spheremat->set_metalness(0.0);
235233
spheremat->set_roughness(0.0);
236-
spheremat->set_emissive_color(Vec3(0.0,0.35,0.8));
234+
spheremat->set_emissive_color(Vec3(0.0, 0.35, 0.8));
237235
spheremat->set_emission_intensity(30.0f);
238236
sphereMesh->set_position({-2.5f, -0.4f, -3.0f});
239237
sphereMesh->set_scale(0.25f);
@@ -243,7 +241,7 @@ void Application::setup() {
243241
energyLight->set_position({-2.5f, -0.4f, -3.0f});
244242
energyLight->set_area_of_effect(20.0f);
245243
energyLight->set_intensity(0.08f);
246-
energyLight->set_color(Vec3(0.0,0.35,0.8));
244+
energyLight->set_color(Vec3(0.0, 0.35, 0.8));
247245
energyLight->set_shadow_type(ShadowType::RAYTRACED_SHADOW);
248246
energyLight->set_area(0.1f);
249247
energyLight->set_shadow_ray_samples(4);
@@ -263,6 +261,9 @@ void Application::setup() {
263261
sky->set_color_intensity(0.25f);
264262
m_scene->set_skybox(sky);
265263

264+
Tools::Loaders::SceneLoader sceneLoader;
265+
sceneLoader.load_scene(m_scene, MESH_PATH + "scene.xml");
266+
266267
m_controller = new Tools::Controller(camera, m_window, ControllerMovementType::ORBITAL);
267268
}
268269

examples/raytracing/main.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
#include <iostream>
21
#include "application.h"
2+
#include <iostream>
33

4-
int main(int argc, char* argv[])
5-
{
4+
int main(int argc, char* argv[]) {
65

76
Application app;
87
try
9-
{
10-
app.run(argc,argv);
11-
}
12-
catch (const std::exception &e)
8+
{ app.run(argc, argv); } catch (const std::exception& e)
139
{
1410
std::cerr << e.what() << std::endl;
1511
return EXIT_FAILURE;

examples/renderer-app/application.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ void Application::setup() {
169169
Texture* toriiT = new Texture();
170170
Tools::Loaders::load_texture(toriiT, TEXTURE_PATH + "torii_color.png");
171171
Texture* toriiN = new Texture();
172-
Tools::Loaders::load_texture(toriiN, TEXTURE_PATH + "torii_normal.png", TEXTURE_FORMAT_TYPE_NORMAL);
172+
Tools::Loaders::load_texture(toriiN, TEXTURE_PATH + "torii_normal.png", TEXTURE_FORMAT_UNORM);
173173
Texture* toriiM = new Texture();
174174
Tools::Loaders::load_texture(toriiM, TEXTURE_PATH + "torii_mask.png");
175175
toriiMat->set_albedo_texture(toriiT);
@@ -193,7 +193,7 @@ void Application::setup() {
193193
Tools::Loaders::load_texture(floorText, TEXTURE_PATH + "floor_diffuse.jpg");
194194

195195
Texture* floorNormalText = new Texture();
196-
Tools::Loaders::load_texture(floorNormalText, TEXTURE_PATH + "floor_normal.jpg", TEXTURE_FORMAT_TYPE_NORMAL);
196+
Tools::Loaders::load_texture(floorNormalText, TEXTURE_PATH + "floor_normal.jpg", TEXTURE_FORMAT_UNORM);
197197
Texture* floorRoughText = new Texture();
198198
Tools::Loaders::load_texture(floorRoughText, TEXTURE_PATH + "floor_roughness.jpg");
199199
auto terrainMat = new PhysicallyBasedMaterial();
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<Scene>
2+
<Resources path="assets/resources/" />
3+
4+
<Camera type="perspective" fov="70">
5+
<Transform>
6+
<scale x="1" y="1" z="1" />
7+
<translate x="0" y="0.919769" z="5.41159" />
8+
<rotate x="0" y="0.893051" z="4.41198" />
9+
</Transform>
10+
</Camera>
11+
12+
<Mesh type="file">
13+
<Filename value="meshes/sphere.obj" />
14+
<Transform>
15+
<scale x="0.5" y="0.5" z="0.5" />
16+
<translate x="0" y="0" z="0" />
17+
<rotate x="0" y="0" z="0" />
18+
</Transform>
19+
20+
<Material type="physical">
21+
<roughness value="0.5" />
22+
<metallic value="0.5" />
23+
<albedo r="0" g="0" b="0" />
24+
<emission r="30" g="30" b="30" />
25+
26+
<!-- Textures for this material -->
27+
<Textures>
28+
<diffuse path="textures/diffuse_map.jpg" />
29+
<normal path="textures/normal_map.jpg" />
30+
<specular path="textures/specular_map.jpg" />
31+
</Textures>
32+
</Material>
33+
</Mesh>
34+
35+
<Light type="point">
36+
<Transform>
37+
<translate x="5.0" y="5.0" z="5.0" />
38+
<scale x="0.5" y="0.5" z="0.5" />
39+
<rotate x="0" y="0" z="0" />
40+
</Transform>
41+
42+
<intensity value="2.0" />
43+
<color r="30" g="30" b="30" />
44+
<influence value="30.0" />
45+
<string name="shadowType" value="raytraced" />
46+
</Light>
47+
48+
<!-- <Skybox filename="textures/sky.hdr">
49+
<rotate x="0" y="0" z="0" />
50+
<intensity value="2.0"/>
51+
</Skybox> -->
52+
53+
</Scene>

include/engine/common.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,10 +400,10 @@ typedef enum AttachmentLoadOpFlagBits
400400
} AttachmentLoadOp;
401401
typedef enum TextureFormatTypeFlagBits
402402
{
403-
TEXTURE_FORMAT_TYPE_COLOR = 0x00000000,
404-
TEXTURE_FORMAT_TYPE_NORMAL = 0x00000001,
405-
TEXTURE_FORMAT_TYPE_DEPTH = 0x00000002,
406-
TEXTURE_FORMAT_TYPE_HDR = 0x00000003
403+
TEXTURE_FORMAT_SRGB = 0x00000000,
404+
TEXTURE_FORMAT_UNORM = 0x00000001,
405+
TEXTURE_FORMAT_DEPTH = 0x00000002,
406+
TEXTURE_FORMAT_HDR = 0x00000003
407407
} TextureFormatType;
408408
typedef enum BindingTypeFlagBits
409409
{

include/engine/core/geometries/geometry.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ class Geometry
102102
void fill_voxel_array(std::vector<Graphics::Voxel> voxels);
103103
static Geometry* create_quad();
104104
static Geometry* create_cube();
105+
static void compute_tangents_gram_smidt(std::vector<Graphics::Vertex>& vertices,
106+
const std::vector<uint32_t>& indices);
105107
};
106108

107109
Graphics::VertexArrays* const get_VAO(Geometry* g);

include/engine/core/materials/hair_strand.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,21 +262,21 @@ class HairStrandMaterial2 : public HairStrandMaterial
262262
m_textures[NGI_TRT] = new Texture(settings);
263263
std::string pigmentTypePath = pigment == BLONDE ? "textures/LUTs/blonde/" : "textures/LUTs/brown/";
264264
Tools::Loaders::load_texture(
265-
m_textures[N1], ENGINE_RESOURCES_PATH + pigmentTypePath + "N_TT_R.png", TEXTURE_FORMAT_TYPE_NORMAL, false);
265+
m_textures[N1], ENGINE_RESOURCES_PATH + pigmentTypePath + "N_TT_R.png", TEXTURE_FORMAT_UNORM, false);
266266
Tools::Loaders::load_texture(
267-
m_textures[N2], ENGINE_RESOURCES_PATH + pigmentTypePath + "N_TRT.png", TEXTURE_FORMAT_TYPE_NORMAL, false);
267+
m_textures[N2], ENGINE_RESOURCES_PATH + pigmentTypePath + "N_TRT.png", TEXTURE_FORMAT_UNORM, false);
268268
Tools::Loaders::load_3D_texture(m_textures[GI], ENGINE_RESOURCES_PATH + pigmentTypePath + "GI.png");
269269
m_textures[GI]->set_format(RGBA_8U);
270270
m_textures[GI]->set_type(TEXTURE_3D);
271271
Tools::Loaders::load_texture(
272-
m_textures[MGI], ENGINE_RESOURCES_PATH + pigmentTypePath + "M_GI.png", TEXTURE_FORMAT_TYPE_NORMAL, false);
272+
m_textures[MGI], ENGINE_RESOURCES_PATH + pigmentTypePath + "M_GI.png", TEXTURE_FORMAT_UNORM, false);
273273
Tools::Loaders::load_texture(m_textures[NGI],
274274
ENGINE_RESOURCES_PATH + pigmentTypePath + "N_TT_R_GI.png",
275-
TEXTURE_FORMAT_TYPE_NORMAL,
275+
TEXTURE_FORMAT_UNORM,
276276
false);
277277
Tools::Loaders::load_texture(m_textures[NGI_TRT],
278278
ENGINE_RESOURCES_PATH + pigmentTypePath + "N_TRT_GI.png",
279-
TEXTURE_FORMAT_TYPE_NORMAL,
279+
TEXTURE_FORMAT_UNORM,
280280
false);
281281
m_textureBindingState[N1] = false;
282282
m_textureBindingState[N2] = false;

include/engine/core/materials/phong.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ class PhongMaterial : public IMaterial
4545
{GLOSSINESS, nullptr},
4646
{AO, nullptr},
4747
{EMISSIVE, nullptr}};
48-
49-
std::unordered_map<int, bool> m_textureBindingState;
48+
49+
std::unordered_map<int, bool> m_textureBindingState;
5050

5151
virtual Graphics::MaterialUniforms get_uniforms() const;
5252
virtual inline std::unordered_map<int, ITexture*> get_textures() const {

include/engine/core/scene/scene.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class Scene : public Object3D
2727
std::vector<Light*> m_lights;
2828
Skybox* m_skybox = nullptr;
2929

30-
bool m_updateAccel = false;
31-
Graphics::TLAS m_accel = {};
30+
bool m_updateAccel = false;
31+
Graphics::TLAS m_accel = {};
3232
// Graphics::TLAS m_dynamicAccel = {};
3333

3434
// ENVIROMENT & FOG
@@ -65,6 +65,8 @@ class Scene : public Object3D
6565
: m_activeCamera(cam) {
6666
add_child(cam);
6767
};
68+
Scene()
69+
: m_activeCamera(nullptr) {};
6870
~Scene() {
6971

7072
delete m_activeCamera;

0 commit comments

Comments
 (0)