Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
Z

ZXEngine

> 数据库
Open source

C++ game engine project, for learning, practice and experiment.

657 stars0 likes6 views
WebsiteGitHub

About

C++ game engine project, for learning, practice and experiment.

ZXEngine

Graphics API Platform

这是我自己开发的游戏引擎项目,创建这个项目的主要目的是为了我自己学习和实践游戏引擎技术,不过也希望这个项目能对你有所帮助。

This is a game engine project. The main purpose that I created this project is to learn and practice game engine technology. And I hope this project will be helpful to you.

本项目以游戏引擎为目标,而并非只关注图形渲染(不过图形渲染也是一个重要模块)。引擎基本外观如下图,具体内容请看图示后面的目录。

This project aimed at the game engine, not only focus on the graphics and rendering (although this is also an important contents). The appearance of the engine is shown in the figure below. For specific content, please see the table of contents below the figure.

目录(Contents)

  • 引擎简介 (Engine Introduction)

  • 引擎编辑器和更多演示 (Engine Editor And More Demonstration)

  • 多套内置渲染管线 (Multiple Built-in Rendering Pipelines)

  • 通用计算管线支持 (Compute Pipeline Support)

  • PhysZ物理引擎简介 (PhysZ Physics Engine Introduction)

  • ZXShader和材质系统 (ZXShader And Material System)

  • 骨骼蒙皮动画系统 (Skeletal Animation System)

  • 粒子系统 (Particle System)

  • 游戏UI系统 (Game UI System)

  • GamePlay层的Lua系统 (Lua System of GamePlay Layer)

  • 音频系统 (Audio System)

  • 多线程与JobSystem (Multithreading And JobSystem)

  • C++反射与序列化 (C++ Reflection And Serialization)

  • 引擎文件格式介绍 (Engine File Format Introduction)

  • 实际游戏项目演示 (Actual Game Project Demonstration)

  • 构建与跨平台 (Build And Cross-Platform)

  • 注意事项 (Notices)

引擎简介 (Engine Introduction)

Platform Graphics API Support Build Solution Support
Windows DirectX 12, Vulkan, OpenGL Visual Studio, xmake, CMake
macOS Metal, Vulkan, OpenGL xmake, CMake
Linux OpenGL, Vulkan(unverified) xmake, CMake
Android Vulkan Android Studio
iOS Metal Xcode

本引擎目前同时支持Vulkan,DirectX 12,Metal和OpenGL,支持Windows,macOS,Linux,Android和iOS。使用自创的zxshader语言来编写shader,支持前面4种图形API,编写一次即可在4种图形API和5种平台运行。本引擎同时也支持基于Vulkan和DirectX12的光线追踪渲染管线。

This engine currently supports Vulkan, DirectX 12, Metal and OpenGL, supports Windows, macOS, Linux, Android and iOS. The engine uses the self-created zxshader language to write shaders. You only need to write zxshader once and it can work in all four graphics APIs and five platforms. This engine also supports ray tracing rendering pipeline based on Vulkan or DirectX12.

本引擎内置了我写的物理引擎PhysZ(看了一些书和别人的项目之后的学习成果,详见后文),支持基本的刚体力学模拟和弹簧,布料模拟。同时我也开发了简单的骨骼蒙皮动画系统,材质系统,粒子系统,UI系统,JobSystem等。

This engine has a built-in physics engine written by myself, which I called it PhysZ (It is the learning result after reading some books and other people’s projects), supports rigid body mechanics simulation spring simulation and cloth simulation. And I also developed a simple skeletal animation system, material system, particle system, UI system, JobSystem, etc.

引擎本身用C++开发,GamePlay层使用Lua语言,引擎层封装部分C++接口给GamePlay层的Lua调用。使用方式类似Unity的XLua,通过一个GameLogic组件把Lua代码绑定到GameObject上,接收来自引擎的Start和Update调用,并通过self访问所挂载的GameObject对象(具体示例看后面)。

The engine itself is developed in C++, the GamePlay layer uses Lua language, and the engine provides part of the C++ interface to Lua for the GamePlay layer. This is similar to Unity's XLua, you can bind the Lua code to the GameObject through a GameLogic component, receive Start and Update calls from the engine, and access the binding GameObject object through "self" (see later for specific examples).

引擎场景中的对象都是Unity式的 GameObject - Component 结构,也有一个类似Unity的引擎编辑器页面。不过编辑功能还不完善,只有一部分 Component 能够被编辑,其它的主要是展示当前的运行时状态。

The objects in the scene of this engine are all Unity-style GameObject - Component structures, and there is also a Unity-like engine editor. However, the editing function is not complete yet, only some Components can be edited, and the others just display the current runtime status.

