Skip to content

Commit 3aca5bc

Browse files
committed
--amend
1 parent 55f49a1 commit 3aca5bc

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

servers/rendering/renderer_rd/shaders/raymarch_inc.glsl

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,24 +262,93 @@ bool hybrid_root_finder_find_root(
262262
}
263263

264264
struct DepthRayMarchResult {
265+
/// True if the raymarch hit something.
265266
bool hit;
267+
268+
/// In case of a hit, the normalized distance to it.
269+
///
270+
/// In case of a miss, the furthest the ray managed to travel, which could either be
271+
/// exceeding the max range, or getting behind a surface further than the depth thickness.
272+
///
273+
/// Range: `0..=1` as a lerp factor over `ray_start_cs..=ray_end_cs`.
266274
float hit_t;
275+
276+
/// UV corresponding to `hit_t`.
267277
vec2 hit_uv;
278+
279+
/// The distance that the hit point penetrates into the hit surface.
280+
/// Will normally be non-zero due to limited precision of the ray march.
281+
///
282+
/// In case of a miss: undefined.
268283
float hit_penetration;
284+
285+
/// Ditto, within the range `0..DepthRayMarch::depth_thickness_linear_z`
286+
///
287+
/// In case of a miss: undefined.
269288
float hit_penetration_frac;
270289
};
271290

272291
struct DepthRayMarch {
292+
/// Number of steps to be taken at regular intervals to find an initial intersection.
293+
/// Must not be zero.
273294
uint linear_steps;
295+
296+
/// Exponent to be applied in the linear part of the march.
297+
///
298+
/// A value of 1.0 will result in equidistant steps, and higher values will compress
299+
/// the earlier steps, and expand the later ones. This might be desirable in order
300+
/// to get more detail close to objects in SSR or SSGI.
301+
///
302+
/// For optimal performance, this should be a small compile-time unsigned integer,
303+
/// such as 1 or 2.
274304
float linear_march_exponent;
305+
306+
/// Number of steps in a bisection (binary search) to perform once the linear search
307+
/// has found an intersection. Helps narrow down the hit, increasing the chance of
308+
/// the secant method finding an accurate hit point.
309+
///
310+
/// Useful when sampling color, e.g. SSR or SSGI, but pointless for contact shadows.
275311
uint bisection_steps;
312+
313+
/// Approximate the root position using the secant method -- by solving for line-line
314+
/// intersection between the ray approach rate and the surface gradient.
315+
///
316+
/// Useful when sampling color, e.g. SSR or SSGI, but pointless for contact shadows.
276317
bool use_secant;
318+
319+
/// Jitter to apply to the first step of the linear search; 0..=1 range, mapping
320+
/// to the extent of a single linear step in the first phase of the search.
321+
/// Use 1.0 if you don't want jitter.
277322
float jitter;
323+
324+
/// Clip space coordinates (w=1) of the ray.
278325
vec3 ray_start_cs;
279326
vec3 ray_end_cs;
327+
328+
/// Should be used for contact shadows, but not for any color bounce, e.g. SSR.
329+
///
330+
/// For SSR etc. this can easily create leaks, but with contact shadows it allows the rays
331+
/// to pass over invalid occlusions (due to thickness), and find potentially valid ones ahead.
332+
///
333+
/// Note that this will cause the linear search to potentially miss surfaces,
334+
/// because when the ray overshoots and ends up penetrating a surface further than
335+
/// `depth_thickness_linear_z`, the ray marcher will just carry on.
336+
///
337+
/// For this reason, this may require a lot of samples, or high depth thickness,
338+
/// so that `depth_thickness_linear_z >= world space ray length / linear_steps`.
280339
bool march_behind_surfaces;
340+
341+
/// If `true`, the ray marcher only performs nearest lookups of the depth buffer,
342+
/// resulting in aliasing and false occlusion when marching tiny detail.
343+
/// It should work fine for longer traces with fewer rays though.
281344
bool use_sloppy_march;
345+
346+
/// When marching the depth buffer, we only have 2.5D information, and don't know how
347+
/// thick surfaces are. We shall assume that the depth buffer fragments are little squares
348+
/// with a constant thickness defined by this parameter.
282349
float depth_thickness_linear_z;
350+
351+
/// Size of the depth buffer we're marching in, in pixels.
283352
vec2 depth_tex_size;
284353
};
285354

0 commit comments

Comments
 (0)