CS2's Responsive Smoke with Godot 4 In 5 Minutes

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
recently valve announced Counter-Strike 2 and showed off some of the new features I really like the response to smoke grenades and wanted to have a go at recreating the mechanic with ingado here's how to create a similar mechanic for your game the hardest part of this video would be implementing volumetric fog to act as our smoke fortunately for us this is built into Godot 4 the new fog volume node is perfect for what we need if you add a fog volume node to your scene nothing will happen that's because we need to enable volumetric fog in the world environment we can then change the density to zero so that only our fog volume will contribute fog to the scene now we have a cube of fog there's a few preset shapes we can set it to for the purpose of our smoke cloud though ellipsoid works very well we can add a fog material to further control how the fog appears in the scene density controls how thick the cloud is Albedo and emission changes the colors of the volume height fall off makes the density lower the higher it gets on the y-axis Edge fade controls a fall off as it gets to the edges of the shape and finally density texture is a 3D texture that can be used to add variants to the fog volume density here is a 16x16 3D noise texture I found online and this is the effect it has when we apply it to the fog if you want to increase the quality of the fog head to the advanced settings and then in rendering and environment we have a volumetric fog section I tend to double or even quadruple these values but be careful if you have a slower rig the fog looks great and reacts well to light but it's very static what can we do to animate it well Godot 4 adds a new fog Shader type that we can use to add further control to how the fog looks here I've written a simple fog Shader that does everything the default fog material does I've then added a 3D Simplex noise function that I found on Shader toy I sample the noise using the fog volumes 3D UV coordinates while adding some time to the y-axis this makes a noise animate upwards I then multiply the density with this value to make the fog look less rounded I've subtracted the noise value with this mask that Fades from the center which will help accentuate the noise at the edges of the smoke I think this looks pretty good but there's a lot you can do to this to really make it look more like the smoke that you can find in say count stroke 2 but I'll leave that up to you here's what the final smoke looks like in action I created a simple rigid body for the grenade that has a Time on it when the timer expires it spawns the smoke volume scene the scene itself has a script attached to it that uses tweening to animate the density of the volume allowing it to be faded in and then out again after a Time well this gives us a simple volumetric smoke but how can we make it react to our bullets and frag grenades lucky for us Godot 4 gives us a solution for that too you see fog volume's density values doesn't just scale from zero to eight we can use negative numbers too to make subtractive fog volumes this makes things very simple for our frag grenades to make these grenades Blow Away fog it's the exact same process as our normal smokes but the volume has a negative density I've also tweaked the tweening parameters so that the fog will fade back in a bit sooner [Music] look for bullets all we need to do is place a cylinder shape negative fog volume and it will punch a hole right through our fog here's a simple script I wrote that will spawn it for us first though let's create a scene for our negative fog volume make sure our fog volume isn't the root so we can have the length of the cylinder volume point along the z-axis you can also use the smoke fade script from before to fade out the bullet wake over time then in my player script when the gun is fired we cast array we can use the start and hit position of the ray to calculate the length needed for this volume to Encompass that distance we then instantiate the volume when we set the volume's height it's scaled on the shape's origin in the center of the object because of this we need to place the wakes volume halfway along the ray we can then use a lookup function with our hit position to point knit in the right direction and there we have it a simple reactive smoke [Music] this should probably be enough for most of you but another feature of the smoking Counter-Strike 2 is that it uses cubes in the world to allow it to fit to a volume while we can do something similar here too the fog implementation has been optimized to allow us to use hundreds of these volumes without significant performance impacts so we can create our smoke out a smaller Cube shaped fog volumes without any issue here I've used a simple script that creates a sphere of Q volumes starting from the middle and expanding out in a circle we only spawn cubes when there isn't a collision at the potential spawn point and count up aspawn cubes if we meet our required quota of volumes then we stop this means that if we sandwich our smoke between Some solid objects it will then expand outwards more [Music] foreign [Music] this was a pretty simple implementation and there's a lot you could do with this to make it look and feel better hopefully I've given you some ideas on how you might be able to create similar mechanics in your own games anyway as always there's a link to the code that I've used in the video in the description as well as any other resources I found useful while researching this video let me know in the comments if there's anything else you'd like me to cover in the future don't forget to like subscribe and yeah see ya cheers
Info
Channel: Crigz Vs Game Dev
Views: 90,535
Rating: undefined out of 5
Keywords: Godot, Godot 4, Responsive Smoke, Reactive Smoke, Volumetric, Volumetric Smoke, Volumetric Fog, indie, indie game, indie game dev, game dev, devlog
Id: zNbku2qrtDM
Channel Id: undefined
Length: 5min 34sec (334 seconds)
Published: Sun Apr 02 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.