引擎编辑器和更多演示 (Engine Editor And More Demonstration)

引擎顶部为主菜单栏,中间是Game和Scene视图,左边是展示场景中GameObject的Hierarchy面板,下面是显示当前项目Assets目录的Project面板和显示日志的Console面板,右边是显示当前选中对象详细信息的Inspector面板。

The top of the engine is the main menu bar, the middle is the Game and Scene views, on the left is the Hierarchy panel that displays the GameObjects in the scene, below is the Project panel that displays the assets of the current project and the Console panel that displays the log, and on the right is the Inspector panel that displays detailed information of the currently selected object.

切换到Scene视图后可以直接在场景中对选中的GameObject进行操作:

Switch to the Scene view can manipulate the selected GameObject in the scene:

点击材质文件后Inspector面板的材质信息和材质预览:

Click the material file, material information and preview on the Inspector panel:

双击场景文件可切换场景,光追管线也可以直接切换。图为点击模型文件后Inspector面板的模型信息和模型预览:

Double-clicking a scene file can switch scenes, and the ray tracing pipeline can also be switched directly. The picture shows the model information and model preview in the Inspector panel after clicking a model file:

点击图片文件后,Inspector面板的图像信息:

Click the image file, the image information in the Inspector panel:

点击zxshader和Lua后Inspector上的代码预览:

Click zxshader and Lua to preview the code in the Inspector:

多套内置渲染管线 (Multiple Built-in Rendering Pipelines)

本引擎有3套内置渲染管线,分别是正向渲染管线,延迟渲染管线和光线追踪渲染管线。

ZXEngine has three built-in rendering pipelines, which are forward rendering pipeline, deferred rendering pipeline and ray tracing rendering pipeline.

引擎的场景文件中保存了渲染管线信息,在切换场景的时候引擎会直接无缝切换渲染管线。所以想运行哪套渲染管线,直接在引擎编辑器中双击对应的场景文件切换即可。

The rendering pipeline information is saved in the scene file, and the engine seamlessly switches the rendering pipeline when switching scenes. So if you want to run which rendering pipeline, just double-click the corresponding scene file in the engine editor to switch.

使用正向渲染管线和光追渲染管线的场景已经在前面演示过了,这里再补充一个延迟渲染管线的演示场景:

Scenes using forward rendering pipeline and ray tracing rendering pipeline have been demonstrated previously. Here is a demonstration scene of deferred rendering pipeline:

通用计算管线支持 (Compute Pipeline Support)

ZXEngine集成了Vulkan,DirectX 12,Metal和OpenGL的通用计算管线,并封装成了统一接口以供使用。由于macOS只支持到OpenGL 4.1,而OpenGL是从4.3版本才加入对计算管线的支持,所以在macOS上使用OpenGL时,所有计算管线相关的模块都会被禁用。除macOS+OpenGL的组合无法使用计算管线外,其它平台+图形API的组合都是可用的。

ZXEngine integrates the compute pipeline of Vulkan, DirectX 12, Metal and OpenGL and is encapsulated into a unified interface for use. Since macOS only supports OpenGL 4.1, and OpenGL added support for the compute pipeline from version 4.3, all compute pipeline related modules are disabled when using OpenGL on macOS. Except for the macOS + OpenGL combination that does not support compute pipeline, other platform + graphics API combinations are support.

目前项目中实际应用了计算管线的地方在骨骼蒙皮动画模块和D3D12的Mipmap生成。在启用了ZX_COMPUTE_ANIMATION宏之后,骨骼蒙皮动画的Mesh更新操作将在计算管线中完成。

Currently, the actual application of compute pipeline in the project is in the skeletal animation system and the mipmap generation of D3D12. When the ZX_COMPUTE_ANIMATION macro is enabled, the update of skinned mesh will be done in the compute pipeline.

PhysZ物理引擎简介 (PhysZ Physics Engine Introduction)

先展示一下PhysZ引擎对刚体力学和布料的模拟效果(GIF演示,截屏大小和帧率都有压缩):

Here is a GIF of the simulation of rigid mechanics and cloth in PhysZ (the size and framerate of the screenshots are compressed):

使用基本的PhysZ物理引擎只需要关心两个Component:Collider和Rigidbody。其中Collider目前提供了三种类型:BoxCollider,PlaneCollider和SphereCollider。下面是这两个Component在引擎里编辑器里的截图:

Using the PhysZ engine involves only two Components: Collider and Rigidbody. Collider currently provides three types: BoxCollider, PlaneCollider and SphereCollider. The following are screenshots of these two Components in the editor in the engine:

