OSL Random color 3dsMax

Post, discuss and share handy resources like textures, models and HDRI maps in this forum.
Forum rules
Please do not post any material that is copyrighted or restricted from public use in any way. OTOY NZ LTD and it's forum members are not liable for any copyright infringements on material in this forum. Please contact us if this is the case and we will remove the material in question.
Post Reply
User avatar
paride4331
Octane Guru
Posts: 3809
Joined: Fri Sep 18, 2015 7:19 am

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.
Attachments
randomcolorOSL.rar
(741.67 KiB) Downloaded 412 times
01.jpg
2 x Evga Titan X Hybrid / 3 x Evga RTX 2070 super Hybrid
Rik
Licensed Customer
Posts: 423
Joined: Wed Jul 28, 2010 8:57 pm

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?
Post Reply

Return to “Resources and Sharing”