問題描述
未定義的 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 Wanderer、Gnietschow)