Quantcast
Channel: Questions in topic: "shader programming"
Viewing all articles
Browse latest Browse all 169

Is there a way to save global shader variables?

$
0
0
Is there a good way to save global shader variables/properties? I've got several different shaders which are supposed to all share the same variable, and I want the player to be able to change this value whenever they want. Right now I'm controlling this with a C# script and using the Shader.SetGlobalInt function to set the variable, and this *does* largely work, however, every time I exit Unity, the global variable isn't saved and resets to zero next time I open, and this is particularly annoying for this set of shaders specifically because a value of zero makes things invisible. If I press play, the objects will become visible again and remain visible after exiting play mode (this is because Shader.SetGlobalInt will be used to correct the global variable in a start function on an empty game object), however, it's still rather annoying and I feel like there's probably a better way to do this. Something I've noticed in writing shaders is that there are some built-in adjustable variables which can be used by shader code like unity_FogStart or unity_FogEnd. I think that ideally I'd want to be able to simply create a new custom variable like those which doesn't rely on any game object if that's possible. Generally I just want to know what'd be the best way to go about this sort of problem. Thanks in advance!

Viewing all articles
Browse latest Browse all 169

Trending Articles