GLSL 関数 fwidth(p) は正確には何をしますか?
私はそれが次のように実装されていることを知っています:
fwidth(p) = abs(dfdx(p)) + abs(dfdy(p))
しかし、私はまだそれを手に入れたかどうかわかりません。
ここでは基本的なレイキャスティングを行っており、必要なミップレベルを計算しようとしています。miplevel を見つけるには、レイがボリュームに当たる座標 (テクスチャ空間内) で fwidth を呼び出します。
// get 'derivate width' of sampling position
vec3 width = fwidth(current_position_in_texture_space * size_of_texture);
// get radius around current position in voxels
float range = length(width);
// calculate factor for interpolation (see below)
float factor = range / distance_from_camera_to_current_position;
私の理解では、GLSL はすべてのスレッドを同期し、派生物を上と右の隣のスレッドと計算します。
トラバーサル中、範囲を線形に補間します:
// during traversal
float new_range = distance_from_camera_to_current_position * factor;
// calculate mip level from voxel range
float level = log2(new_range);
// get new sampling stepsize
float stepsize = new_range * 0.5;
これが正しい場合、レベルは現在の位置をサンプリングするために必要なミップ レベルである必要があります。しかし、現在、ボリュームのサンプリング ステップ サイズが大きすぎます...ただし、カメラまでの距離が短くなると減少します。