Unity的Compute Pander是否也可以使用_texelsize后缀?

发布于 2025-02-05 03:35:35 字数 812 浏览 3 评论 0原文

根据 Unity Documentation 在Shader代码中,我们可以获得我们的大小纹理带有{texturename} _texelsize中命名的变量。我在编写计算着色器时尝试但失败了。所以我想知道这是否是因为_texelsize后缀在计算着色器中不起作用?

我尝试的内容如下。

我在计算着色器中定义了以下两个变量

Texture<float4> _MyTexture;
float4 _MyTexture_TexelSize;

,并在C#代码中设置_myTexture,

ComputeShader myComputeShader;
Texture2D myTexture;
// ...
myComputeShader = myComputeShader.SetTexture(0, "_MyTexture", myTexture);

我也尝试更改_MYTEXTURE的类型示例2d,但它不起作用。

我的目标是用_MYTEXTURE使用_MYTEXTURE_TEXELSIZE在阴沉器代码中,而无需在C#代码中设置它。

According to the Unity documentation, in shader code we can get the size of a texture with variables named in {TextureName}_TexelSize. I tried but failed when writing compute shader. So I wonder if it's because the _TexelSize suffix doesn't work in compute shader?

What I've tried is as follows.

I defined the following two variables in my compute shader

Texture<float4> _MyTexture;
float4 _MyTexture_TexelSize;

and set _MyTexture in C# code

ComputeShader myComputeShader;
Texture2D myTexture;
// ...
myComputeShader = myComputeShader.SetTexture(0, "_MyTexture", myTexture);

I've also tried to change the type of _MyTexture to sample2D but it doesn't work.

My goal is to get the size of _MyTexture with _MyTexture_TexelSize in shader code without setting it in C# code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撩动你心 2025-02-12 03:35:35

手动设置值:

myComputeShader.SetVector("_MyTexture_TexelSize", new Vector4(1.0f / myTexture.width, 1.0f / myTexture.height, myTexture.width, myTexture.height));

Set the value manually:

myComputeShader.SetVector("_MyTexture_TexelSize", new Vector4(1.0f / myTexture.width, 1.0f / myTexture.height, myTexture.width, myTexture.height));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文