Blender V5.3
eevee_raytrace_shared.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#pragma once
12
14
15#ifndef GPU_SHADER
16namespace blender::eevee {
17#endif
18
24
25 /* Return the depth buffer Z thickness of a pixel at a given view space Z depth. */
27 float avg_pixel_radius_unit,
28 float min_pixel_thickness,
29 float min_constant_thickness)
30 {
32 avg_pixel_radius_unit *= min_pixel_thickness;
33 if (winmat[3][3] == 0.0f) {
34 /* Perspective pixels increase footprint with the distance. */
35 params.thickness_vs_scale = avg_pixel_radius_unit;
36 params.thickness_vs_bias = -min_constant_thickness;
37 params.thickness_ndc_scale = winmat[3][2];
38 params.thickness_ndc_bias = 0.0f;
39 /* Convert from NDC to screen range. */
40 params.thickness_ndc_scale *= 0.5f;
41 }
42 else {
43 /* Orthographic pixels have fixed footprint. */
44 params.thickness_vs_scale = 0.0f;
45 params.thickness_vs_bias = 1.0f; /* Avoid NaN. */
46 params.thickness_ndc_scale = 0.0f;
47 params.thickness_ndc_bias = -(avg_pixel_radius_unit + min_constant_thickness) * winmat[2][2];
48 /* Convert from NDC to screen range. */
49 params.thickness_ndc_bias *= 0.5f;
50 }
51 return params;
52 }
53
54 /* Return the depth buffer Z thickness of a pixel at a given view space Z depth. */
55 float pixel_depth_thickness_at(float vs_z) const
56 {
57 float vs_thickness = vs_z * thickness_vs_scale + thickness_vs_bias;
58 /* NDC offset from view space offset.
59 * From http://terathon.com/gdc07_lengyel.pdf (slide 24) */
60 float ndc_thickness = vs_thickness / (vs_z * (vs_z + vs_thickness));
61 return ndc_thickness * thickness_ndc_scale + thickness_ndc_bias;
62 }
63};
64
107
123
124#ifndef GPU_SHADER
125} // namespace blender::eevee
126#endif
#define host_shared
int32_t bool32_t
unsigned int uint
Definition BKE_text.h:55
MatBase< float, 4, 4 > float4x4
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
struct ScreenThicknessParameters ray_thickness
struct ScreenThicknessParameters fast_gi_thickness
static ScreenThicknessParameters build(float4x4 winmat, float avg_pixel_radius_unit, float min_pixel_thickness, float min_constant_thickness)