确定 miplevel 和 fwidth

发布于 2024-11-05 04:51:18 字数 963 浏览 3 评论 0原文

GLSL 函数 fwidth(p) 到底有什么作用?

我知道它的实现方式是:

fwidth(p) = abs(dfdx(p)) + abs(dfdy(p)) 

但我不确定我是否已经得到它。

我在这里做一些基本的光线投射,并尝试计算所需的 miplevel。要找到 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;

如果这是正确的级别,则应该是对当前位置进行采样所需的 mip 级别。但目前采样步长的体积太大……尽管如果与相机的距离减小,采样步长也会减小。

What exactly does the GLSL function fwidth(p) do?

I know that it is implemented as:

fwidth(p) = abs(dfdx(p)) + abs(dfdy(p)) 

but i am not sure if i got it yet.

I am doing some basic raycasting here and try to calculate the miplevel that is required. To find the miplevel is call fwidth on the coordinate where the ray hits the volume (in texture space).

// 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;

In my understanding GLSL will syncronize all threads and calculate the derivates with the top and right neighbour threads.

During the traversal i interpolate range linear:

// 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;

If this is correct level should be the mip level that is required to sample the current position. But currently the volume is sampling step size is to big ... altough it reduces if the distance to the camera is reduced.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

郁金香雨 2024-11-12 04:51:18

你所做的事情有很多问题。

  • 为什么不让 GPU 自己选择正确的 miplevel?只需对步进位置进行采样即可。

  • 您的缩放比例可能是错误的。

  • 让司机认真地为您选择合适的级别。

  • 考虑一下三线性采样的工作原理。然后考虑它如何适用于体积。

  • fwidth 不是确定 miplevel 的正确方法,即使您想要最近的 miplevel。

  • 我是否说过让 GPU 进行 miplevel 选择?

  • fwidth 对于加快或减慢步进很有用

There are many things wrong with what you are doing.

  • Why not let the gpu select the right miplevel itself? Just sample on the stepping position.

  • Your scaling is probably wrong.

  • Let the driver select the right level for you, seriously.

  • Think about how trilinear sampling works. Then think about how it works for volumes.

  • fwidth is not the right way to determine a miplevel, even if you want the nearest one.

  • Did I say let the GPU do the miplevel selection?

  • fwidth is useful for stepping faster or slower

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文