Set RenderAttributes ShaderGraph

Started by Brotcrunsher · one year ago · 3 replies · 189 views

#1
Brotcrunsher
Member
JoinedJan 2023 Posts2 Score1,678
Heya everyone!

The ShaderGraph variables page states:
If a Constant has "Is Attribute" set to true, then the value will not be exposed in the Material Editor and will instead be accessible via RenderAttributes in code.
I created a variable called "Wobbly" which has clearly noticeable effects when I modify the value within the ShaderGraph itself - so the Variable itself does "work". When trying to set the same variable from my C# code however, I see no effect. I tried these two approaches:

var mat = GetComponent<ModelRenderer>().GetMaterial();
mat.Attributes.Set( "Wobbly", 100.0f ); // (1)
mat.Set( "Wobbly", 10.0f ); // (2)
Log.Info( mat.Attributes.GetFloat( "Wobbly" ) ); // (3)
Both (1) and (2) seem to have no effect. I notices however, that (2) does return false which I assume means that something went wrong. (3) does print 100, so (1) seems to at least have done "something", but it doesn't actually change the visuals of my shader.

For completeness sake, here are the settings from by Wobbly Variable within the Shader Graph:

Any help would be much appreciated!

Cheers!
#2
thekronn0s
Member
JoinedAug 2021 Posts2 Score20
Try Attributes from ModelRenderer.SceneObject
#3
Brotcrunsher
Member
JoinedJan 2023 Posts2 Score1,678
That did indeed change the appearance! However, it's not exactly what I was hoping for. It changes the attribute for every instance of the material in the whole scene (as the name already implies). I was hoping to just change the material of one instance. Is there a way to do that?
#4
Braxen 🐟
Member
JoinedJun 2021 Posts189 Score190
You have to disable batching on the scene object 
people
Log in to reply
You can't reply if you're not logged in. That would be crazy.