This is the user documentation for Soft2D-for-Unity.
Soft2D is a 2D multi-material continuum physics engine designed for real-time applications. Soft2D for Unity provides a high-level encapsulation for Soft2D and offers users a range of easy-to-use interfaces, enabling users to easily implement various physical simulations and rendering effects in Unity.
Unity Version | Graphics API | Rendering Pipeline | Scripting Backend |
---|---|---|---|
2021.3.22f1 or higher | Vulkan or Metal | Built-in or URP | IL2CPP |
Note: MacOS currently only supports M1 chips.
Users can use Soft2D-for-Unity in two ways:
- Download this repository and open it as a new project in Unity.
- Download the plugin package file from the Asset Store and import it into an existing project.
If you clone this project using git
, make sure to use git-lfs
to correctly pull the binary files in the project.
Download the Soft2D-for-Unity plugin from the Unity Asset Store and import it into an existing project. Once the import is complete, the plugin will automatically pop up a start-up window. Clicking "Run and Restart" will perform the following actions:
- The project's
Graphics API
setting will be modified toVulkan
orMetal
. - The project's
Scripting Backend
setting will be modified toIL2CPP
. - If the current rendering pipeline is the URP, a macro
SOFT2D_URP_PIPELINE
will be added into the project settings.
This section introduces how to use the Soft2D-for-Unity plugin in the Unity editor. All tutorial scenes used in this section can be found in Soft2D/Tutorial/
.
Soft2DManager
is the core scene manager, responsible for managing scene parameter configuration, rendering, and managing objects (bodies, colliders, and triggers). A Soft2DManager must be placed in the scene to use the related functions of the plugin. For more details, see Soft2DManager.
A body is a continuum that can be simulated, composed of a group of particles. It is the most common object in Soft2D-for-Unity. For more details, see Body. The following video shows how to create a body in the editor:
Body.mp4
A custom body is a body with user-specified sample points. Users can customize the particle positions within the body. For more details, see Custom Body.
CustomBody.mp4
A mesh body is a body with topological relationships. Each vertex position of the input mesh will generate a particle, and they follow the topology of the triangles within the mesh. For more details, see Mesh Body.
MeshBody.mp4
An emitter is an object that can freely control the emission of bodies. For more details, see Emitter.
Emitter.mp4
A collider is an obstacle that blocks the movement of bodies. For more details, see Collider.
Collider.mp4
Users must enable the
World Query
option inSoft2DManager
for the trigger to work properly. See World Query Settings.
A trigger is a spatial region with a specific shape that can detect particles passing through it. For more details, see Trigger.
Trigger.mp4
Debugging tools can be used to visualize colliders or triggers in the scene. For more details, see Debugging Tools.
DebugTools.mp4
See Custom Shaders.
We provide several sample scenes to demonstrate how to use Soft2D-for-Unity in games. These sample scenes can be found in Soft2D/Samples/
.
This is a game with multiple levels. Users can interact with the content in the scene through the mouse, fingers, or a gyroscope. The default building content of the Unity project in this repository is all the levels of this game. Supports Windows/Linux/MacOS/iOS/Android platforms.
In this scene, the post-processing effect is only supported in the URP pipeline. The built-in pipeline does not support the post-processing effect.
With Post-processing (URP) | Without Post-processing (Built-in) |
---|---|
In this scene, the post-processing effect is only supported in the URP pipeline. The built-in pipeline does not support the post-processing effect.
With Post-processing (URP) | Without Post-processing (Built-in) |
---|---|
This scene only supports the URP pipeline. And please use
3D URP
pipeline to ensure correct lighting effects.
This scene only supports the URP pipeline. And please use
3D URP
pipeline to ensure correct lighting effects.
The tutorial scenes does not render correctly in the 2D URP
pipeline.
- Please change the background of camera from
Skybox
toSolid Color
.
Skybox | Solid Color |
---|---|
How to simulate very small objects in a large-scale world?
- In Soft2D-for-Unity, the sampling density of the particles in a body is automatically adjusted based on the size of the world. A larger world will lead to sparser particle sampling. Therefore, there may not be enough precision to simulate very small objects in a larger world.
Can different rendering materials be set for different particles?
- Currently, particles are drawn using the
Graphics.DrawMeshInstancedIndirect()
method, which temporarily does not support setting different materials for different particles.