Unity VFX -- (5) VFX Graph Basics

        In Unity, there is also a completely different workflow for creating VFX, the VFX Graph. VFX Graph can generate the same or better effects than particle systems.

        Compared with the particle system, one of the biggest benefits of VFX Graph is that it can simulate much more particles while maintaining good performance of the application. For VFX artists, one of their main responsibilities is to ensure that the special effects they produce do not affect the overall usability and frame rate of the application, so performance optimization is very important.

The difference between VFX Graph and particle system

        VFX Graph is a node-based editor. It looks more complex than a component based particle system.

Advantages of VFX Graph

        VFX Graph can process millions of particles at the same time, and the number of particles that the particle system can process at the same time is smaller than that of VFX Graph.

        The more complex effects produced by VFX Graph, such as the sprite at the beginning, are almost impossible for particle systems.

Disadvantages of VFX Graph

        VFX Graph is more difficult for beginners than particle system.

        VFX Graph has stricter hardware requirements (for specific hardware requirements and related documents, please refer to this link Requirements and compatibility | Visual Effect Graph | 12.0.0 ), which may not be available on some devices.

        VFX Graph runs on the GPU, and Unity's physical calculations are placed on the CPU, so the particles of the VFX Graph cannot interact with other physical effects of the application (such as collision with the ground). Particle systems run on the CPU, so they can interact with physics-based components.

How to choose VFX Graph and particle system

        If we have rich experience and need to create very complex effects, or the effects require million-level particle support, we can choose VFX Graph.

        If we are not experts and just want to create some simple effects that can run on all devices, or the effect needs to interact with other physically-based objects in the scene, use particle systems.

        The following two pictures are a comparison of a weather effect. The number of particles that need to be simulated for this effect is 1 million, which are realized by particle system and VFX Graph respectively.

        The particle system only has a poor 5.6FPS.

        VFX Graph still has a performance of 100 FPS in the case of simulating millions of particles.

Put a VFX Graph special effect into the scene

         1. Turn off the environmental particles made in the previous notes (just set it to inactive in the Inspector).

        2. In Assets -> CreativeCore_VFX -> VFX -> Samples, drag one of the weather VFX Graph prefabs (Snow_VFXGraph_Prefab.prefab is selected in this case) to the Heirarchy.

        3. Move this newly added object position into the air to make the scene look like it is raining or snowing.

Open the VFX Graph editor window

        1. When the VFX Graph object is selected, locate its Visual Effect component. The icon of this component is a small light.

        2. Select the Edit button to open the VFX Graph window

        3. Rearrange the window layout so that you can see the VFX Graph and the scene at the same time.

VFX Graph editor mobile tour

         Before starting to edit the VFX Graph, we can try to move the navigation in the editor area to get familiar with it. Similar to Shader Graph or animation state machine editor, the main navigation methods in VFX Graph are:

        Pan: Hold down the middle of the mouse and drag, or hold down Alt (Windows) or Option (MAC), click the mouse and drag.

        Zoom (Zoom): Scroll the mouse wheel.

        Focus and zoom in: Select an element and press F.

        Fit to window: Press the A key.

         Let's take a look at the VFX Graph as a whole. It has four main nodes, distributed vertically from top to bottom. These four default nodes are called context nodes (Context Nodes, or Context for short).

Browse the VFX Graph context

Spawn Context

        The first context, which controls the generation of particles, is similar to the Emission module of the particle system.

        By default, a new VFX Graph uses a constant particle spawn rate (spawn rate), but we can change it to variable, periodic or bursts, just like the smoke effect did before.

        1. Adjust the Rate property to make the special effects of the VFX Graph version consistent with the Rate of the weather special effects made with the particle system.

                The spawn rate here can be set to a large value, while having little impact on FPS.

Initialize Particle Context

        Initializing the particle context controls where and how the particles initially appear. This context contains many of the same properties as in the main Particle System module, including the initial size, shape, velocity, lifetime, and maximum number of particles. It also contains the equivalent property of Shape in the particle system, which defines the shape of the container where the particles are generated.

        2. Configure and initialize the particle context, so that the effect of the VFX Graph version looks similar to the weather effect made by the original particle system.

Update Particle Context

        Updating the Particle Context controls what happens to a particle from spawning to disappearing. This update operation runs every frame. Contains properties similar to those in the particle system: Color over Lifetime, Size over Lifetime, Noise (called Trubulence in VFX Graph) and Texture Sheet Animation (called Flipbook Player in VFX Graph).

        Each behavior can be added as a new Block in the context. For example, the Turbulence in the picture above is a Block.

        3. Try to create a new Block by right-clicking in the Context and selecting Create Block. We can search for the Block to be added through the search box in the submenu.

Output Particle Context

        The output particle context controls the appearance of each particle, which is similar to the function of the Renderer module in the particle system. Here we can assign materials to the particles.

        4. Configure the output particle context so that the effect of the VFX Graph version looks similar to the weather effect made by the original particle system.

Create a brand new VFX Graph

        1. In the Project window (note that it is not Heirarchy), right-click, select Create -> Visual Effects -> Visual Effect Graph, and then put the newly created VFX Graph into Heirarchy. Then move it to where you want it in the scene.

        2. Double-click VFX Graph in the Project window to open the VFX Graph editor window.

        3. Try to modify some Blocks to see if you can achieve the effect you want, such as the effect of exploding fireworks.

View a complex VFX Graph

        Next, let's look at a professional-level VFX Graph example to get a feel for what a complex VFX Graph looks like.

        1. From the main menu, select Window -> Package Manager, then select Visual Effect Graph. In the right pane, expand Samples, then select Import to import VisualEffectGraph Additions.

        2. The sample will be automatically imported into the directory we opened in the Project window. Find Bonfire (you can search directly in the search box of the Project window), and drag it into the Hierarchy.

         3. In the Project window, double-click Bonfire to open the VFX Graph editor and take a look at the graph.

        Similar to the concept of the subsystem of the particle system, bonfire is also composed of several subgraphs: Smoke, Flames and Sparks. Each subgraph is connected together by a node group, and a random wind direction is added in the middle.

        We also noticed that these VFX Graphs use Operators, which are smaller nodes connected to the main context.

        Operators allow us to use mathematical calculations and logical expressions to customize behavior, which is crucial for the simulation of more complex effects. 

        VFX Graph can be complex easily and quickly. As the complexity increases, the effects become more complex and rich.

Challenge: Use VFX Graph to produce the fire and smoke effects previously created with the particle system

        For a more detailed description of VFX Graph, you can refer to the official documentation:

 Visual Effect Graph | Visual Effect Graph | 6.9.2-preview

Guess you like

Origin blog.csdn.net/vivo01/article/details/130245113