2012-11-09 73 views
0

根據this nVidia CG tutorial(以及我自己的經驗),訪問具有非常數索引的CG着色器中的統一數組要麼效率不高或者不受支持(通常不支持,似乎不受支持)。非恆定索引到均勻陣列CG着色器

我的問題是;我怎樣才能繞過這個問題?

我正在寫一個GPU皮膚着色器,其中我傳遞了一個骨骼(4x4矩陣)數組,我需要使用存儲在頂點屬性中的索引訪問(具體來說,是一個float4矢量,其組件被投射到整數)。顯然,由於上述限制,這不起作用......也許我錯過了一個更好的方法來做到這一點?

回答

1

這確實是這樣做的常見方式,例如, (這是HLSL,但基本相同 - 請注意全球統一的'boneArray')

float4x3 CalcBoneTransform(float4 blendWeights, float4 boneIndices) 
{ 
    // Calculate normalized fourth bone weight2 
    float4 weights = float4(blendWeights.x, blendWeights.y, blendWeights.z , 1.0f - blendWeights.x - blendWeights.y - blendWeights.z); 
    // Calculate bone transform 
    float4x3 boneTransform; 
    int4 indices = boneIndices; 
    boneTransform = weights.x * boneArray[indices.x]; 
    boneTransform += weights.y * boneArray[indices.y]; 
    boneTransform += weights.z * boneArray[indices.z]; 
    boneTransform += weights.w * boneArray[indices.w]; 
    return boneTransform; 
} 
+0

感謝您的迴應!事實證明,事實上,可以爲我的平臺(Playstation Mobile)做到這一點,但是有一個未記錄的怪癖,這意味着一個單一的統一陣列最多隻能有256個字節(這樣一個由4個4×4矩陣組成的陣列) 。一旦我發現了這一點,這是一個簡單的問題,我的骨頭陣列拆分成256個字節的單個塊。 – DAVco