Note: π§ This repository is a work in progress as GPU Zen 2 gets closer to release, you can follow its progress in the
develop
branch.
When building real-time applications artists must conform to a performance budget according to their projectβs system requirements. Baking allows for the caching of data from geometry with much higher polygon counts to image textures that can be used as inputs in shaders.
This example presents a series of techniques for baking textures to be used in real-time applications. Applications for baking include creating assets with varying levels of detail (LOD), caching lighting effects such as global illumination and diffuse lighting for static assets, and creating atlas maps for objects with multiple materials and UV spaces.
First install Git, then open any terminal such as Hyper in any folder and type:
# π Clone the repo
git clone https://github.com/alaingalvan/gpu-zen-2-baker --recurse-submodules
# πΏ go inside the folder
cd gpu-zen-2-baker
# π― If you forget to `recurse-submodules` you can always run:
git submodule update --init
From there we'll need to set up our build files. Be sure to have the following installed:
-
An IDE such as Visual Studio, XCode, or a compiler such as GCC.
Then type the following in your terminal from the repo folder:
# π· Make a build folder for your IDE files
mkdir build
cd build
# πΌοΈ To build your Visual Studio solution on Windows x64
cmake .. -A x64
# π To build your XCode project on Mac OS
cmake .. -G Xcode
# π§ To build your .make file on Linux
cmake ..
# π¨ (Optional) Build your project:
cmake --build .
This example was written to work on:
-
πΌοΈ Windows (Tested on Windows 10 | 3.0Ghz AMD Ryzen 1700 / NVIDIA 1080 / 32GB Ram)
-
π MacOS (Tested on MacOS 10.13 High Sierra | iMac 2017 / 3.4GHz Intel i5 / Radeon Pro 560 / 16GB Ram)
When the program starts a UI element will appear to the right that shows all the controls for the baker system.
Click Load Low Poly Mesh
to load the low poly mesh you'll be applying textures to. Make sure this mesh has UVs.
Click load High Poly Mesh
to load the high poly mesh you'll be getting your data from.
Click Choose Output Folder
to change the output folder.
You can set the resolution, cage distance, and which maps to bake from the UI.
Click the Bake
button to bake those textures and have them written to <yourpath>/<yourmap>.png
.
-
β¬οΈ Normal
-
βοΈ Object Normal
- π Ambient Occlusion
Action | Input |
---|---|
Rotate Camera | Alt + Left Click |
Pan Camera | Alt + Middle Click |
Zoom Camera | Alt + Right Click |
Move Light | Shift + Left Click |
The file structure for this example is a basic actor-component engine, with a middleware component to the engine to handle shared state that actors can subscribe to (such as the graphics window).
ββ external/
ββ assets/
β ββ shaders/
β β ββ Bake.vert # Shared Vertex Shader across all baker passes
β β ββ BakeNormals.frag # Baker pass for normals / object normals
β β ββ BakeAmbientOcclusion.frag # Baker pass for ambient occlusion
β ββ ...
ββ src/
β ββ Engine/
β β ββ Core/ # Core Engine structures, basic Actor-Component design
β β ββ Actors/ # Actors, where you'll find entities in the scene
β β ββ Middleware/ # The engine's shared state, such as graphic windows and IMGUI
β β ββ Engine.cpp
β β ββ Engine.h
β ββ XMain.cpp # Cross Platform main function
ββ ...
ββ CMakeLists.txt
-
Your platform dependent main function is called, which calls the abstraction main function
void xmain(int argc, const char** argv)
. -
xmain
creates anEngine
tostart()
it. -
The
Engine
creates middleware that holds state that can be managed independently and shared toActor
s. It creates aCoreMiddleware
that manages events, the window, presentation, and keeps the engine running so long as the window hasn't closed. -
When the
CoreMiddleware
is updating, it passes theEngine
'sScene
over to theRenderer
, which performs a preorder traversal of scene hierarchy, updating each actor and rendering it. Afterwords it renders the GUI.
The core logic of the Baker can be found in the Baker
class located in /src/Engine/Actors/
, with its shaders found in /assets/shaders
.
-
CrossWindow - A Cross platform windowing library.
-
CrossWindow-Graphics - Creates and manages OpenGL context.
-
OpenGL-Registry - Header files for all OpenGL APIs.
-
Glad - OpenGL library Loader.
-
VectorMath - Modified version of Sony's open sourced vector and matrix math library.
-
stb - A number of public domain libraries, including a PNG writer / reader that we're using in this example.
-
dear imgui - a bloat-free graphical user interface library for C++.
-
Open Asset Import Library - Loads 40+ 3D file formats into one unified and clean data structure.
This project is licensed as either MIT or Apache-2.0, whichever you would prefer.