Navigating huge UE 4 rendering code UMBC Graphics
Navigating huge (UE 4 (rendering)) code UMBC Graphics for Games
UE 4 is BIG • For the 4. 20. 2 -release tag in github • C++ (*. h, *. cpp) • 51, 074 files • 14, 494, 615 lines of C++ code • C# (*. cs) • 1813 files • 496, 550 lines of C# code • Shaders (*. ush, *. usf) • 332 files • 86, 359 lines of HLSL code
Navigating large software • Mostly not really just about UE 4 or just about rendering • At some point, you will need to make changes to a large pre-existing software base • Tools and strategies are the same
Tools of the trade • Paper or text editor for notes • IDE • Know how to bookmark / set breakpoints • Know how to step through & examine code • For UE 4, VS extensions in Engine/Extras • File search • VS Find in Files / Xcode search • VS Visual Assist extension (VAX) • External search tool like ripgrep
Types of knowledge • Big picture • Basic idea of what it is doing • Don’t sweat the details • Local view • How does one thing work • Usually to make changes there or create something similar • Find & understand the local code • Understand who calls it, and with what assumptions • Understand what it calls, and what they do (but not necessarily how)
Big picture: Know what to expect • What algorithms do you expect to see? • What data, inputs and outputs? • For rendering, this class
Example • Two common rendering strategies • Forward shading • Deferred shading • UE 4 supports both
Forward shading • Compute per-pixel shading while rendering objects • Redundant shading computation for pixels that are overwritten • More per-object control over shading • Supports transparency for sorted objects • Usually limits on type and number of lights
Deferred shading • When rendering objects, just save shading parameters per-pixel • In later passes, apply shading and lighting computations per pixel • Culling lights by coverage allows tons of lights • Base shading code needs to be similar for all objects • Rise of Physically Based Shading in games • Transparent objects in a separate forward pass
Big picture: Look for documentation • Rendering overview • docs. unrealengine. com/latest/INT/Programming/Rendering/Overview • Some independent blog posts • interplayoflight. wordpress. com/2017/10/25/how-unreal-renders-a-frame • medium. com/@lordned • Ask someone who knows
Big picture: See what it does • PC: Render. Doc • Install Render. Doc • Enable plugin • Restart UE 4 • UE 4: r. Composition. Graph. Debug • Shows all passes • Use vis console command to see pass outputs
Big picture: Step through the code • Constrain to the level you care about • Optimizers make life hard • Reorder code, eliminate variables, limit variable lifetime, … • Turn off optimization in just one file • VS: #pragma optimize( "", off ) • Xcode: #pragma clang optimize off • DON’T CHECK THIS IN!!! • Breakpoint & step • FDeferred. Shading. Scene. Renderer: : Render • FPost. Processing: : Process
Details: Where to start • Find a starting point in the code • Build your understanding out from there • Keep the window small • You’re changing a black box in a chain of black boxes • Just be sure to honor the interfaces and assumptions
Details: Finding code • Find in files • VS: Solution search box, Ctrl-Shift-F, Ctrl-T • Xcode: Magnifying glass, search bar • Limit by path, file type, previous search results • Try a few different words • • Looking for a page or two of results. Too many isn’t useful. If you know a log string or cvar name, start with that. For blueprint or material node, look for node name Given several choices, look for the more unique one
Details: Understanding code you find • Read the code • Add breakpoints • Look at the call stack on break • Step through • May help to add ONETHREAD command line argument • For shader compiler, b. Allow. Compiling. Through. Workers=False
Details: Finding something similar • How to make a material node • Find a uniquely named one, similar to what you want • Copy & rename everything it does • Modify to new purpose • How to make a blueprint node • Find a uniquely named one , similar to what you want • Copy & rename everything it does • Modify to new purpose • How to make a new postprocessing pass • Find a uniquely named one , similar to what you want • Copy & rename everything it does • Modify to new purpose
- Slides: 16