Itoo Software Forum

Author Topic: Transform - rotation by vector flow map  (Read 1759 times)

Tomas

  • Newbie
  • *
  • Posts: 11
Transform - rotation by vector flow map
« on: March 30, 2017, 09:16:43 AM »
Hallo,
I would like to rotate geometry around Z axis by vector flow map. The problem is in definition of input data for rotation by one axis. Standart definition of forestpack is in grayscale for one axiz. But the vector  flow map has definition in two R and G colors. Practically forestpack use standard anisotropy map, but I need to load vector flow map to create the same result.
I would like to rotate some hairs by vector flow map, that can be easily painted in many software,. for example - Krita knows it. But there is a problem to find a software that knows to paint anisotropy map in grayscale that needs to be used for forestpack.
So there are two ways to solve my problem.
1) add a function to use a vector flow map definition for transform operations in forest pack OR
2) somehow convert my vector flow map in to gray-scale standart anisotropy map.

easily saying, I need to do some mathematical operation on attached vector flow map to get as same result as attached anisotropy map.Both of standards have ability to define angle from 0-360 angle by color as you can see. So both images have the same information, but written in different definition.
Thanks for any help.
Tomas.


Paul Roberts

  • iToo Software
  • Hero Member
  • *****
  • Posts: 1593
Re: Transform - rotation by vector flow map
« Reply #1 on: March 31, 2017, 11:31:52 AM »
Hi,

Thanks for contacting us with this question. I've been able to solve this using a Forest Effect. As I understand it Flow maps define a 2D vector with the Red channel for the X axis and the Green for the Y. Using this information we can write a simple expression to work out the vector direction and rotate the FP object to match. It's just a couple of lines:

vector v = [fpItem.tintColor.x-0.5, fpItem.tintColor.y-0.5,0];
fpItem.rotation.z = atan2(v.x, v.y);

I've also added an offset value, so that you can edit the rotation relative to the flow map and the ability to add some randomisation too. The final expression after these changes looks like this:

vector v = [fpItem.tintColor.x-0.5, fpItem.tintColor.y-0.5,0];
fpItem.rotation.z = atan2(v.x, v.y)+degToRad(RotationOffset)+randomReal(-RandomRotation,RandomRotation);

Attached to this post is a sample scene file and an effects file that you can load and use without needing to enter the script. To do this:

1 - Add the flow map to the Forest object's Get Color from Map map slot. You can find this in the Material rollout. Make sure that Gamma is set to 1.0
2 - Turn on As Texture.



3 - Go to the Effects rollout and click the Edit Effect button.
4 - Click Import and load the supplied .eff file.
5 - Click OK

Your scattered objects should now rotate to follow the flow map.



I hope that helps, please let me know if you have any further questions.

Many Thanks,

Paul
Paul Roberts
iToo Software

Tomas

  • Newbie
  • *
  • Posts: 11
Re: Transform - rotation by vector flow map
« Reply #2 on: April 10, 2017, 03:24:48 PM »
Wow! I didn't know that Forest has an option of smart scripting! This works for me very well. Still testing it on my workflow, but all seems better than I have expected. Thank you very much!

Tomas

  • Newbie
  • *
  • Posts: 11
Re: Transform - rotation by vector flow map
« Reply #3 on: April 11, 2017, 11:03:16 AM »
Hallo again :)
Could I pleas to modify the script to work in UV mode?
There are a plane and head model in my scene and one forest pack modifier that uses plane and head as surface. The distribution has to be in UV mode because I need to distribute hairs along UV space with 0 direction in Normal.
As you can see it works only on plane, but in 3D space of head is not working properly. First picter shows setup without script and scend one with script. I do not understand why is not working properly, because the script should rotate only along Z axis and it is doing it but the result is mishmash. When I turn Of the script and manually rotate the object unter transformation - rotation Z, hairs rotate properly in right space.


here is a scene: (Max 2017, FP 5.2)
https://www.dropbox.com/s/t69qr8pcrh84cx4/None_V01_FP_Hair_02.zip?dl=0
Thank You.
Tomas

« Last Edit: April 11, 2017, 10:04:03 PM by IN4553 »

Paul Roberts

  • iToo Software
  • Hero Member
  • *****
  • Posts: 1593
Re: Transform - rotation by vector flow map
« Reply #4 on: April 11, 2017, 07:02:18 PM »
Hi,

You're right, rotations in FP are complex and this script doesn't work well on 3d surfaces. Instead I've tried another approach and created a Substance that converts the flow map to a rotation map that can be used with the random rotation controls. If you have Substance Designer and this solution is of interest, please let me know and I'll clean up and upload the files.


I'll continue to see if I can solve this by modifying the script as well.

