需要帮助通过脚本访问和修改Shader Graph的Vector2属性(在Unity中)。

huangapple go评论42阅读模式
英文:

Need help accessing and modifying Shader Graph Vector2 property via script (in Unity)

问题

我想要使用着色器图形构建一个背景层,并且想要添加视差效果。我已经编写了一个脚本来处理所有的数学计算。现在剩下的就是在运行时更改我的一个着色器的 "Vector2 属性"(这将应用我计算出的数学)。

不考虑上下文,我如何通过脚本访问和修改

需要帮助通过脚本访问和修改Shader Graph的Vector2属性(在Unity中)。

?(它是一个 "Vector2")

在Unity文档中,我找到了 "Material.SetFloat",但似乎找不到任何关于Vector2的内容。

英文:

So I'm building a background layer using a shader graph. And I wanna add a parallax effect. I've already wrote a script to do all the math crap. Now all that's left is to change one of my Shaders "Vector2 properties" at runtime (which will apply the math I've calculated).

Context aside, how do I access and modify

需要帮助通过脚本访问和修改Shader Graph的Vector2属性(在Unity中)。

via script?
(It's a "Vector2" btw)

I found "Material.SetFloat" in the Unity Documentation but I can't seem to find anything for a Vector2?

答案1

得分: 1

对于所有的向量,请使用SetVector函数。

它接受一个Vector4(xyzw),但你应该能够传递一个Vector2。

使用属性的名称,就像在着色器图中的“Reference Name”下显示的那样,默认情况下以下划线开头。例如,_MyProperty

myMaterial.SetVector("_MyProperty", myVector2);
英文:

For all vectors, use the SetVector function.

It takes a Vector4 (xyzw), but you should be able to pass it a Vector2.

Use the name of the property as it shows in shader graph under Reference Name, which by default starts with an underscore. eg. _MyProperty.

myMaterial.SetVector("_MyProperty", myVector2);

huangapple
  • 本文由 发表于 2023年5月26日 07:31:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76336804.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定