This repository contains a basic 3D model viewer implemented in C++ using the Vulkan library.
The provided source codes were tested in Windows 10 using the following libraries:
- Vulkan SDK 1.3.211.0;
- glfw3 3.3.7;
- glm 0.9.9.8;
- rapidjson;
To run the application, you need to pass the config.json
file path as an argument to it (e.g. main.exe config.json
). Also, we suggest you move the shaders
folder to the same folder where the executable is located.
If you want to recompile the shaders, please update the compileShaders.bat
file (Windows) or create a new one following this tutorial.
To compile the source code and build the application for Windows, you may need to:
- Install Visual Studio (>= 2019);
- Install vcpkg:
- Note: By default, vcpkg install x86 libraries. If you use a 64-bit version of Windows, you need to add the following environment variable:
VCPKG_DEFAULT_TRIPLET = x64-windows
before installing the vcpkg libraries;
- Note: By default, vcpkg install x86 libraries. If you use a 64-bit version of Windows, you need to add the following environment variable:
- Install Vulkan SDK;
- Run the following vcpkg commands in the command prompt:
- vcpkg install vulkan-headers;
- vcpkg install glfw3;
- vcpkg install glm;
- vcpkg install rapidjson;
- vcpkg integrate install;
Then, you can create a new, empty Visual Studio project, add the source codes, and you may need to change the following properties of the project:
Configuration Properties -> General -> C++ Language Standard:
toISO C++17 Standard (/std:c++17)
;Configuration Properties -> C/C++ -> General -> Additional Include Directories:
to<VULKAN_MODEL_VIEWER_PATH>\include;%(AdditionalIncludeDirectories)
;Configuration Properties -> Linker -> General -> Additional Library Directories:
to<VULKAN_SDK_PATH>\Lib;%(AdditionalLibraryDirectories)
;Configuration Properties -> Linker -> Input -> Additional Dependencies:
addvulkan-1.lib
,
where:
<VULKAN_MODEL_VIEWER_PATH>
is the path where the repository is stored;<VULKAN_SDK_PATH>
is the path where the Vulkan SDK is installed;
By default, this project comes with the Viking Room model by nigeloh updated by the Vulkan tutorial.
If you want to load your own models in the application, please keep in mind that the current version of the application only supports the loading of a single .obj file (ideally stored in the models
folder), associated with a single texture (ideally stored in the textures
folder), that already has precomputed normals (vn
items).
Then, create a configuration file following the examples available in the configs
folder to setup the scene to be loaded.
This application was successfully tested using the following models:
- Dabrovic Sponza, after exporting a new .obj file with precomputed normals using 3D Viewer;
- Erato;
- Gallery;
- Viking Room;
- Vokselia Spawn;
Tips: If you want to set up the camera properly, you can move the camera around the scene and press C
to capture the camera data and later insert it in the configuration file.
Also, if you want to disable the texture visualization, press 'R'. Conversely, press 'T' to enable the texture visualization.