# Duncan, help - fluid as a shader

**URL:** https://forum.highend3d.com/t/duncan-help-fluid-as-a-shader/41491
**Category:** Maya
**Tags:** fluids
**Created:** [January 30, 2004, 12:02am UTC](https://forum.highend3d.com/t/duncan-help-fluid-as-a-shader/41491 "2004-01-30T00:02:43Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![nrubens\_99](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/n/c0e974/32.png) [@nrubens\_99](https://forum.highend3d.com/u/nrubens_99)
#### Post date: [January 30, 2004, 12:02am UTC](https://forum.highend3d.com/t/duncan-help-fluid-as-a-shader/41491/1 "2004-01-30T00:02:43Z")

</div>

Duncan,

```
I am using fluids to shade a particle system. I now have a system where by each particle is an exact copy of the fluid object. This presents some problems. When clumps of particles are present, a repeating pattern occurs. I am looking for a way to have the fluid span several particles (where each group whould have a pattern) and track with them so that the particles do not appear to be moving through a static fluid system.    

```

My questions to you are:  
1.Is this possible to do?  
2.How do i span the UVs of a shader across a particle field

---

<div class="post-metadata">

### Author: ![bouncelight](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/b/c0e974/32.png) [@bouncelight](https://forum.highend3d.com/u/bouncelight)
#### Post date: [February 4, 2004, 9:38pm UTC](https://forum.highend3d.com/t/duncan-help-fluid-as-a-shader/41491/2 "2004-02-04T21:38:40Z")

</div>

bump this up…

i’d like to hear the answer as well. from anyone would be ok…

---

<div class="post-metadata">

### Author: ![duncanbrinsmead](https://forum.highend3d.com/user_avatar/forum.highend3d.com/duncanbrinsmead/32/395_2.png) [@duncanbrinsmead](https://forum.highend3d.com/u/duncanbrinsmead)
#### Post date: [February 5, 2004, 8:55pm UTC](https://forum.highend3d.com/t/duncan-help-fluid-as-a-shader/41491/3 "2004-02-05T20:55:16Z")

</div>

You can do what you want by using a particle sampler info to set the fluid’s texture scale and origin values.  
Basically you cache the start position per particle and use this to adjust the fluid texture origin in such a way that at the start frame all the particles are cut out of one larger block of texture( this initial coherence will break down as the particles move and pull the chunks of texture with them ). You could also adjust the texture scale based on the particle width, to preserve the overall frequency of the texture. One thing that can work really well is to make the textureTime affected by particle age. In general it is best to use the spaceTime texture for this, as it does not have any directional bias in its animation. (note for a puffy look, don’t use billow.. use spacetime or perlin with inflection on.. much faster)

At any rate the key is that you can use particleSamplerInfo per-particle values to drive any of the shading attribute in the fluid.

One other point on this.. it is generally best when doing this to have no dynamic grids on the fluid( i.e. totally procedural density) as the effect of grids would be repeated for each particle.

Also for best shading you will probably wish to soften the edges of the fluid volume by making the edgeDropoff shape a sphere. Otherwise density of the fluid cube( beyond the spherical particle bounds ) will affect self shadowing of the fluid.

```
Duncan

```

---

<div class="post-metadata">

### Author: ![jtk77](https://forum.highend3d.com/user_avatar/forum.highend3d.com/jtk77/32/54731_2.png) [@jtk77](https://forum.highend3d.com/u/jtk77)
#### Post date: [February 5, 2004, 10:57pm UTC](https://forum.highend3d.com/t/duncan-help-fluid-as-a-shader/41491/4 "2004-02-05T22:57:39Z")

</div>

spaceTime eh ?  
Wow, I hadn’t thought of doing it that way. I was trying to puzzel this one out myself.  
Thanks Duncan.

---

<div class="post-metadata">

### Author: ![\-rfk-](https://forum.highend3d.com/letter_avatar_proxy/v4/letter/-/2acd7d/32.png) [@\-rfk-](https://forum.highend3d.com/u/-rfk-)
#### Post date: [February 16, 2004, 6:48pm UTC](https://forum.highend3d.com/t/duncan-help-fluid-as-a-shader/41491/5 "2004-02-16T18:48:45Z")

</div>

Duncan wrote: At any rate the key is that you can use particleSamplerInfo per-particle values to drive any of the shading attribute in the fluid. Can anyone explain in more detail what to connect, e.g. colors, I try to connect normalized age to color input, but the colours do not render color/age, same with opacity. What is the proper method to get most out of fluidShape as a particle shader, textures etc. this is not documented very clearly.

---

<div class="post-metadata">

### Author: ![duncanbrinsmead](https://forum.highend3d.com/user_avatar/forum.highend3d.com/duncanbrinsmead/32/395_2.png) [@duncanbrinsmead](https://forum.highend3d.com/u/duncanbrinsmead)
#### Post date: [February 16, 2004, 8:29pm UTC](https://forum.highend3d.com/t/duncan-help-fluid-as-a-shader/41491/6 "2004-02-16T20:29:55Z")

</div>

ColorInput is an attribute that controls which source is the input to the color ramp..density, gradients, etc. I don’t think you want to drive that attribute. There are a variety of ways one could control color. First make sure that your particles are not set to “live forever” if you want to use ageNormalized. You could set the color of the ramp indices in an expression based on ageNormalized. Or if you wish to drive the lookup to a ramp using age you could connect ageNormalized to a ramptexture vCoord then connect the ramp outColor to the color index on the fluid color ramp (fluidShape.Color[0].Color\_Color.. in the connection editor expand Color and Color[0] )

You don’t need to use a ramp texture, however. To drive the built in ramp color attribute on the fluid you can connect the ageNormalized to the colorInputBias. Now if the defined colorInput is 1 the bias will do nothing, so you want to have an input of 0.5. To do this make the colorInput = density, make the density a constant gradient and set the density scale to 0.5. The varying bias will now cause the color to vary between the midpoint of the color ramp and the right side. If you wanted to use the entire ramp you would have to first remap the normalized age to -1 to 1 (the range used by the bias attribute).

As a rule of thumb look at the fluid in shaded mode and edit the particular attribute to see if modulating the value creates the desired effect. If it does, then connect the particle sampler attributes to drive the attribute.

Keep in mind that you can connect to and drive not only the slider type attributes, but also the ramp indices. You can connect to the index color (value for opacity) as well as the left to right position of the index. The flexibility is quite enormous given all the fluid attributes you can drive, although it takes a while to figure it out. Note that you can only drive shading attributes with sampler info connections, not ones like densityScale( which is only computed once per frame, not per pixel ).  
The fluid attributes you can vary per pixel are all the attributes in the following blocks in the attribute editor:  
Surface  
Shading  
Shading Quality  
Textures  
Lighting

I hope this helps.

Duncan
