material instance creation

   2078   3   1
User Avatar
Member
25 posts
Joined: 3月 2016
Offline
I'm having difficulties creating multiple material instances and overriding the textures with the one my HDA creates for every mesh I generate.

No matter what I try I only get one instanced material and it does not set the corresponding texture for it.

I tried using the split attr on the unreal_material_instance attribute but I guess it only works for instanced copy to points geometry? I added a copy to points to see if it would make a difference but sadly it does not.



My current setup;
I am using a TOP network to load in the geometry and textures. I process every workitem with this for the file import
`pdginput(0,"file/geo",0)`
and assign a different material on each iteration which works although I have the feeling I am doing some really hacky things to get the hda to create a different material with textures for each mesh which was also a pain to get working.



I have this python script in my topnetwork to fill the texture paths;
# Executes a Python script, either in process or as a job
#
# The following variables and functions are available in both case:
# work_item
# graph
# intData, floatData, strData,
# intDataArray, floatDataArray, strDataArray
#
# In addition to the above, in-process scripts can also access:
# self         - the current PDG node
# parent_item  - the parent work item, if it exists

import hou
matnetRef = hou.node("../../matnet1")


#children = matnetRef.children()
#if(matnetRef.children()!=0):
#    for n in matnetRef.children():
#        n.destroy(True)
    
pdgInput = parent_item.inputFiles[1]
wedgeindex = work_item.intAttribValue("wedgeindex")



material = hou.node("../../matnet1/principledshader"+str(wedgeindex))
#material.parm("basecolor_useTexture").set(1)
material.parm("basecolor_texture").set(str(pdgInput[0]))

materialName = str(material)

#work_item.setStringAttrib("materialNodeName",materialName)
work_item.addEnvironmentVar("materialNodeName",materialName)

I get a material with textures for every processed mesh but I don't get more than one material instance



I also unsure if this is the right way to go. If anyone has any ideas or could take a look I would very much appreciate some help

Attachments:
object_las_.dev.ProcessInputScans.1.0.hda (1.7 MB)

User Avatar
Member
5 posts
Joined: 9月 2022
Offline
Hello

I have encountered the same problem.
Essentially, we have two options:

- The first option is to create a new material for each new object in the scene for which we would like to apply a material with modified material parameters. However, this approach is not optimal as the material instance was designed for these purposes.
- The second option is to create only one material instance, even though we cannot control its name. What's the point of being able to control the parameters of a material instance if we cannot create more than one instance?

I believe one of the issues stems from the fact that we cannot control the name of the created instance. We have one parameter called "unreal_material_instance" where we can reference our master material. However, the system does not automatically create new instances when it encounters new values for the material instance parameters.

Attachments:
01.png (326.2 KB)
02.png (297.3 KB)
03.png (223.4 KB)

User Avatar
Member
25 posts
Joined: 3月 2016
Offline
However, the system does not automatically create new instances when it encounters new values for the material instance parameters.

Yes that seems to be the problem! I gave up trying to get it working solely using houdini engine. At the moment I am creating the material instances with a python in editor script in unreal after my static meshes have cooked...it's not the "one click solution" I was hoping for but it does work for now
User Avatar
Member
4 posts
Joined: 8月 2020
Offline
I've been struggling with the topic of this thread as well, but the work around is to set random parameter of Material Instance (hereinafter referred to as MI). Imagine, you have 2 packed primitives. You need to set up different MIs of one Master Material. In order to get two different MIs, you should set parameter to a different value, i.e. parameter Roughness. One packed primitive will have value of 0.75, and another one will have 0.76

You can do it with
unreal_material_parameter_roughness
if your MI has parameter with the name of "Roughness". Read about this in the documentation.

Also I found out, that those attributes can be placed inside packed primitives and Unreal will find and read them afterwards
  • Quick Links