【问题标题】:Why does the value of a constant affect HLSL shader compilation?为什么常量的值会影响 HLSL 着色器编译?
【发布时间】:2012-06-16 06:38:04
【问题描述】:

我在 XNA4 中有一个效果文件,正在编译为 Shader Model 3。

这一行编译得很好(在 2 种颜色之间插值):

return lerp(float4(1,0,0,1),float4(0,0,1,1),pf.x);

将第一种颜色的绿色分量从 0 更改为 0.5:

return lerp(float4(1,0.5,0,1),float4(0,0,1,1),pf.x);

导致编译失败:

error X6045: When constant registers are read multiple times in a single 
instruction, the _abs modifier must either be present on all of the 
constants, or none of them. 

搜索错误代码不会返回任何内容(编辑:除了这个问题)

【问题讨论】:

  • 哦,它现在确实返回了这个问题;-)
  • 那么你的意思是,在网上发布“谷歌一无所获”只是暂时的吗?
  • 如果您在 SO 上发帖,Google 会在几秒钟后将问题编入索引。我指出这只是一种好奇心,没有理由编辑您的帖子。

标签: xna directx xna-4.0 hlsl


【解决方案1】:

根据documentation,传递给lerp()的所有值都应该是相同的类型和大小,所以也许这会起作用:

return lerp(float4(1,0.5,0,1),float4(0,0,1,1),float4(pf.x,pf.x,pf.x,pf.x));

【讨论】:

  • 你也可以用pf.xxxx代替float4(pf.x,pf.x,pf.x,pf.x)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多