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
FFCanvas
component 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
, andFluid
texture channels. -
When the internal texture channels of a
FFCanvas
are 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 theTiling
andOffset
of the texture property. In the Material Property Overrides of theFFCanvas
you 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 theTiling
andOffset
of a given texture property, e.g._MainTex
, is adding_ST
to the property name (_MainTex_ST
). -
You should now be able to draw to the
FFCanvas
as described in Drawing. For testing you can simply add aSimple Project Decal
component, and assign a camera andFFCanvas
. This should allow you to project a decal onto the canvas by clicking on the objects in theGame
window while playing.
Texture-based fluid simulation
-
Add a
Fluid
texture channel using theFluidFormat
andBLACK
initialization to yourFFCanvas
. -
Make sure, your renderers have a material assigned, which is able to overlay the
Fluid
texture channel. FluidFlow provides example shaders for all rendering pipelines. -
Add a
FFGravityMap
component and assign the targetedFFCanvas
. -
Add a
FFSimulator
component, assign theFFGravityMap
created before, and selectFluid
as the targeted texture channel. -
When paining to the
FFCanvas'
Fluid
texture channel (using theFLUID
type instead ofCOLOR
while painting), the painted fluid should flow according to gravity.
Particle-based fluid simulation
-
Add a
Fluid
texture channel using theFluidFormat
andBLACK
initialization to yourFFCanvas
. -
Make sure, your renderers have a material assigned, which is able to overlay the
Fluid
texture channel. FluidFlow provides example shaders for all rendering pipelines. -
Add a
FFGravityMap
component and assign the targetedFFCanvas
. -
Add a
FFSimulatorParticle
component, assign theFFGravityMap
created before, and selectFluid
as the targeted texture channel. -
Instead of drawing to the
FFCanvas
, fluid-particles have to be added directly to theFFSimulatorParticle
component, usingAddParticle
orProjectParticles
. Check out theSimpleDrawParticle
component for a simple example.