What exactly does the GLSL fwidth (p) function do?
I know that it is implemented as:
fwidth(p) = abs(dfdx(p)) + abs(dfdy(p))
but I'm not sure if I got it yet.
I am doing some basic raycasting here and trying to figure out the miplevel that is required. To find miplevel is a call to fwidth at 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 synchronizes all threads and computes derivatives with the threads of the upper and right neighbors.
During the traversal, the range interpolation is linear:
float new_range = distance_from_camera_to_current_position * factor;
float level = log2(new_range);
float stepsize = new_range * 0.5;
If this is the correct level, then there must be a mip level needed to select the current position. But at present, the volume is the size of the sampling step to a large ... although it decreases if the distance to the camera decreases.
source
share