I want to split an image into 64x32 squares using a GLSL TOP. Then, I would like to assign a progressive index to these squares, starting from the bottom left and moving to the top right. Finally, I want to project the different sections of the image onto various rectangle instances.
You would start off with a Grid SOP where you set the Rows and Columns paramater to your intended split. The nice thing is that the Grid SOP already comes with texture coordinates we can use to offset the final textures in the instancing by. One slight complication is that these are created as vertex attributes but to have access to them in Instancing, we need to have them as point attributes. So add a Texture SOP and set the Apply to parameter to “Point texture”.
Next create a Rectangle SOP for your instancing, append a Texture SOP to it and set the Scale parameter to 1/cols and 1/rows respectively. With this you make sure that a single rectangle will only use a fraction of the applied texture as defined by your requirements.
Now for the instancing, select whatever operator you want to use for the position of all rectangles and use the SOP that has the adjusted Grid SOPs texture coordinates as the source for the Texture Coord Op also setting the Texture Mode parameter to “Transform”. So now for each instanced rectangle, the texture coordinates are offset by the amount calculated in the grid SOP…
When applying a texture to the geometry, you will see that the texture seems to repeat for one row and column at the top and right of the geometry. To remove this, scale the texture in the Texture SOP appended after the Grid SOP to 1-(1/cols) and 1-(1/rows) respectively.