基於圖像的照明,切線空間坐標和優化


5

當我看到一個法線貼圖的實現,該實現在頂點著色器中計算了 TBN矩陣並在該階段將所有內容(尤其是視圖矢量和光照矢量)轉換為切線空間時,正確的做法。這樣,片段著色器中不再需要矩陣向量乘法。

進入基於圖像的照明:對於我們要從圖像中獲取的每個片段,通常是一個或多個立方體貼圖紋理,其光強度來自某些方向。我認為這些數據在世界空間中。

我的問題是:是否可以在保留上述頂點著色器變換優化的同時使用IBL?

  • 在我看來,我們仍然需要將獲取方向從切線空間轉換為世界空間(或立方體貼圖所在的任何空間)。
  • 相反,如果要在世界空間中工作,例如使用延遲著色,則需要為每個片段變換法線。

IBL是否一定意味著每個片段至少有一個矩陣向量相乘,而我提到的優化是一種不常見的情況,還是我錯過了一些東西?

4

Yes, you do need to transform the fetch direction into the space of the cubemap. If you could somehow figure out the fetch direction in the vertex shader, then you could do the transformation there instead, but that would produce worse lighting.

It also may be worth optimizing for a smaller number of interpolants between the vertex and pixel shaders (rather than a smaller number of matrix-vector multiplications in the pixel shader). As soon as you have one transformed view vector and two transformed light vectors that must be interpolated (which would otherwise be constant), you've matched the size of the tangent/bitangent/normal matrix that you would otherwise be interpolating. That has the potential to have more performance impact than doing extra matrix multiplications in the shader.