Instancing UV Texture Coordinates

 

Hi Folks.

I'm trying to automagically generate a certain number of 'Cards' and arrange them in 3D in a grid like style.
This works quite well with instancing nodes and a basic Dupliator script I hacked together.


Now I want to shift the UV Coordinates on each Card so that every instance uses a different area of the incoming Texture which looks like this:


I tried various approaches but couldn't find a way to 'Instance' a shift of UV Coordinates.
Given all the cool features of Aximmetry I sense that it should be possible and that I just haven't found the right solution yet.
Any help would be much appreciated.


Cheers & all the best.

(BTW....would be cool if one could upload .zip files, so I could share my xcomp and script...:-))

   EricWest

 
Profile Image
EricWest
  -  

PS: Using a ShaderArray as described in one of the instancing tutorials is no option, since it maxes out at 8 shaders.
In our case we're facing somewhat between 12 and 36 Cards/Textures though....

 
Profile Image
EricWest
  -  

PPS: I think the coolest way would be if the Serial Instancer would sport a vec2 input for UV Coordinates, similar to the vec3 positions input.


 
Profile Image
EricWest
  -  

Talking to myself here...:-)

Pretty much everything on the overall setup works.
Just that UV mapping offset is a total showstopper....there has to be a way to handle this...

 
Profile Image
Eifert@Aximmetry
  -  

Hi Eric,

If you are only instancing 24 objects I would suggest using an Array compound instead of instancing.
If you need the extra rendering power of instancing cause you are instancing thousands of objects, then you can make your own shader to receive the 'instanced' UV coordinates. This solution will make things a bit less flexible to control in the flow editor.


The Array compound solution:
First, you make an Array compound from a simple compound using the Setup Array option:Set how big array should be: (should be the same as the number of times you want to create the geometry)


Then in the Array compound, you are free to set the UV coordinate (Tex Coord Transf).
In the example below, the UV x coordinate will be offset based on the Array Index module: (Array Index module's value incremented by 1 at every step of the array, so it will be integer numbers from 1 to 24 for each of your geometry)

Connect the Array compound to your Scene:



The shader solution:

You open a shader that you wish to use by double-clicking on it:

In the shader you open the Vertex compound:

You add the following input pin and modules to modify the Tex Coords 1:

Save the modified shader. (File->Save as...)

Add the new shader to your xcomp and use it with the Serial Instancer and Instanced Node modules:

Note that a new "UV Vector XC" input pin appeared on the modified shader, this is the pin we previously connected out in the shader. To this new input pin, you will have to connect the UV coordinates in a vector. This vector should have 2 times the amount geometry items (since the "UV Vector XC" input pin vector has two items). In the case 24 geometry that will mean a vector with 48 items. There is a Vector Size module to check how many items you have in a vector.
The amount geometry the Serial Instancer instances is based on how many vector items you gave to its Positions input pin. Since one Position is 3 vector items, 24 geometry will require 72 (3x24) items in the vector.

Warmest regards,

 
Profile Image
EricWest
  -  

Hi Eifert.

Wow! What a fantastic support! Just plain awesome!

Thanks a bunch for your in depth explanations.
I will give this a go right away.

Cheers.

Eric.

 
Profile Image
EricWest
  -  

Hi there.

Revisiting the array method, this would also be a great way to generate stuff like e.g. a bargraph display made out of (say) rectangles.

However, once I set the array size of the compound, this is a fixed value which then generates that exact amount of rectangles 
and can't be altered dynamically.

So if I want to display 6 rectangles to indicate 60% on that bargraph, how would I do that inside an array compound with a fixed size of 10?

Apparently I'm missing some vital idea here...:-)

Cheers.

Eric.


 
Profile Image
Eifert@Aximmetry
  -  

Hi Eric,

You will have to connect the limit into the array compound, like:

Note, you don't have to worry much about the extra executions.
If the Force Both is Off in the If module, then only the modules behind the selected Then or Else will be executed.

If Force Both is On, then the connected modules behind both Then and Else input pins will be executed.

Warmest regards,

 
Profile Image
EricWest
  -  

Hi Eifert.

Ah! Brilliant! Thanks!

I found though that your above flow is missing one connection to make it actually work ... :-)

Cheers.

Eric