How wchen777/copied-city works
The project is a realtime procedural city generator built using OpenGL. Its primary goal is to replicate the visual style of Nier Automata’s Copied City, featuring effects such as Screen Space Ambient Occlusion (SSAO), shadow mapping, texture and skybox mapping, and fog. The system uses external libraries (GLEW for OpenGL extension handling and GLM for mathematical computations) and organizes its own source code into several logical domains (camera, city generation, rendering, utilities, and mesh definitions).
Main Components
• Core Application & Main Loop: Represent the entry point (src/main.cpp) and main window (src/mainwindow.cpp/h) that initialize the application, set up the rendering loop, and manage overall state.
• Camera System: Include the modules under “src/camera” (camera.cpp, transforms.cpp) that handle view and projection matrices, user input, and scene navigation.
• City Renderer: Illustrate the components in “src/cityrenderer” for handling the visual aspects of the procedural city. This module deals with rendering shadows, sky, SSAO, and texture mapping (renderssao.cpp, rendershadow.cpp, rendersky.cpp, blocktexture.cpp).
• Mesh and Geometry: Outline the “src/trimeshes” module that represents basic geometric primitives and OBJ mesh loading (cube, obj_mesh implementations).
Relationships and Interactions
• The Main Application initializes the Camera, City Generator, and Rendering Engine.
• The City Generator produces procedural layout data and geometry (possibly in the form of mesh data) that is passed to the Renderer via the City Renderer module.
• The Camera system provides the view and projection matrices to the rendering pipeline.
• The renderer uses shader programs (loaded from “resources/shaders”) and textures (from “resources/textures”) to render the scene with multimedia effects such as SSAO, shadow mapping, and skybox rendering.
• Utility modules support scene parsing and asset management, feeding data into the core rendering process.
• External libraries (GLEW and GLM) are foundational and are part of the build as referenced by CMake (CMakeLists.txt and build scripts).
Architectural Patterns and Design Principles
• Layered/MVC-like Separation: Distinct separation between data generation (City Generator), business logic (Renderer Engine), and presentation (City Renderer, UI from mainwindow).
• Module isolation: Each subdirectory within “src” targets a discrete concern (e.g., camera handling, procedural generation, meshes, utilities), making it easier to manage dependencies.
• Use of External Libraries: Clearly mark GLEW and GLM as support libraries that the entire rendering stack depends on, indicating their integration in the build process.
Technologies and Frameworks
• OpenGL: Core rendering API.
• GLEW: For handling OpenGL extensions.
• GLM: For mathematical computations specific to graphics.
• CMake/Ninja: For build management based on the CMakeLists.txt and build.ninja files.
• Procedural Generation Algorithms: Represented in the City Generator module.