Skip to content

πŸ₯§ An OpenGL 4.x example of GPU Zen 2's ray casting techniques for baked texture generation chapter.

License

Notifications You must be signed in to change notification settings

alaingalvan/GPU-Zen-2-Baker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

GPU Zen 2 | Ray Casting Techniques for Baked Texture Generation

GPU Zen 2 cmake-img License Travis Tests

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.

Getting Started

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:

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)

Usage

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.

Supported Maps

Surface

  • ⬆️ Normal

  • β†˜οΈ Object Normal

Lights

  • πŸŒ’ Ambient Occlusion

Navigation

Action Input
Rotate Camera Alt + Left Click
Pan Camera Alt + Middle Click
Zoom Camera Alt + Right Click
Move Light Shift + Left Click

Architecture

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

Execution Order

  1. Your platform dependent main function is called, which calls the abstraction main function void xmain(int argc, const char** argv).

  2. xmain creates an Engine to start() it.

  3. The Engine creates middleware that holds state that can be managed independently and shared to Actors. It creates a CoreMiddleware that manages events, the window, presentation, and keeps the engine running so long as the window hasn't closed.

  4. When the CoreMiddleware is updating, it passes the Engine's Scene over to the Renderer, 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.

Dependencies

  • 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.

License

This project is licensed as either MIT or Apache-2.0, whichever you would prefer.

About

πŸ₯§ An OpenGL 4.x example of GPU Zen 2's ray casting techniques for baked texture generation chapter.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published