Randomizer for Properties of Material Graph Node

Hello,

We are trying the randomize the properties of components of a material Graph as part of the Synthetic data generation process. The Material Graph is created in a way to have additive effect of multiple file_texures. We want to randomize a texture of particular file_texture.

Current Implementation which is not working

    def get_blade_material():
        shape = rep.get.prims(path_pattern='/World/Looks/MachineBlade_Material/base_texture/file_texture')
        with shape:
            rep.modify.attribute('inputs:texture', rep.distribution.choice([
                    'omniverse://localhost/NVIDIA/Materials/vMaterials_2/Ground/textures/aggregate_exposed_diff.jpg',
                    'omniverse://localhost/NVIDIA/Materials/vMaterials_2/Ground/textures/gravel_track_ballast_diff.jpg',
                    'omniverse://localhost/NVIDIA/Materials/vMaterials_2/Ground/textures/gravel_track_ballast_multi_R_rough_G_ao.jpg',
                    'omniverse://localhost/NVIDIA/Materials/vMaterials_2/Ground/textures/rough_gravel_rough.jpg'
                    ]))
    rep.randomizer.register(get_blade_material)

However in the extension we are able to access the component (Material Graph node) of same material graph in the extension we developed and manipulate it’s property using the code below

prims_1 = self.stage.GetPrimAtPath("/World/MachineBlade/MachineBlade_Material/base_texture/file_texture")
prims_1.GetAttribute("inputs:brightness").Set(0)

Requesting help on understanding of configuring Material graph in Replicator

Attaching the USD and the Python script
SDG_Replicator.py (2.5 KB)

Blade_SDG_Scene.zip (12.6 MB)

Hello @Shekhar.L! I’ve shared your post with the dev team for further assistance.

Hi @Shekhar.L

Here’s a working example I’ve set up that randomizes textures in a material created using the material graph:

import omni.replicator.core as rep

prim_path = "/World/Looks/MetalWithDefect/normalmap_texture"
textures = ['./RandomTextures/Dent_01.png', './RandomTextures/Dent_02.png', './RandomTextures/Dent_03.png']

with rep.new_layer():

    def alter_attribute():
        material = rep.get.prims(path_pattern = prim_path)
        with material:
            choice = rep.distribution.choice(textures)
            rep.modify.attribute("inputs:texture", choice)
        return material.node

    rep.randomizer.register(alter_attribute)

    with rep.trigger.on_frame(num_frames=10):
        rep.randomizer.alter_attribute()

This simply assigns a different texture into the normalmap_texture prim. This works with a single material in the scene, randomizing the textures. There wont be any shader recompilation when the prim texture is reassigned. Though there might be a loading delay if the textures aren’t in memory (from what I understand).

Let me know if this helps!