2012-11-09 40 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