Particle parameters are a strong system constructed into the Unreal Engine* that permits the customization of particle techniques outdoors of Unreal Engine 4’s Cascade particle editor. This tutorial creates such a system and demonstrates how you should use it to spice up visible constancy.
Why use particle parameters?
Particle parameters are important to any recreation that seeks to leverage particle techniques to their most potential. The aim is to make particle techniques reply dynamically to the world round them.
On this tutorial, we use particle parameters together with CPU particles to vary the lighting of a scene based mostly on a gameplay component, on this case the gas left on a hearth (see Determine 1). As the quantity of gas on the fireplace decreases, so does the visible impact created by the particle system and the lighting created by the fireplace particles in that system. As soon as the gas is totally gone, we begin to fill the gas again up once more till the gas is again to the place it began. This creates a pleasant loop that demonstrates the complete vary of the particle impact.
Determine 1. Campfire with particle parameters.
Including Parameters to P_Fire
Determine 2. Particle parameters.
To make this particle impact, we modify the P_Fire particle system included within the Unreal Engine starter content material. In Determine 2, modules that we modify are highlighted in purple, and modules we add are highlighted in orange.
Lighting is without doubt one of the main advantages of utilizing CPU particles and can kind the core of this impact.
Determine 3. First flame emitter.
Choose parameter distribution on the distribution drop-down menu
Within the particulars panel of the primary flame emitter within the P_Fire particle system, choose Distribution Float Particle Parameter from the Brightness Over Life Distribution drop-down menu as proven on the prime of Determine 3. This enables us to tie the quantity of sunshine emitted to a variable, on this case, the quantity of gas left within the fireplace.
The subsequent step is to specify which particle parameter this distribution will probably be tied to. We’ll use the title “FuelLeft“. Enter this within the Parameter Identify subject, as present in Determine 3.
Set mapping mode
A highly effective function of particle parameters is enter mapping. This function permits us to specify the max and min enter that we’ll settle for and to scale these values to a given vary as a way to make a single enter parameter perform seamlessly for a lot of totally different modules. This functionality permits us to make totally different elements of the particle results scale down at totally different factors. Results just like the sparks and embers will solely begin to change as soon as the fireplace begins burning low, and we are going to set their enter vary to replicate that. We’ll use DPM Regular for all of the distributions on this tutorial as we need to each clamp the enter and scale it to a selected vary. That is chosen beneath the Param Mode drop-down menu proven in Determine 3.
Set enter vary
Subsequent we specify the min and max output. For this impact, we’ll use 0.0 for the min and 1.0 for the max, as proven in Determine 4. This implies the sunshine from this a part of the fireplace will scale from Zero % gas (totally darkish) to 100 % gas (a pleasant campfire glow).
Determine 4. Setting enter vary.
Set output vary
The output vary lets us specify the minimal and most brightness for this a part of the fireplace. Set these to the values proven in Determine 5.
Determine 5. Setting output vary.
Set default enter worth
Now we have to set a default enter worth in case the impact just isn’t given a worth. That is completed with Fixed (see Determine 6). For this particle system, we’ll set the default at 1.0, or a full flame.
Determine 6. Setting the default worth.
Organising the remainder of the modules
Second emitter mild
To make sure the sunshine emitted by the fireplace is in keeping with the particles within the particle system, we modify the sunshine module on the second emitter as nicely. Change the Brightness Over Life part on the sunshine module on the second emitter to match the values proven in Determine 7. If we did not scale this mild supply as nicely, the fireplace would nonetheless emit a full glow when it’s simply embers.
Determine 7. Second emitter mild.
First and second emitter scale
Presently, the quantity of sunshine that our fireplace produces will change with gas, however the dimension of the flames is not going to. To alter this, we add a Dimension Scale emitter to each the primary and second emitter as proven in Determine 2. This distribution will probably be a Vector Particle Parameter as a substitute of a Float Particle Parameter. Since we’re giving it the identical parameter title because the Float Particle Parameter, Cascade copies the float worth throughout all three fields for our vector. For each modules, we would like the graphics to scale in dimension from Zero % to 100 % gas, so the one fields we have to change are Parameter Identify and Fixed. Set each modules to match the values proven in Determine 8.
Determine 8. Emitter scale.
Smoke spawn fee
Smaller fires produce much less smoke, and we are able to modify our particle system to replicate that. To do that, we arrange a particle parameter on the speed part of the spawn module on the smoke emitter. Nevertheless, not like the earlier particle parameters we arrange, we solely need to begin cutting down the smoke spawned after we attain 40 % gas and beneath. To do that, set the Max Enter to 0.4 as a substitute of 1. Set Distribution to match the values proven in Determine 9.
Determine 9. Smoke spawn fee.
Embers spawn fee
Embers additionally scale with the scale of the fireplace, however do not begin cutting down till our fireplace will get actually small. We’ll begin cutting down embers at 50 % (0.5) for this impact. Set the Spawn Fee Distribution on the Embers emitter to match the values proven in Determine 10.
Determine 10. Embers spawn fee.
Distortion spawn fee
The distortion attributable to the flames must be scaled in the identical approach that the flames are scaled. Since we scaled the flames from Zero % to 100 % gas, we have to do the identical with the distortion. Set the Spawn Fee Distribution on the Distortion emitter to match the values proven in Determine 11.
Determine 11. Distortion spawn fee.
Arrange a blueprint
Now that our fireplace impact might be scaled with the quantity of gas, we have to arrange a blueprint to set the quantity of gas. On this tutorial, the quantity of gas slowly depletes, after which fills again up once more to display the impact. To create a blueprint for this impact, drag the particle system into the scene, after which click on Blueprint/Add Script within the particulars panel.
Organising the variables
For this impact we are going to want simply two variables, as proven in Determine 12 beneath:
FuelLeft: A float that retains observe of how a lot gas is in our fireplace, starting from 1 for 100 % gas to Zero for Zero % gas. The default is about to 1, so the fireplace begins at full flame.
FuelingRate: A float that dictates how shortly we deplete or fill gas. For this tutorial, we’ll set the default worth to -0.1 (-10 % per second) for this tutorial.
When each variables have been created, the variable part of the blueprint ought to match that of Determine 12.
Determine 12. Hearth variables.
Altering gas left
For this impact, we have to change the quantity of gas left each tick and apply it to the particle system. To do that, we multiply the Fueling Fee by Delta Seconds and add it to Gasoline Left. This worth then will get set to Gasoline Left.
To use Gasoline Left to the particle system, we use the Set Float Parameter node. For the goal, we use our modified P_Fire particle system element, and for Param we use Gasoline Left. The parameter title must be the title we utilized in our particle system, which on this tutorial is FuelLeft.
Determine 13. Modifying gas left.
Bounding gas left
Finally our fireplace will run out of gas. On this tutorial, we need to change to fueling the fireplace as a substitute of depleting it at that time. To do that, we proceed to work on the tick and examine whether or not our new gas worth is simply too low (lower than or equal to -0.1) or too excessive (larger than or equal to 1.0). The explanation we set the low bounds to -0.1 is in order that the fireplace will keep depleted for a bit earlier than refueling. This does not trigger any issues as a result of any values handed to our particle system beneath Zero are handled as Zero as a result of min enter we arrange.
If we discover that Gasoline Left is out of bounds, we multiply the Fueling Fee variable by -1. If Gasoline Left is being decreased, this may trigger it to be elevated in subsequent ticks, or vice versa whether it is being elevated.
Determine 14. Bounding gas left.
Click on right here to Be part of the Intel® Sport Dev program at no cost instruments, sources, and alternatives that can assist you carry the most effective recreation expertise to the most important worldwide viewers
Supply: https://software program.intel.com/en-us/articles/boost-visuals-with-particle-parameters-in-unreal-engine-4