Itoo Software Forum

Author Topic: Problem with order of instances returned from IForestGetRenderNodes  (Read 29521 times)

Dali Renderer

  • Newbie
  • *
  • Posts: 4
Hello!

I am using IForestGetRenderNodes() to collect all instances before rendering.
Then for every instance I generate unique name and use that name as a seed for material settings (for example, to apply random tint). This generated name can be used for cryptomatte hash also.
So, having a ForestPack object "WhiteCorals", I send to the renderer "WhiteCorals[0]", "WhiteCorals[1]", "WhiteCorals[2]" and so on.

Problem is that IForestGetRenderNodes() returns different random order of instances each time the scene file is reloaded. I have set number of CPU Threads in the ForestPack settings to 1, without any effect.

Unfortunately, TForestInstance structure does not have any global ID of the instance, so no way to sort instances by ID and keep same order of instances between animation frames.

I could sort instances by coordinates, but this sounds like a bad solution - what if distribution surface is animated?

Could you provide a solution to keep the order of instances constant?

<FP 8.2.6>

Mikhail.

iToo

  • Administrator
  • Hero Member
  • *****
  • Posts: 4589
    • iToo Software
Re: Problem with order of instances returned from IForestGetRenderNodes
« Reply #1 on: July 26, 2024, 04:01:54 PM »
Hello Mikhail,

What is the reason to keep same order of instances between frames ?

I'm afraid there is no way to get that. Because when Forest object is rebuilt, we cannot guarantee that number of instances will be the same.
Items would be hidden because camera clipping or other many parameters. Basically scattering process rebuild everything from scratch on each frame.

I must say this is an unsual request. At least it was not required by other renderers.
If you want to follow this conversation by private, please write us at helpdesk@itoosoft.com.

Thanks,
Carlos Quintero
iToo Software

Dali Renderer

  • Newbie
  • *
  • Posts: 4
Re: Problem with order of instances returned from IForestGetRenderNodes
« Reply #2 on: July 26, 2024, 05:07:11 PM »
For example, at frame #500 I have 10000 corals. Every coral has its own color tint that I calculate in the shader during render-time.
I save the scene, close 3ds max, open scene and re-render frame #500. I see that colors are changed!
This is because that at the first attempt, some instance at <0.1, 0.2, 0.1> was placed at the slot #123, but next time this same instance was placed at slot #567
So its name changed from "WhiteCoral[123]" to "WhiteCoral[567]".
See attached picture - every time I render the shot, I get different colors for corals.

Solution is to make 100+ copies of the same model, assign 100+ different materials and spread all these models in the FP.
The better way is to modify shading in the shader using ID of the instance.

iToo

  • Administrator
  • Hero Member
  • *****
  • Posts: 4589
    • iToo Software
Re: Problem with order of instances returned from IForestGetRenderNodes
« Reply #3 on: July 27, 2024, 08:57:50 AM »
Ok, i understand.

For this purpose, you could use TForestInstance::tintRf, tintRc1 or tintRc2.
These are random values (in the range [0,1]) assigned to the instance, which keep their value between frames.
They are based on a hash from the item's XY position, and used for our plugin ForestColor.

In the same way, TForestInstance::seed is a random value, but in the integer range.

I hope that helps.
Carlos Quintero
iToo Software

Dali Renderer

  • Newbie
  • *
  • Posts: 4
Re: Problem with order of instances returned from IForestGetRenderNodes
« Reply #4 on: July 27, 2024, 12:22:29 PM »
Thank you, I will try this solution.

Mikhail.