未定義的 TEXCOORD 數量 (Undefined number of TEXCOORDs)


問題描述

未定義的 TEXCOORD 數量 (Undefined number of TEXCOORDs)

如何聲明一個 TEXCOORD 數組?在不同的結構中,我有:

float2 foo : TEXCOORD0 
float3 bar : TEXCOORD1

現在我需要

float4 Positions[NUMBER_OF_FLOATS]
float3 OtherPositions[NUMBER_OF_FLOATS_2]

我希望這些數組由 TEXCOORD 組成(如果我省略了 TEXCOORD 語義,我會因此而出錯) . 但是不管我怎麼寫,我都會得到一個重複的錯誤,我多次使用 TEXCOORD0 和 TEXCOORD1。

感謝任何幫助。


參考解法

方法 1:

The problem is that the predefined semantics like TEXCOORD have a specific type (seen in doc). So the compiler expects you TEXCOORD to be float vector and not an array of float vectors. Maybe it works with custom semantics, but didn't found any references and never tested it by myself.

I also stumbled over this problematic and solved it (quite ugly) with the preprocessor. In your case it would look like

#if NUMBER_OF_FLOATS > 0
  float4 Position_1 : TEXCOORD0;
#endif
#if NUMBER_OF_FLOATS > 1
  float4 Position_2 : TEXCOORD1;
#endif
#if NUMBER_OF_FLOATS > 2
  float4 Position_3 : TEXCOORD2;
#endif
...

Of course this would need a recompling of the shader if the number changes and your vertex layout must have to fit, but despite it is not the best solution it works for me :)

(by WandererGnietschow)

參考文件

  1. Undefined number of TEXCOORDs (CC BY‑SA 2.5/3.0/4.0)

#hlsl #direct3d






相關問題

如何將幾何著色器與輸出流一起使用? (How do you use Geometry Shader with Output Stream?)

поўнаэкранны квадрат у піксельным шэйдары мае экранныя каардынаты? (fullscreen quad in pixel shader has screen coordinates?)

硬編碼 HLSL 著色器 (Hardcoding HLSL Shader)

GLSL和HLSL之間的模型視圖區別? (Modelview Difference between GLSL and HLSL?)

未定義的 TEXCOORD 數量 (Undefined number of TEXCOORDs)

像素著色器總是返回白色 (Pixel shader always returning white)

GLSL / HLSL 著色器中的星球大戰全息效果 (Star Wars holographic effect in GLSL / HLSL shader)

在 GLSL 中混合多個紋理 (Blending multiple textures in GLSL)

警告 X4000:使用可能未初始化的變量 (warning X4000: use of potentially uninitialized variable)

著色器中的點積與直接向量分量總和性能 (Dot product vs Direct vector components sum performance in shaders)

Unity Compute Shader 中調用 numthreads 和 Dispatch 的區別 (Difference Between Calling numthreads and Dispatch in a Unity Compute Shader)

DirectX 11 曲面細分著色器不工作 (DirectX 11 Tesellation Shader Not Working)







留言討論