NokiMo
pucklovesgames
pucklovesgames

patreon


Blobby Polygonal Clouds and Liquid - FILES

Here is a way to make blobby liquids and smoke from simple geometry (sphere in this case) by messing with the gbuffer (blurring the normals) and then compositing it back to the main camera with a depth comparison.

This is a big one for me, with a bunch of different areas all coming together. It's important to know that it's just a starting point, I feel like there's so much potential in this area that I'll be playing and uncovering things here for a while. I'm very excited about the possibilities for non-photorealisitic rendering using stuff I've learnt from this.

There's a few things which go into making this effect.

Blurring the normals using Command Buffers.

A Command Buffer can be added to any camera, in order to read AND write to the gbuffer on deferred cameras. With forward rendering cameras I think you're mostly limited to reading and saving out render textures (like depth and normals), but if you're using a deferred camera, you can get up to a whole bunch of mischief.

Read about them more here:  https://docs.unity3d.com/Manual/GraphicsCommandBuffers.html 

Why do we want to blur the normals? On a deferred camera, the lighting is calculated in screenspace, after a bunch of render textures are made, including normals and depth. This allows a deferred renderer to have heaps of lights without effecting performance the way it would in a forward renderer. If we take that normals render texture, and blur it, then the edges between objects will blend into each other when the lighting is calculated, because the lighting uses the light direction and the normals dot product to work out what areas are lit.

I've made a camera that I'm using to render the blobby objects, which has it's Culling Mask set to the 'Cloud' layer, and all the blobby objects are also on that layer, so they only render in that camera.

I've then got a script on this camera which adds a Command Buffer. In the case of blurring the normals, this Command Buffer is added 'After Gbuffer' and then makes a copy of 'GBuffer2' (which is the internal name for the normals render texture). It then blurs that copy (through a separate blur shader) and then afterwards, writes it back to the gbuffer. 

This is done on the Command Buffer Camera Blur scrip on the Cloud Camera.

By the time the lighting is calculated in the render pipeline, the normals have been blurred, and everything blends into each other nicely.

Compositing the second camera into the first via a depth comparison.

I'm also rendering out depth separately on the Cloud Camera. I'm also doing this via Command Buffers - it is done on the Grab Render Texture Command Buffer script on the Cloud Camera. I've made this script a bit more open, so you could also use it to write global textures for any of the gbuffers, but if you just want to grab the depth, then leave the Camera Event at 'Before Lighting' and the Render Texture Type to 'Resolved Depth' on a deferred camera. The string you put in 'Command Buffer Name' has to match the Global Texture Sampler name you use in your shader.


I'm then compositing the Cloud Camera render texture back onto the Main Camera by comparing the depths of the two cameras. This allows controlling the blend softness between the clouds and non-cloud objects. It also means you can add your own textures and effects to the depth - in this case I'm adding a slight world noise distortion to break the clouds up more, which can also be animated to give them movement.

This is done in the Post Process Blit script on the camera, specifically in the attached shader SkyCloudsPP.

So much more to do.

There are so many more ways I can think to use these new toys. I've made up a very basic effect as part of this package because I wanted to get it out to everybody as soon as I could, but I'm also working on a bunch of other more advanced uses. You don't need to stop at just blurring the normals or depth, you can pass those gbuffers through any shader you want for all sorts of cool stylised effects.

Something not working?

There's a lot of different parts to this, and it's quite complicated, so let me know if anything doesn't make sense or doesn't work properly, here or on discord, and I'll fix it up ASAP.

Thanks for the support!

Blobby Polygonal Clouds and Liquid - FILES

Related Creators