Home Coding, Scripting, Shaders

Color variation by id shader - [Maya,Arnold]

dlz
dlz
polycounter lvl 4
Offline / Send Message
dlz polycounter lvl 4
I wonder if there’s some way to change the color of the meshes with variation based on the id or influence of another object or other characteristic, but only with one material.
I notice this can be done easily with the colorJitter node in Arnold although it is a random variation and It's good..
but there's a way to control the color more specifically?
I am testing some things in python and with the node editor in Maya but didn't find a way to do it.

Replies

  • poopipe
    Options
    Offline / Send Message
    poopipe grand marshal polycounter
    There's no ID number as such in Maya afaik but you could assign a color or ID  to each shading group and do whatever you need based on that.  
  • dlz
    Options
    Offline / Send Message
    dlz polycounter lvl 4
    i see.. it's strange though that you can control different attributes like color in the same material with randomness but not individually. Iif that makes sense
  • sprunghunt
    Options
    Offline / Send Message
    sprunghunt polycounter
    dlz said:
    i see.. it's strange though that you can control different attributes like color in the same material with randomness but not individually. Iif that makes sense
    If you are using python couldn't you just loop through all the shaders and give each a random color?
  • dlz
    Options
    Offline / Send Message
    dlz polycounter lvl 4
    @sprunghunt yes, that would be really easy with multiple shaders.
    But how would you do this with only one shader? as I commented in the first comment I know the existence of a color jitter node that randomizes the color of the objects by its id, but I didn't know how to control each id or object to assign a specific color.
    Hope that makes sense, thank you for your answers.
  • sprunghunt
    Options
    Offline / Send Message
    sprunghunt polycounter
    dlz said:
    @sprunghunt yes, that would be really easy with multiple shaders.
    But how would you do this with only one shader? as I commented in the first comment I know the existence of a color jitter node that randomizes the color of the objects by its id, but I didn't know how to control each id or object to assign a specific color.
    Hope that makes sense, thank you for your answers.
    One way you could do it is by writing a script that gives each object random vertex colors -  and the shader reads from that. 
  • dlz
    Options
    Offline / Send Message
    dlz polycounter lvl 4
    @sprunghunt I'll try! Thank you again!
  • oglu
    Options
    Offline / Send Message
    oglu polycount lvl 666
    You could also feed in the vertexcolors of a plane. If there is something like a terrain in the scene.
    Depending on how you create your objects.

    Or you could use OSL to hack something together.
    https://www.youtube.com/watch?v=vBZ0WaOl_B8

  • dlz
    Options
    Offline / Send Message
    dlz polycounter lvl 4
    @sprunghunt The vertex color solution works pretty good to control each object and assign specific colors, thanks :)
    @oglu I'll look into that video too! Arvid Schneider is really great in arnold shaders and procedural things

    For everyone interested, this is some code I write :

    import maya.cmds as cmds
    import pymel.core as pm
    cube = cmds.polyCube()
    color= 0.0
    ran = 50

    #Create Shader network
    std = pm.shadingNode('standardSurface', asShader=1)
    dataColor = pm.shadingNode("aiUserDataColor", asShader=1)
    dataColor.attribute.set("colorSet1")
    dataColor.outColor >> std.baseColor

    #loop create cubes with vertex colors and assign shaders
    for i in range(ran+1):
        actualCube = cmds.duplicate(cube[0])
        cmds.move(i*1.1,0,0, actualCube)
        print(color/ran)
        cmds.select(actualCube)
        cmds.polyColorPerVertex( rgb=(1, (color/ran), (color/ran)), cdo =1)
        cmds.setAttr(actualCube[0] + ".aiExportColors", 1)
        color += 1
        pm.hyperShade(assign=std)
    cmds.delete(cube)


    the only problem connecting the vertex color to the color of an Arnold shader is that it messes up the color with the smooth mesh preview, but appart from that its really good and you can always convert the subdivision preview to polygons
  • mihail.lupu
  • dlz
    Options
    Offline / Send Message
    dlz polycounter lvl 4
    @mihail.lupu yes, I know that node but I explain in the first message that I wanted a solution with more control in the variation (to make an increment of the saturation and other things ) the vertex color solution works fine for my purposes.
    Thanks anyways
Sign In or Register to comment.