Showing posts with label volume VOP. Show all posts
Showing posts with label volume VOP. Show all posts

Tuesday, 13 March 2018

simple vector field avoidance

based on this vid's ideas...
https://www.youtube.com/watch?v=MWJ0E1Rdoiw

As an example case: You have a grid space with some cylinders scattered about. On the X side of the grid space you have a bunch of particles being emitted. We want the particles to flow through the space avoiding said cylinders.


  • We make a Volume that encompasses the whole area in question. We give it a vector value and name it Vel. For velocity.
  • We make a volume VOP. The volume we just made goes into input 1. The cylinders go into input 2.
  • Inside the VOP we make a constant vector value of (1,0,0). This is the direction we want the particles to go in. That's X.
  • We make an XYZdist node and plug our Position and Input 2 bits in. We're getting the distance to the nearest faces with this.
  • We want the Normal attribute of the faces. To get this, add a Primitive Attribute node. Plug in the relevant parts from XYZdist. Remember to feed in Input 2, for the "file" input. Change the attribute to N. We now have the Normal. Add a Normalize node to keep the maths clean.
  • Do a cross product between the constant X and our normalized Normal. Normalize this too.
  • Do another cross product between the normalized cross product and our normalized normal. This is a bit fiddly, but it's all about 90 degree angles and getting to what we want.
  • Normalize the result and plug it into a Bind Export with the attribute named Vel.

We now have the basis of a vector field.
However it'd be nice to use the distance from the cylinders as a blending function. So if you're in a bit of the field not close to a cylinder, you'd just go on about your way.. Only as you got closer would you be affected. To do this............

  • Go back into the VOP. Connect the Dist output from the XYZdist node into a Fit Range Node.
  • Promote the Source Maximum input. We'll set this later outside of the VOP.
  • Plug the output of the Fit Range into a Ramp parameter. Set the ramp to a linear type.
  • The output of the ramp can go into the Bias input of a Mix node.
  • Constant X goes into input A of the Mix. The normalized result of the 2 crossproducts goes into input B. The output of the Mix can now be plugged into the Bind Export we made before.
Outside of the VOP we need to reverse the ramp parameter so that at 0 (ie. very close to the cylinder) we have maximum effect (ie. a value of 1). And at 1 (ie. further away from the cylinders) we have a value of 0. The Maximum distance could be anything depending on scene size. Try 10 & then work up or down. 

Finally.. this can be used in a POP network now, to override a particle system's velocity!