42 float3 t_mins = (aabb_min - ray_origin) / ray_direction;
43 float3 t_maxs = (aabb_max - ray_origin) / ray_direction;
68 bool is_persp = (view.
winmat[3][3] == 0.0f);
70 pixel_size *=
max(0.01f, linear_depth);
84 float3 near_center = vs_near_plane + vs_view_direction * near_t;
87 float3 far_center = vs_near_plane + vs_view_direction * far_t;
89 sphere_center =
mix(near_center, far_center, 0.5f);
92 for (
int x = -1;
x <= 1;
x += 2) {
93 for (
int y = -1;
y <= 1;
y += 2) {
94 float3 near_corner = near_center + (near_pixel_size * 0.5f *
float3(
x,
y, 0));
97 float3 far_corner = far_center + (far_pixel_size * 0.5f *
float3(
x,
y, 0));
103 sphere_radius =
sqrt(sphere_radius);
115 inflate_scale *= -vP.
z;
118 inflate_scale *= 0.5f;
120 float3 ws_inflate_vector = obj.normal_object_to_world(
sign(lP - ls_center));
121 float3 vs_inflate_vector = view.normal_world_to_view(ws_inflate_vector);
122 vs_inflate_vector.
z = 0;
125 vs_inflate_vector *= inflate_scale;
127 vP += vs_inflate_vector;
146 [[
vertex_id]] [[maybe_unused]]
const int vert_id,
151 draw::ID id = res_id.get(inst_index);
152 uint resource_id =
id.resource_id<1>();
159 v_out.ls_aabb_min =
float3(0.0);
160 v_out.ls_aabb_max =
float3(0.0);
161 v_out.resource_id = resource_id;
184 for (
int i = 0; i < 8; i++) {
187 srt.inflate_bounds(view, obj, ls_center,
P, lP);
189 ls_conservative_min =
min(ls_conservative_min, lP);
190 ls_conservative_max =
max(ls_conservative_max, lP);
193 v_out.ls_aabb_min = ls_conservative_min;
194 v_out.ls_aabb_max = ls_conservative_max;
207 ls_conservative_min + (ls_conservative_max - ls_conservative_min) *
float3(1, 0, 0),
208 ls_conservative_min + (ls_conservative_max - ls_conservative_min) *
float3(0, 1, 0),
209 ls_conservative_min + (ls_conservative_max - ls_conservative_min) *
float3(0, 0, 1));
210 for (
int i = 0; i < 8; i++) {
230 float2 screen_uv = frag_co.xy /
float2(srt.fb_resolution);
245 float ls_near_box_t = srt.ray_aabb(
246 ls_near_plane, ls_view_direction,
interp.ls_aabb_min,
interp.ls_aabb_max);
248 if (ls_near_box_t < 0.0f) {
253 float3 ls_near_box = ls_near_plane + ls_view_direction * ls_near_box_t;
256 float near_box_t =
distance(ws_near_plane, ws_near_box);
259 far_box_t =
min(far_box_t,
distance(ws_near_plane, ws_opaque));
265 for (
float t = near_box_t; t <= far_box_t; t =
max(t + step_size,
nextafter(t))) {
267 t =
min(t, far_box_t);
268 step_size = srt.pixel_size_at(view, t);
270 float3 P = ws_near_plane + (ws_view_direction * t);
272 srt.step_bounding_sphere(
273 views.get(0), vs_near_plane, vs_view_direction, t, t + step_size,
P, step_radius);
276 float2 pixel = frag_co.xy *
exp2(
float(srt.fb_lod));
281 .radius = step_radius,
void drw_debug(Box shape, float4 color)
bool drw_bounds_are_valid(ObjectBounds bounds)
Box shape_box(float3 v000, float3 v100, float3 v010, float3 v001)
#define storage(slot, qualifiers)
VecBase< float, D > normalize(VecOp< float, D >) RET
float distance(float, float) RET
VecBase< uint, D > floatBitsToUint(VecOp< float, D >) RET
VecBase< float, D > uintBitsToFloat(VecOp< uint, D >) RET
TEX_TEMPLATE DataVec texelFetch(T, IntCoord, int) RET
int midpoint(int a, int b)
float length_squared(VecT a)
float reduce_min(float2 a)
float reduce_max(float2 a)
ccl_device_inline float interp(const float a, const float b, const float t)
void foreach_visible(const LightRenderData &srt, float2 pixel, float linear_view_z, CallbackT &cb, ResourceT &res)
void tag_usage_vert(TagUsageTransparent &srt, TagUsage &, const int inst_index, const draw::View &views, const draw::Model &models, draw::Resource &res_id, const int vert_id, const VertIn &v_in, VertOut &v_out, float4 &out_position)
float nextafter(float value)
void tag_usage_frag(TagUsageTransparent &srt, const draw::View &views, const draw::Model &models, TagUsage &tag, const HiZ &hiz, const VertOut interp, const float4 frag_co)
PipelineGraphic tag_usage_transparent(usage::tag_usage_vert, usage::tag_usage_frag)
float4 bounding_corners[4]
float3 point_world_to_object(float3 P) const
float3 point_object_to_world(float3 lP) const
bool is_perspective() const
float3 point_world_to_view(float3 P) const
float4 point_world_to_homogenous(float3 P) const
float3 point_screen_to_world(float3 ssP) const
float3 point_view_to_world(float3 vP) const
float3 world_incident_vector(float3 P) const
float3 point_screen_to_view(float3 ssP) const
void inflate_bounds(const ViewMatrices view, const ObjectMatrices obj, float3 ls_center, float3 &P, float3 &lP)
const ObjectBounds(& bounds_buf)[]
float ray_aabb(float3 ray_origin, float3 ray_direction, float3 aabb_min, float3 aabb_max)
void step_bounding_sphere(const ViewMatrices view, float3 vs_near_plane, float3 vs_view_direction, float near_t, float far_t, float3 &sphere_center, float &sphere_radius)
float pixel_size_at(const ViewMatrices view, float linear_depth)