各参数作用顾名思义即可。其中Damping参数是模拟各种形式的阻尼效果的,Linear Damping和Angular Damping分别对应线性运动和角运动,数值为0代表无阻尼。

The function of each parameter is just as the name implies. And the Damping parameter is used to simulate various forms of damping effects. Linear Damping and Angular Damping correspond to linear motion and angular motion respectively. A value of 0 represents no damping.

弹簧组件如图,类似Unity的SpringJoint,参数分别是连接对象,自己和连接对象的锚点(各自的模型空间),弹簧的松弛长度和弹簧系数。

The spring component is shown in the figure, similar to Unity's SpringJoint. The parameters are the connection object, the anchor points of itself and the connection object (their respective model spaces), the rest length and spring coefficient of the spring.

布料模拟需要添加一个Cloth组件,参数分别是布料质量,摩擦系数,弯曲刚度,拉伸刚度和是否使用重力。注意布料需要配合动态Mesh,本引擎暂时只支持DynamicPlane。

Cloth simulation needs to add a Cloth component, the parameters are cloth mass, friction coefficient, bend stiffness, stretch stiffness and whether to use gravity. Note that cloth needs to be matched with dynamic mesh. This engine currently only supports DynamicPlane.

PhysZ引擎主要是我在学习了Ian Millington的《Game Physics Engine Development》和Gabor Szauer的《Game Physics Cookbook》之后,加上一些自己的思考和实践的成果。引擎里的注释也比较多,欢迎对物理引擎感兴趣的人一起讨论学习。

The PhysZ engine is the result of me studying Ian Millington's "Game Physics Engine Development" and Gabor Szauer's "Game Physics Cookbook", plus some of my own thinking and practice. If you are also interested in physics engines, I hope this engine can be helpful to you.

ZXShader和材质系统 (ZXShader And Material System)

ZXShader是专门给ZXEngine用的一套Shader系统,因为ZXEngine同时支持Vulkan/DirectX12/Metal/OpenGL,所以也需要一个统一的Shader语言才能支撑后面的材质系统。ZXShader目前暂时只支持光栅渲染管线,光追渲染管线的Shader是在VK和DX下独立写的。ZXShader语言本身并不复杂,对GLSL,HLSL或者Unity ShaderLab比较熟悉的人应该都能很快看懂,代码示例在ExampleProject\Assets\Shaders中。

ZXShader is a shader system for ZXEngine. Because ZXEngine supports Vulkan/DirectX12/Metal/OpenGL, a unified shader language is needed to support the material system. ZXShader currently only supports the rasterization rendering pipeline. The Shader of the raytracing rendering pipeline is written independently under VK and DX. The ZXShader language itself is not complicated. People who are familiar with GLSL, HLSL or Unity ShaderLab should be able to understand it quickly. The code examples are in ExampleProject\Assets\Shaders.

材质系统和Unity的比较类似,就是挂一个Shader,然后可以在编辑器面板上看到这个材质暴露给引擎的参数。并且可以通过引擎编辑器调整参数数值,然后实时看到渲染结果的动态反馈。如图,直接调整正在运行的场景中的材质:

The material system is similar to Unity. Select a render object, and then you can see the parameters exposed by the material to the engine editor. And you can adjust parameter values through the engine editor, and then see the feedback of the rendering results in real time. For example, adjust the materials in the running scene:

选中Asset中的材质文件后,直接调整材质参数,在材质球上预览变化:

This is after selecting the material file in the Asset, adjusting the material parameters, and previewing the changes on the material ball:

骨骼蒙皮动画系统 (Skeletal Animation System)

切换到AnimDemo场景,点击运行按钮后,可以看到骨骼蒙皮动画的展示:

Switch to the AnimDemo scene and click Play button to see the skeletal animation demonstration:

本引擎的动画系统支持动画混合,所以这里除了能看到单个动画播放外,还能看到人物从走路状态进入跑步状态时,两个动画之间流畅的过渡。

The animation system supports animation blending, so in addition to the individual animation play, you can also see the smooth transition between the two animations when the character enters the running state from the walking state.

此外,动画系统还支持通过计算管线来更新Mesh数据,同时也兼容传统的顶点着色器更新方式。启用ZX_COMPUTE_ANIMATION宏定义后,带有动画的Mesh数据更新将在计算管线中完成。未启用ZX_COMPUTE_ANIMATION时,蒙皮动画将在顶点着色器中计算。

The animation system also supports update skinned mesh through compute pipeline, and is compatible with traditional vertex shader updating methods.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C++cppcpp20cross-platformdirectx

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库