Of course this could be implemented with math nodes but I find it far simpler to write it all down in OSL and condense the logic in a single script node. The result shown below is admittedly not the animation that will get nominated for the next Academy Award but does show nicely the slow settling I had in mind, including the effect that near the end the fluid seems to clear up quicker:
OSL code and node setup
The node is simple enough:shader edgedecay( point Pos = P, float Edge = 0.1, float Power = 1, float Density= 10, float Length = 1 - Edge, output float Fac=Density ){ float h = Pos[2]; if(h>Edge){ float d = (h - Edge)/Length; if(Power > 0 && d < 1){ Fac = Density * ( 1 - pow(d,Power)); }else{ Fac = 0; } } }The node setup for the videoclip is:
The Density input was animated from 2.7 to 3.5 in 100 frames, while at the same time the Power input was animated from 1.0 to 0.0.
The following graph shows the plot of the density profile with relevant parameters:
If you would like to know more about programming OSL you might be interested in my book "Open Shading Language for Blender". More on the availability of this book and a sample can be found on this page.
No comments:
Post a Comment