Can I tweak material graph parameter of a specific scene object?
Hello! I think I could ask this question several different ways. Ultimately, TL/DR: I'm trying to use the same material on multiple scene objects, and I'd like to control the scene objects' opacity independently through a script.
This leads me to several sub-questions:
- Are materials instances on a scene object? It seems like from other posts that they are not but I find this confusing as you can specify the texture per scene object.
- Is there a way I could reference the scene object texture's alpha property through script? I've gotten as far as [Component.Image name].[texture script name] but I'm not sure what would come after that.
- I noticed that the "Default" material has two material-parameters in the image inspector window: "Texture" and "Alpha". Is there a way to achieve this alpha parameter in the image inspector window with a custom material (for clarification, I don't mean in the material inspector window, I mean the image inspector)?
Any guidance on even one of these sub-questions is very much appreciated!
hi Diana G
you can use a Material in multi scenes and if you made a change in that material it will infect all the scenes linked to
to reference the scene object texture's alpha first you need to access the variable of the alpha
by moving the mouse up the alpha and a window will popup like image below
roughness is the variable for that slider im selecting you will have defferent variable name
now you can edit the alpha
in this exemple code ( baseColor ) is the variable
// @input Component.Image image
// @input float alpha = 0.5 {"widget":"slider", "min":0.0, "max":1.0, "step":0.01}
var currColor = script.image.mainPass.baseColor;
script.image.mainPass.baseColor = new vec4( currColor.r, currColor.g, currColor.b, script.alpha );
i hope that help
if you need any help let us know .
cheers
Hi, @...!
1. Are materials instances on a scene object? It seems like from other posts that they are not but I find this confusing as you can specify the texture per scene object.
No they are not .For all custom materials if you modify their settings you will modify all references of a Material. Default Image material is an exception, that's why you can change texture.
To avoid this you can create a copy of material when Lens is initialized and modify the copy.
Sample script might be next :
// do something with material
2. Is there a way I could reference the scene object texture's alpha property through script? I've gotten as far as [Component.Image name].[texture script name] but I'm not sure what would come after that.
Kanz answered this question for you
For a default material alpha is material.mainPass.baseColor.a
Also when you are using Graph Materials you are able to set s scripting name of parameter by yourself
(Please make sure that blend mode on a material is set to Normal to see alpha working)
3. I noticed that the "Default" material has two material-parameters in the image inspector window: "Texture" and "Alpha". Is there a way to achieve this alpha parameter in the image inspector window with a custom material (for clarification, I don't mean in the material inspector window, I mean the image inspector)?
Image Component that uses custom material will show this parameters in the UI if their scripting names match with scripting names of a Default material (baseTex and baseColor). Texture Parameter will show anyway but Alpha parameter can appear in the Image inspector if your material has a BaseColor parameter with a "baseColor" scripting name. The alpha of this color is the alpha
Example:
Hope this helps!
Kanz and Olha, thank you so much! You guys crushed it with your explanations. I had played with naming custom variables but I didn't realized there was some implied behaviors when naming your parameters things like "baseColor" or "baseTex". That's so cool! Also, cloning the material was a game changer.
Thanks guys!