Blender V5.3
eevee_surf_occupancy.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2017-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
32#pragma once
33
38
39namespace eevee {
40
48
49/* Note: All fragments need to be invoked even if we write to the depth buffer.
50 * So not early fragment tests. */
53 [[resource_table]] const Uniform &uni,
54 [[resource_table]] const draw::View &views,
55 [[resource_table]] const Sampling &sampling,
56 [[in]] const VertOutCommon &interp,
57 [[front_facing]] const bool front_facing,
58 [[frag_coord]] const float4 frag_co)
59{
60 const ViewMatrices view = views.get(0);
61 int2 texel = int2(frag_co.xy);
62 float vPz = dot(view.forward(), interp.P) - dot(view.forward(), view.position());
63 if (volume_uses_radial_depth(uni)) {
64 vPz = -distance(interp.P, view.position());
65 }
66
67 float offset = sampling.rng_1D_get(SAMPLING_VOLUME_W);
68 float jitter = volume_froxel_jitter(texel, offset) * uni.uniform_buf.volumes.inv_tex_size.z;
69 float volume_z = view_z_to_volume_z(uni, view, vPz) + jitter;
70
71 if (srt.use_fast_method) {
73 volume_z, uni.uniform_buf.volumes.tex_size.z);
74 for (int i = 0; i < imageSize(srt.occupancy_img).z; i++) {
75 /* Negate occupancy bits before XORing so that meshes clipped by the near plane fill the
76 * space between the inner part of the mesh and the near plane.
77 * It doesn't change anything for closed meshes. */
78 occupancy_bits.bits[i] = ~occupancy_bits.bits[i];
79 if (occupancy_bits.bits[i] != 0u) {
80 imageAtomicXor(srt.occupancy_img, int3(texel, i), occupancy_bits.bits[i]);
81 }
82 }
83 }
84 else {
85 if (volume_z > 0.0f) {
86 uint hit_id = imageAtomicAdd(srt.hit_count_img, texel, 1u);
87 if (hit_id < VOLUME_HIT_DEPTH_MAX) {
88 float value = front_facing ? volume_z : -volume_z;
89 imageStore(srt.hit_depth_img, int3(texel, int(hit_id)), float4(value));
90 }
91 }
92 }
93}
94
95} // namespace eevee
#define VOLUME_HIT_DEPTH_SLOT
#define VOLUME_HIT_COUNT_SLOT
#define VOLUME_OCCUPANCY_SLOT
float volume_froxel_jitter(int2 froxel, float offset)
float view_z_to_volume_z(const ViewMatrices view, float depth, float near, float far, float distribution)
bool volume_uses_radial_depth(const eevee::Uniform &uni)
#define texture_atomic
#define image(slot, qualifiers, format)
#define front_facing
#define frag_coord
#define push_constant
#define resource_table
#define fragment
float dot(VecOp< float, D >, VecOp< float, D >) RET
float distance(float, float) RET
IMG_TEMPLATE uint imageAtomicXor(T &, IntCoord, uint) RET
ImageBase< uint, 2, false, true > uimage2DAtomic
IMG_TEMPLATE uint imageAtomicAdd(T &, IntCoord, uint) RET
ImageBase< uint, 3, false, true > uimage3DAtomic
ImageBase< float, 3 > image3D
IMG_TEMPLATE SizeVec imageSize(const T &) RET
IMG_TEMPLATE void imageStore(T &, IntCoord, DataVec)
ccl_device_inline float interp(const float a, const float b, const float t)
Definition math_base.h:549
void surf_occupancy(SurfOccupancy &srt, const Uniform &uni, const draw::View &views, const Sampling &sampling, const VertOutCommon &interp, const bool front_facing, const float4 frag_co)
Bits bits_from_depth(float depth, int bit_count)
float3 forward() const
float3 position() const