Page 1 of 1

OSL Random color 3dsMax

PostPosted: Tue May 15, 2018 8:27 am
by paride4331
The Octane 'Random color texture' may depend on the number and order of objects using it.
(For example, using movable proxy on instance objects)
In this case, when hiding or deleting some of the objects, the other objects will change color.

To keep a constant random color per object, a simple OSL texture can be used to produce random color depending on the object User ID.

First, set some unique user ID to each object:
-Select all objects to use your random material
-Open the Octane object properties dialog
-Set 'start' to 0
-In the tool button '...', select 'Set selected IDs from selection order'

Then, use the RandomGreyInstance.osl as a texture, or copy the code below:

Code: Select all
#include <octane-oslintrin.h>
shader randomColorGreyFromInstance(
    int seedI = 0 [[string label = "Seed"]],
    output color c = 0)
{
    float noiseOut = noise("cell", (float)(_getinstanceid() + seedI));
    c = color(noiseOut, noiseOut, noiseOut);
}

That gives a random grey color for each object. see sample randomColorFromUserID.max

This can then be used as the input of a Gradient texture, to select your colors.

Re: OSL Random color 3dsMax

PostPosted: Tue May 15, 2018 10:14 am
by Rik
Thanks Paride, that's great (appreciate the release 14 max file too)

Is it possible to apply the user id randomly to elements - such as leaves on a tree mesh?

Or would you need to keep thousands of instanced leaves plus trunk/branches as separate meshes but lumped together as a group?