The goal is to create an array of planes that display a rotated texture which depends on the object index of each individual plane multiplied by 90 degrees.

Steps of Issue:

  1. Create one large plane mesh and subdivide
  2. Each subdivision is that separated to create a new object
  3. Use the Shader Editor to insert and connect nodes as shown below enter image description here
  4. The result is that each object has texture that has not been rotated.
  • 1
    $\begingroup$ I think you are mistaken about the meaning of this node. The object index is an information you can use when rendering your scene for the compositing (and in the shader editor with this node), it can manually be set in the object properties > Relations foldout but it doesnt automatically get incremented with each object $\endgroup$
    – Gorgious
    Feb 19 '20 at 18:54
  • $\begingroup$ @Gorgious If this node (or the output) isn't intended for use in a material, then why can it be added to a material? $\endgroup$ Feb 19 '20 at 18:56
  • $\begingroup$ I edited my comment, it can indeed be used in a material, but you actually have to manually update them or use a python script to do so, but to my knowledge there is no way to get the index of creation of each object $\endgroup$
    – Gorgious
    Feb 19 '20 at 18:57
  • $\begingroup$ @Gorgious You're correct in that you have to manually set the index (which you should add as an answer). $\endgroup$ Feb 19 '20 at 19:05
  • $\begingroup$ Alright I figured the (simple) script to do it, I'm writing an answer $\endgroup$
    – Gorgious
    Feb 19 '20 at 19:56

First method (answer to the question)

The object index references the object pass which can be used either in the shader editor to pass information to your material relative to each or different groups of objects, or in the compositor with light passes.

But its purpose is not to get automatically incremented each time you create an object. Thus, you can either manually change their number or use a very simple script to do it automatically.

Open a new workspace of type "Text editor", create a new script with Text > New. Write this (important : You must respect the 4 spaces offset or add a tabulation on the third line else the python interpreter will complain) :

import bpy
for i, obj in enumerate(bpy.context.selected_objects):
    obj.pass_index = i

Then, select all of your plane objects in object mode, and click "Run Script" in the top right corner of your text editor. Voilà ! This method seems to remember the order in which each item of an array has been created so your node network should work.

Important : The mapping node works with radians, so you either have to add a math node set to "To radians" (V2.81+) or type "pi/2" (without the quotation marks and in lower caps) in place of "90"

Second method (exploring the node network)

If what you are trying to achieve is simply to have a plane with regularly places 90° rotated squares, you can achieve that with a single object and a bit of node magic.

  • Add a "Texture Coordinate" node
  • Add a "Vector Math" node set to "Absolute", and connect the object output of the Texture Coordinate node to its input
  • Connect this node to a "Vector Math" node set to "Modulo", and set the second vector to 1,1,1. This will create repeating squares of size 1 in x and y directions.
  • Connect it to a 'Vector Math' node set to 'Add' and set the second vector to '-0.5,-0.5,-0.5'
  • Connect it to a 'Mapping' node's 'Vector' input

  • Add a 'Vector Math' node set to 'Floor' and connect the texture coordinate's object output to its input

  • Connect it to a 'separate XYZ' node
  • Add a 'Math' node set to 'add' and connect both the x and y outputs
  • Connect it to a 'Math' node set to 'Multiply' and write "pi/2" in the second field.
  • Connect it to the 'Z' input of 'Combine XYZ' and connect it to the rotation input of the mapping node.

Voilà ! Scale your plane way up in edit mode. You now have a repeating pattern along X and Y, which rotates with every new square. Example with a "Gradient Texture" set to 'Linear' : enter image description here

No reference to an infamous 4-armed shape intended

Let's go deeper. Let's capitalize on the node flexibility to add a value node which will make the square pattern tweakable.

  • Add a value node
  • Connect it to the bottom socket of the "Divide" node
  • Connect it to bottom socket of the "Modulo" node
  • Connect it to new "Math" node set to 'Divide' by 2
  • Connect this to the second field of a "Math" node set to 'Subtract', with the first one set to 0
  • Finally, connect it to the bottom half of the "Vector Add" node

enter image description here

Result :

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.