When writing your own fluid rendering shaders, include the /FluXY/Resources/Shaders/FluidUtils.hlsl file at the top of your shader. This will make a variety of helper functions and samplers available to you:
FluXY solvers expose 2 textures to all shaders:
You can use them anyway you like. Generally, the RGB channels of the density texture are interpreted as a color, and A interpreted as opacity. The velocity texture's A channel (which stores pressure) can be interpreted as fluid "height", useful for simulating waves, specially when using the iterative pressure solver.
When accessing the data in these textures, you should keep in mind that they store data for all containers in the solver. To access the region of the textures specific to a container, use the TileToUV() function included in FluidUtils.hlsl:
// convert texture coordinates from tile to normalized uvs: float2 uv = TileToUV(i.uv,_TileIndex); // use them to access velocity and density float4 density = tex2D(_MainTex, uv); float4 velocity = tex2D(_Velocity, uv);
If you're using Shader Graph to create your shaders, the TileToUV subgraph node you'll find in /Samples/Resources/Shaders/URP accomplishes the same goal.
FluXY includes a basic unlit fluid shader, compatible with all rendering pipelines. This is mostly used in conjunction with coontainers using "Plane" as their shape:
You will find this shader at FluXY/Rendering/BasicFluid:
Let's take a look at what this shader offers:
This is a grayscale texture that will be advected (carried) using the fluid's velocity texture input, and used to modulate fluid density. You can use this to cheaply add fine detail to your fluid:
If set, the shader will map the fluid's density to the U (horizontal) coordinate of this texture.
Amount of advection applied to the detail texture. This is a multiplier of the fluid's velocity vector.
A value of 0 will use alpha blending. A value of 1 will use additive blending. Any value in-between will interpolate between the two.
Opacity falloff applied at the edges of the container.
Softness at the intersection of the fluid container with other objects in the scene. Useful for smoke/fire effects.