MxEngine

MxEngine

开源教育型3D游戏引擎 支持实时渲染与物理模拟

MxEngine是一款基于现代C++的开源3D游戏引擎,专为教育目的设计。引擎支持OpenGL图形API,提供延迟物理渲染、屏幕空间反射等先进渲染特性,以及刚体动力学、3D音频、实体组件系统等功能。它支持运行时C++编译和GLSL着色器编辑,方便快速原型开发。MxEngine适合学习3D图形编程和游戏开发的开发者使用,是一个理想的教学和学习平台。

MxEngine游戏引擎C++OpenGL3D渲染Github开源项目

MxEngine

Appveyor Build status GitHub Trello discord

<!-- soon! [![Documentation](https://codedocs.xyz/MomoDeve/MxEngine.svg)](https://codedocs.xyz/MomoDeve/MxEngine/) -->

MxEngine is an educational modern-C++ general-purpose 3D game engine. Right now MxEngine is developed only by me, #Momo, but any contributions are welcome and will be reviewed. Fow now MxEngine supports OpenGL as graphic API and targets x64 only. I develop the project in my free time, so updates may be not so frequent!

Note: MxEngine is currently being ported to new Vulkan rendering backend. Development progress of the rendering library can be found here: VulkanAbstractionLayer

<p align="center"> <img src="preview_images/readme_main.png"> </p>

Versions & Releases

MxEngine releases come with versions in format X.Y.Z where X stands for major release, Y for minor release and Z for bug fixes or non-significant changes.

Major releases are prone to breakage of already existing API and functional but bring a lot new features to the engine. Usually it is possible to rewrite all code using new API and retain former behaviour.

Minor releases may change API or add new features but usually user code can be easily adapted to them. With this releases also come some new MxEngine user libraries (for example new bindings or non-required components)

Bug fixes & improvements are just fixes to already existing code to reestablish initially planned behaviour. This fixes may also be merged into major or minor releases if they come in the same time.

For full version list see versions.md file

Installing and running MxEngine

As a developer (if you want to contribute or check samples)

Right now MxEngine is distributed in source code with configurable CMake files. Here are the steps you need to do to compile and run MxEngine sample projects:

  1. clone this repo to your system using git clone --recurse-submodules https://github.com/asc-community/MxEngine
  2. build project by running CMakeLists.txt located in root directory (set up the environment if needed)
  3. select one of executables from samples folder and run it to check if everything was built successfully
  4. to create your own project, consider taking ProjectTemplate sample as starting point, it has everything already configured for build

As a user (if you want to develop your own application)

To develop your own applications using MxEngine you can use template project with already setup dependencies: MxEngineTemplate (make sure it contains up-to-date version of the engine)

Feature list

<details> <summary><b>Rendering features</b></summary>
- Deferred Physically Based Rendering (Cook-Torrance GGX)
- Screen Space Reflection, Screen Space Ambient Occlusion, Screen Space Global Illumination
- Cascade shadow maps, omnidirectional shadow maps, spot projection maps
- directional, point and spot dynamic lights
- Adaptive tone mapping, FXAA, fog, bloom effect, god rays, depth of field
- Particle System based on compute shaders
- 2D debug utilities: light, sound, object bounds, lines, rectangles and etc.
</details> <details> <summary><b>Physics features</b></summary>
- Rigid body dynamics: static, dynamic and kinematic bodies
- Collision detection with triggers and callbacks
- Raycasting with object type filtering
</details> <details> <summary><b>Audio features</b></summary>
- 3D sounds with distance attenuation
- Support of popular audio formats: .mp3, .ogg, .wav, .flac
</details> <details> <summary><b>Programmable API</b></summary>
- Entity Component System (20+ different components)
- Safe to use handle system (RAII or by managable object pools)
- 50+ supported objects formats via Assimp library (with automatic normal & tangent generation)
- Event system with ability to add your own event types
- Logging, image & cubemap loading, json reading, UUID, random generators and more
</details> <details> <summary><b>Scripting & runtime editing</b></summary>
- Runtime C++ code compilation via dynamically load libraries
- Runtime GLSL shader editing (both engines and your own)
- ImGui editor with multiple draggable windows (docking)
- Load/save file dialog, texture viewer, mesh, material & component editors
- One-click scene loading/saving, generic serializer for all components and resources
</details>

Code snippets

Primitive creation

You can easily create spheres, planes, cylinders and etc. Custom number of vertecies for displacement maps are supported out of box

auto cube = MxObject::Create(); cube->AddComponent<MeshSource>(Primitives::CreateCube()); cube->AddComponent<MeshRenderer>();

Loading object from file

MxEngine is using Assimp library which can load any popular object format. To load materials simply pass same path to object file

auto object = MxObject::Create(); object->AddComponent<MeshSource>(AssetManager::LoadMesh("objects/your_object.obj")); object->AddComponent<MeshRenderer>(AssetManager::LoadMaterials("objects/your_object.obj"));

Creating lights

Dynamic directional lights, spot lights and point lights are supported. Each has a similar interface and is created in a uniform way

auto object = MxObject::Create(); auto light = object->AddComponent<SpotLight>(); light->SetColor(Vector3(1.0f, 0.7f, 0.0f)); light->SetIntensity(100.0f); light->SetAmbientIntensity(0.3f); light->SetOuterAngle(45.0f);

Using scripts for runtime code compilation

by creating a seperate file with special macro definition you are able to add scripts to objects and then edit them in runtime - the scripts will be recompiled automatically:

#include <MxEngine.h> using namespace MxEngine class YourScript : public Scriptable { public: virtual void OnCreate(MxObject& self) override { } virtual void OnReload(MxObject& self) override { } virtual void OnUpdate(MxObject& self) override { } }; MXENGINE_RUNTIME_EDITOR(YourScript);
// you can add it as a component by name: auto object = MxObject::Create(); object->AddComponent<Script>("YourScript");

Creating multiple objects using GPU instancing

you can create MxObjects which share same mesh and material. They all can have different position and color, but still rendered in one draw call

auto factory = MxObject::GetByName("ObjectFactory"); auto instance1 = Instanciate(factory); instance1->Transform.SetPosition({0.0f, 1.0f, 0.0f}); auto instance2 = Instanciate(factory); instance2->Transform.SetPosition({0.0f, 2.0f, 0.0f}); auto instance3 = Instanciate(factory); instance3->Transform.SetPosition({0.0f, 3.0f, 0.0f});

Playing audio files

To play audio files in 3D world, attach listener to player object and create object with audio source component. mp3, wav, flac and ogg file formats are supported

auto player = MxObject::Create(); auto listener = player->AddComponent<AudioListener>(); auto object = MxObject::Create(); object->Transform.SetPosition({1.0f, 0.0f, 1.0f}); auto audio = object->AddComponent<AudioSource>(AssetManager::LoadAudio("sounds/music.mp3")); audio->Play();

Controlling particle systems

The engine supports particle systems which are computed on GPU (up to million particles at 60FPS)

auto object = MxObject::Create(); auto particles = object->AddComponent<ParticleSystem>(); particles->SetMaxParticleCount(5000); particles->SetParticleSpeed(10.0f); particles->SetShape(ParticleSystem::Shape::HEMISPHERE);

Managing multiple cameras

You can create cameras and render scene from different angles. The results can be used for post-effects or dynamic textures

auto object = MxObject::Create(); auto camera = object->AddComponent<CameraController>(); camera->SetDirection(Vector3(1.0f, 0.0f, 0.0f));

Creating physical objects

MxEngine supports realtime physics simulation. Just add RigidBody component and attach suitable collider

auto sphere = MxObject::Create(); sphere->AddComponent<MeshSource>(Primitives::CreateSphere()); sphere->AddComponent<MeshRenderer>(); sphere->AddComponent<SphereCollider>(); auto rigidBody = sphere->AddComponent<RigidBody>(); rigidBody->SetMass(1.0f); rigidBody->SetLinearVelocity({0.0f, 10.0f, 0.0f});

Raycasting on your game scene

All physical objects with colliders can be raycasted and accessed using simple api

auto raySource = Vector3(0.0f); auto rayDirection = Vector3(1.0f, 0.0f, 0.0f); auto rayLength = 100.0f; auto rayDistance = raySource + rayDirection * rayLength; float rayFraction = 0.0f; auto object = Physics::RayCast(raySource, rayDistance, rayFraction); if(object.IsValid()) { MXLOG_INFO("raycast", "found object: " + object->Name); MXLOG_INFO("raycast", "distance to object: " + ToMxString(rayLength * rayFraction)); }

Setting up timers and events

You can sign up for event or create timer with specific call interval in one line of code

Timer::CallEachDelta([]() { MXLOG_INFO("MyTimer", "I am called every 500ms!"); }, 0.5f); Event::AddEventListener("MyEvent", [](UpdateEvent& e) { MXLOG_INFO("MyEvent", "I am called every frame!"); });

Reading input from user devices

To read input, you can add event listener or just retrieve state in update method. Also, there are binders for player controls

auto player = MxObject::Create(); auto control = player->AddComponent<InputController>(); control->BindMovement(KeyCode::W, KeyCode::A, KeyCode::S, KeyCode::D); if (Input::IsMousePressed(MouseButton::LEFT)) ShootBullet(player);

Integrating your editors into MxEngine runtime editor

If you want custom editors in your application, you can use ImGui functions in update loop

void OnUpdate() override { if(Runtime::IsEditorActive()) { ImGui::Begin("MySettings"); ImGui::InputFloat("player health", &health); ImGui::InputFloat("player ammo", &ammo); ImGui::End(); } }

Saving rendered images to disk

Sometimes you want to save rendered image to your hard drive. There are functions to do so

auto texture = cameraController->GetRenderTexture(); ImageManager::SaveTexture("images/camera.png", texture); ImageManager::TakeScreenShot("images/viewport.png");

Drawing debug primitives

There are cases when you just want to display some 2D primitives to debug your game or check current object state

auto debug = object->AddComponent<DebugDraw>(); debug->RenderBoundingBox = true; debug->BoundingBoxColor = Colors::Create(Colors::RED); Rendering::Draw(Line({0.0f, 0.0f, 0.0f}, {10.0f, 10.0f, 10.0f}), Colors::Create(Colors::GREEN, 1.0f));

Scene managing

You can save your game objects, resources and scripts into a json script file. They can be loaded later with one function

// application state and all MxObjects and resources are saved and written to a json file Scene::Save("scene.json"); // to completely replace current scene with another simply load a json file Scene::Load("another_scene.json");

Dependencies

If you are interesed in libraries MxEngine depend on, consider reading dependencies.md file. It contains third-party library list with links to each project's github repository and brief explanation of why each library is used in the engine. Note that some of the libraries are shipped in modified version, so do no try to edit engine CMake file if your are unsure if everything will still work correctly

Answers to some questions:

  • Is it possible to build MxEngine under Linux/MacOS/other system?

    MxEngine supports Windows/Linux builds. Unluckly, other systems are not supported out-of-box for now. If you want to help with porting library to other systems, consider reading PR guideline.

  • Whats the roadmap for the engine? Which features can I expect to see, if I follow this repository?

    I put all features and not-fixed bugs to the public trello board. If you want to see some specific feature in engine, which is not mentioned already, you can request it in feature request issue

  • Why do you do this project? How long are you planning to develop the engine? Will it one day be better than UE/Unity/Godot?

    Initially this was an educational project (actually I still learn a lot of new things when developing it), where I learned about OpenGL, graphics, software engeneering and game development. I loved it and still love to spend my free time fixing some stuff or implementing new features. Thats really a great opportunity to have such cool project, even if it will never be any better than existing game engines like Unity or Unreal Engine

  • If I want to help you with development, how can I get into this project? Is there a documentation for it?

    Sadly there are too much things that I need to document and so much features which I need to implement, that I have almost no time for proper documentation. You can start with ProjectTemplate CMake project, and try some things for yourself. I promise I will add more samples with each release to make usage of the engine easier. If you want to help me with developing, building on other systems or fixing bugs, first contact me personally (links to my social media can be found in my profile). We can discuss what you may do and how can you help the engine to progress

More engine screenshots

<p align="center"> <img src="preview_images/readme_additional1.png"> <i>physics simulation with colliders turned on</i> <img src="preview_images/readme_additional2.png"> <i>Sponza scene with one point light</i> <img src="preview_images/readme_additional3.png"> <i>light and sound bounds, other debug utilities</i> </p> <img src="preview_images/readme_additional4.png"> <i>shadow casting from dynamic lights, screen-space reflections</i> </p>

Special thanks

God Ray Effect by #Fall2019

<img src="preview_images/readme_god_ray.PNG"> </p>

Projects based on MxEngine

Here is the list of some projects using MxEngine. If you want to see yours here, contact me.

PathTracer by MomoDeve

Path tracing in GLSL shaders, project link: https://github.com/MomoDeve/PathTracer

<p align="center"> <img src="https://github.com/MomoDeve/PathTracer/blob/master/preview.png"> </p>

Rainball by WhiteBlackGoose

3D pseudo water simulation, project link: https://github.com/WhiteBlackGoose/Rainball

<p align="center"> <img

编辑推荐精选

TRAE编程

TRAE编程

AI辅助编程,代码自动修复

Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

热门AI工具生产力协作转型TraeAI IDE
蛙蛙写作

蛙蛙写作

AI小说写作助手,一站式润色、改写、扩写

蛙蛙写作—国内先进的AI写作平台,涵盖小说、学术、社交媒体等多场景。提供续写、改写、润色等功能,助力创作者高效优化写作流程。界面简洁,功能全面,适合各类写作者提升内容品质和工作效率。

AI助手AI工具AI写作工具AI辅助写作蛙蛙写作学术助手办公助手营销助手
问小白

问小白

全能AI智能助手,随时解答生活与工作的多样问题

问小白,由元石科技研发的AI智能助手,快速准确地解答各种生活和工作问题,包括但不限于搜索、规划和社交互动,帮助用户在日常生活中提高效率,轻松管理个人事务。

聊天机器人AI助手热门AI工具AI对话
Transly

Transly

实时语音翻译/同声传译工具

Transly是一个多场景的AI大语言模型驱动的同声传译、专业翻译助手,它拥有超精准的音频识别翻译能力,几乎零延迟的使用体验和支持多国语言可以让你带它走遍全球,无论你是留学生、商务人士、韩剧美剧爱好者,还是出国游玩、多国会议、跨国追星等等,都可以满足你所有需要同传的场景需求,线上线下通用,扫除语言障碍,让全世界的语言交流不再有国界。

讯飞智文

讯飞智文

一键生成PPT和Word,让学习生活更轻松

讯飞智文是一个利用 AI 技术的项目,能够帮助用户生成 PPT 以及各类文档。无论是商业领域的市场分析报告、年度目标制定,还是学生群体的职业生涯规划、实习避坑指南,亦或是活动策划、旅游攻略等内容,它都能提供支持,帮助用户精准表达,轻松呈现各种信息。

热门AI工具AI办公办公工具讯飞智文AI在线生成PPTAI撰写助手多语种文档生成AI自动配图
讯飞星火

讯飞星火

深度推理能力全新升级,全面对标OpenAI o1

科大讯飞的星火大模型,支持语言理解、知识问答和文本创作等多功能,适用于多种文件和业务场景,提升办公和日常生活的效率。讯飞星火是一个提供丰富智能服务的平台,涵盖科技资讯、图像创作、写作辅助、编程解答、科研文献解读等功能,能为不同需求的用户提供便捷高效的帮助,助力用户轻松获取信息、解决问题,满足多样化使用场景。

模型训练热门AI工具内容创作智能问答AI开发讯飞星火大模型多语种支持智慧生活
Spark-TTS

Spark-TTS

一种基于大语言模型的高效单流解耦语音令牌文本到语音合成模型

Spark-TTS 是一个基于 PyTorch 的开源文本到语音合成项目,由多个知名机构联合参与。该项目提供了高效的 LLM(大语言模型)驱动的语音合成方案,支持语音克隆和语音创建功能,可通过命令行界面(CLI)和 Web UI 两种方式使用。用户可以根据需求调整语音的性别、音高、速度等参数,生成高质量的语音。该项目适用于多种场景,如有声读物制作、智能语音助手开发等。

咔片PPT

咔片PPT

AI助力,做PPT更简单!

咔片是一款轻量化在线演示设计工具,借助 AI 技术,实现从内容生成到智能设计的一站式 PPT 制作服务。支持多种文档格式导入生成 PPT,提供海量模板、智能美化、素材替换等功能,适用于销售、教师、学生等各类人群,能高效制作出高品质 PPT,满足不同场景演示需求。

讯飞绘文

讯飞绘文

选题、配图、成文,一站式创作,让内容运营更高效

讯飞绘文,一个AI集成平台,支持写作、选题、配图、排版和发布。高效生成适用于各类媒体的定制内容,加速品牌传播,提升内容营销效果。

AI助手热门AI工具AI创作AI辅助写作讯飞绘文内容运营个性化文章多平台分发
材料星

材料星

专业的AI公文写作平台,公文写作神器

AI 材料星,专业的 AI 公文写作辅助平台,为体制内工作人员提供高效的公文写作解决方案。拥有海量公文文库、9 大核心 AI 功能,支持 30 + 文稿类型生成,助力快速完成领导讲话、工作总结、述职报告等材料,提升办公效率,是体制打工人的得力写作神器。

下拉加载更多