Getting Started
Demo Scenes
Example scenes using FluidFlow can be found in FluidFlow/Example/Scenes.
Each example scene contains a RP Material Switcher object at the top of the Hierarchy which allows swapping the materials in the scene to match your current rendering pipeline.
A minimal example for setting up a FFCanvas
-
Add a
FFCanvascomponent to an object in your scene. -
Assign the renderers of the objects you want to draw on, to the Surfaces of the
FFCanvas, and set up the surface as described in FFCanvas. -
Add the Texture Channels you want to draw on, and set their Texture Channel Format.
-
Assign a material to your Surfaces' renderers, that supports drawing to the selected Texture Channels. Fluid Flow provides basic shaders (integrated RP, URP, HDRP) that support drawing to the
Color,Normal, andFluidtexture channels. -
When the internal texture channels of a
FFCanvasare shared by multiple Surfaces (UV Scale != (1,1),UV Offset != (0,0)), the renderers' materials need to transform their UVs before sampling the texture set by theFFCanvas. Most shaders support this out-of-the-box via theTilingandOffsetof the texture property. In the Material Property Overrides of theFFCanvasyou can you can set the name of this property for a given shader (if no target shader is set, it applies to all shaders). Unity's default naming scheme for accessing theTilingandOffsetof a given texture property, e.g._MainTex, is adding_STto the property name (_MainTex_ST). -
You should now be able to draw to the
FFCanvasas described in Drawing. For testing you can simply add aSimple Project Decalcomponent, and assign a camera andFFCanvas. This should allow you to project a decal onto the canvas by clicking on the objects in theGamewindow while playing.
Texture-based fluid simulation
-
Add a
Fluidtexture channel using theFluidFormatandBLACKinitialization to yourFFCanvas. -
Make sure, your renderers have a material assigned, which is able to overlay the
Fluidtexture channel. FluidFlow provides example shaders for all rendering pipelines. -
Add a
FFGravityMapcomponent and assign the targetedFFCanvas. -
Add a
FFSimulatorcomponent, assign theFFGravityMapcreated before, and selectFluidas the targeted texture channel. -
When paining to the
FFCanvas'Fluidtexture channel (using theFLUIDtype instead ofCOLORwhile painting), the painted fluid should flow according to gravity.
Particle-based fluid simulation
-
Add a
Fluidtexture channel using theFluidFormatandBLACKinitialization to yourFFCanvas. -
Make sure, your renderers have a material assigned, which is able to overlay the
Fluidtexture channel. FluidFlow provides example shaders for all rendering pipelines. -
Add a
FFGravityMapcomponent and assign the targetedFFCanvas. -
Add a
FFSimulatorParticlecomponent, assign theFFGravityMapcreated before, and selectFluidas the targeted texture channel. -
Instead of drawing to the
FFCanvas, fluid-particles have to be added directly to theFFSimulatorParticlecomponent, usingAddParticleorProjectParticles. Check out theSimpleDrawParticlecomponent for a simple example.