meta4d-me / CatDogEngine

A cross-platform game engine/editor written in modern C++ (WIP)
GNU General Public License v2.0
161 stars 17 forks source link

ParticleSystem #415

Closed OVOAOVO closed 8 months ago

OVOAOVO commented 1 year ago

Workflow

If you want to use the particle system directly, including importing resources, you can add a particle emitter or a particle force field by clicking on the + in the EnitityList on the left. image Through the right side of the inspector panel to adjust the corresponding parameters, but at present our particleType only Sprite can be used, as well as the instance State at present because the uber shader has not yet been perfected the effect is not correct, these two points please note that! image Currently there is only one rotational force used in the force field, after checking the RotationForceValue box, a centripetal force will be generated inside the blue box. image If you need to import, please produce a .efkefc file (this file is generated by EffekSeer export) and export it to .cdbin file in AssetPipline, then directly drag it to the engine scene, we will access EffekSeer to make the process of importing less cumbersome! image image

These are two files you can check out https://github.com/CatDogEngine/TestAssets/tree/main/Particle You can see the introduction of these two documents in

To generate a cdbin file first you need to compile the EffekSeer related .exe .dll in AssetPipline (please add the EffekSeer SDK to your OS environment variables, then use MakeThirdParty.bat to build AssetPipline). image image Fill in the EffkseerToCD command parameters with the directory you want to output to and the filename.(the first parameter is empty fill in some random but can not not fill, the second parameter that is the output of the directory and file name) image In the Main.cpp file of EffkseerToCD you need to fill in the .efkefc file address image This will give you access to the generated .cdbin image Currently .cdbin import only supports properties that can be adjusted inside the engine, you can create a new particle emitter component to see which properties can be imported into the engine.

Functions completed so far and their drawbacks

Basic state update of particles (Particle.h/cpp, ParticleRenderer.h/cpp ) Particle pool maintenance (ParticlePool.h/cpp) GPU particles (vs/fs_particle.sc) Instantiating particles (ParticleRenderer.h/cpp, vs/fs_particle.sc) ECS component for particles (ParticleComponent.h/.cpp) Billboard View particles (ParticleRenderer.h/cpp, vs/fs_wo_billboardparticle.sc) Particle shader variants (ParticleComponent.h/cpp, vs/fs_particle.sc) Particle Force Field(ParticleForceField.h/cpp)

So far our particle base is relatively perfect, I mean the maintenance of particle pool and ECS management, but there are some features are not yet perfect, such as shader variants now do not support .vs caused by some of the functionality of the anomalies, we will follow up to fix these. Secondly, there are some features that we will do in the future, for example, the current particle type only supports mesh but not Ribbon Track and model in the list, we will support these features in the future, the shape of the particle emitter is only a box at the moment, we will add hemisphere, sphere and so on after that, there is no depth sort at the moment, which causes the particles to block each other, we will add bipartite sort or subsumption sort in the future. Translucent and opaque rendering, particle self-illumination, multi-threading .... etc. etc. There are still a lot of things that need to be done

Some Example

EffkSeer

EffekSeer

OurEngine catdog1 catdog2 cadog4 catdog3

Some performance

In the case of using instantiation the maximum number of particles that can be supported in the current engine is around 20,000 (maintained at 60fps VGA: 6600X).

T-rvw commented 1 year ago

What you tried to render particles is good. But to merge a engine feature, codes should be more generic.

  1. PrimitiveType for every particle.
  2. Motion types for every particle.
  3. Textures should not be fixed as one color texture. Learn about what is the meaning of material. You should create a material to present all rendering parameters and resources and states.
T-rvw commented 12 months ago

The idea to create all particles as a big vertex buffer + index buffer is wrong. As you are using DrawInstance, you just need to take care about how many mininum primitive types are used. Then create vb/ib for primtive types prepared for instancing.

OVOAOVO commented 9 months ago

For this billboard branch just open the comment in ParticleRenderer.cpp Replace the original bx::mtxSRT and you'll see the normal billboard To run the shader's billboard just select the billboard in the inspector panel

T-rvw commented 9 months ago

If you are ready to merge, please resolve conflicts and add some introduction to what particle system in this PR looks like because it is not a small feature which you can learn about it in 5 mins. As a suggestion, you should comment :

  1. Introduce a workflow from prepare asset file to render and adjust parameters to non-developers. Attach picture/gif is better.
  2. Introduce your feature list, implementation's pros and cons ri developers. Reference documents or codes.
T-rvw commented 9 months ago

You can also show some examples in this PR : snapshot in Effekseer editor, snapshot in CatDogEditor. How to adjust parameters to get a sprite particle emitter which has good visual appearance.

T-rvw commented 8 months ago

Use MeshUtils.hpp functions to replace duplicated vertex/index buffer build logics. Then should be OK to merge.