All the best,

Paul
Paul Roberts
iToo Software

Tomas

  • Newbie
  • *
  • Posts: 11
Re: Transform - rotation by vector flow map
« Reply #5 on: April 11, 2017, 10:00:12 PM »
Hmmmm, this looks interesting!
I actually still wonder if would be better to convert vector flow map to rotation map or use vector flow map as it is. My workflow of this project is still in progress so I do not know if substance will help me or not unfortunately.
The advantage of rotation map is in possibilities to use it also as anisotropy map as it is - Vray works with B/W format.
So Yes, I am interested to see your workflow in Substance Designer. I'd be pleased if you can leave here a files.
Thank you for a help.


Paul Roberts

  • iToo Software
  • Hero Member
  • *****
  • Posts: 1593
Re: Transform - rotation by vector flow map
« Reply #6 on: April 13, 2017, 06:57:19 PM »
Hi,

Please find attached the substance files I created to try and convert a Flow map to a FP map. At the moment these don't seem to work in 3DS Max's substance loader, so you'd need to convert your bitmaps in Substance designer. Once you've done that though it's a simple case of applying them to the Transform > Rotation > Z control by map slot and edit the Min/Max values to get the results you need.

I hope that helps, please let me know if you have any further questions. I'd be interested to know how you get on because I think there's interesting potential in creating maps with Substance Designer to work with Forest Pack.

Many Thanks,

Paul
Paul Roberts
iToo Software

Tomas

  • Newbie
  • *
  • Posts: 11
Re: Transform - rotation by vector flow map
« Reply #7 on: April 14, 2017, 12:36:53 AM »
Hallo Paul
Thank you for files. Just opened them in substance designer and watching your nodes now. Thanks for a help.
I probably will try to convert your result to perpendicular vector field if you understand (the cone area in my flow map should be exact same as original anisotropic map in the top of this thred) but give me a time :) I hope I will find a solution now myself.
Tomas.
 Just realized that, If I switch the input in to Vector Float node, that rotate the vector to perpendicular direction. So solved.
Hm....but I will wonder If I can rotate whole vector field by any constant  angle, not only by 90 degree.
« Last Edit: April 14, 2017, 01:01:58 AM by IN4553 »

Tomas

  • Newbie
  • *
  • Posts: 11
Re: Transform - rotation by vector flow map
« Reply #8 on: April 18, 2017, 10:17:56 PM »
Hi,
after a while of testing I am not sure if this method can work. I am very confused from results.
I converted the vector flow map in to B/W format.
I changed the FP option to UV as picture shows.
On the 2D plane object, everything works great. Te see the scattering better, I have used green arrow object to see the vector field on the 2D plane. Is is not a bad idea to make a printscreen of this 2D plane and use it as a diffuse texture for my 3D Head model. After this I could see on my head the vector field from texture - this was just a "safe" step to see if the vector field was painted right and all UVW seems are right.
So, I have applied the 3D head as a surface but the arrows don't follow the vector field. I tried to rotate the arrows to every directions but it is not working anyway.
 The red FP arrows should be in same directions as green arrows in the diffuse texture.
I really don't know how FP works with this. I thought that FP rotates the object around Z axis in UVW space of the object, but it seems to me there has to be something more.
Can be done something to correct this? Is possible to make this working or is this completely wrong idea?

Here is a scene:

https://www.sugarsync.com/pf/D7185189_06313296_9324323




« Last Edit: April 19, 2017, 01:54:07 AM by IN4553 »

Tomas

  • Newbie
  • *
  • Posts: 11
Re: Transform - rotation by vector flow map
« Reply #9 on: April 19, 2017, 10:33:33 AM »
ok, I do not understand why is working with this:
I wanted to change your vector to perpendicular type because this seemed to me is better for my hairs. So I have switched the inputs in vector node in substance. It worked on plane object but not on 3D head. When I returned back to your original substance pipe ( not switched format ), it is working properly.

I still do not understand why this affects the result.
I still have to do some anisotropic reflection test to finish my workflow.
Anyway thanks for great help to solve this task!


Paul Roberts

  • iToo Software
  • Hero Member
  • *****
  • Posts: 1593
Re: Transform - rotation by vector flow map
« Reply #10 on: April 19, 2017, 12:13:39 PM »
Hi, I'm glad it's working for you now. I guess the substance is sensitive to change because it uses the colour information to calculate a vector direction using and expressions with ATAN2. Depending on what is being changed the vectors could become incorrectly aligned.

Anyway, I'm glad you have it working now. I'd be interested to see how you develop this workflow and know a little more about the project if you're able to share. We're always interested in unusual uses for our tools.

All the best,

Paul
Paul Roberts
iToo Software