29 world_sphere_.clipping_distances =
float2(1.0f, 10.0f);
34 world_sphere_.influence_scale = 0.0f;
35 world_sphere_.influence_bias = 1.0f;
36 world_sphere_.parallax_distance = 1e10f;
38 world_sphere_.use_for_render =
true;
63 const SceneEEVEE &sce_eevee = inst_.scene->eevee;
69 auto_bake_enabled_ = inst_.is_viewport() &&
73void LightProbeModule::sync_volume(
const ObjectRef &ob_ref)
91 grid.
view_bias = lightprobe.grid_view_bias;
104 1.0f /
float3(cache_size + 1));
113void LightProbeModule::sync_sphere(
const ObjectRef &ob_ref)
115 SphereProbe &
cube = sphere_map_.lookup_or_add_default(
ObjectKey(ob_ref));
117 if (inst_.get_recalc_flags(ob_ref) != 0 ||
cube.initialized ==
false) {
121 cube.initialized =
true;
123 cube.do_render =
true;
127 int subdivision_lvl = probe_module.subdivision_level_get(probe_resolution);
129 if (
cube.atlas_coord.subdivision_lvl != subdivision_lvl) {
130 cube.atlas_coord.free();
131 cube.atlas_coord = find_empty_atlas_region(subdivision_lvl);
132 SphereProbeData &cube_data = *
static_cast<SphereProbeData *
>(&
cube);
134 cube_data.atlas_coord =
cube.atlas_coord.as_sampling_coord();
136 cube.use_for_render =
false;
140 float influence_distance = light_probe.distinf;
141 float influence_falloff = light_probe.falloff;
142 float parallax_distance = light_probe.distpar;
143 parallax_distance = use_custom_parallax ?
max_ff(parallax_distance, influence_distance) :
146 auto to_eevee_shape = [](
int bl_shape_type) {
149 cube.influence_shape = to_eevee_shape(light_probe.attenuation_type);
150 cube.parallax_shape = to_eevee_shape(use_custom_parallax ? light_probe.parallax_type :
151 light_probe.attenuation_type);
157 cube.influence_scale = 1.0 /
max_ff(1e-8f, influence_falloff);
158 cube.influence_bias =
cube.influence_scale;
159 cube.parallax_distance = parallax_distance / influence_distance;
160 cube.clipping_distances =
float2(light_probe.clipsta, light_probe.clipend);
168void LightProbeModule::sync_planar(
const ObjectRef &ob_ref)
170 PlanarProbe &plane = planar_map_.lookup_or_add_default(
ObjectKey(ob_ref));
172 if (inst_.get_recalc_flags(ob_ref) != 0 || plane.initialized ==
false) {
176 plane.initialized =
true;
177 plane.updated =
true;
178 plane.plane_to_world = ob_ref.object_to_world();
179 plane.plane_to_world.z_axis() =
math::normalize(plane.plane_to_world.z_axis()) *
181 plane.world_to_plane =
math::invert(plane.plane_to_world);
182 plane.clipping_offset = light_probe.clipsta;
184 plane.parallax_distance = light_probe.distpar;
192 switch (lightprobe.type) {
209 world->probe_resolution);
212 int subdivision_lvl = sph_module.subdivision_level_get(probe_resolution);
214 if (subdivision_lvl != world_sphere_.atlas_coord.subdivision_lvl) {
215 world_sphere_.atlas_coord.free();
216 world_sphere_.atlas_coord = find_empty_atlas_region(subdivision_lvl);
218 world_data.
atlas_coord = world_sphere_.atlas_coord.as_sampling_coord();
223 world_sphere_.do_render =
true;
230 volume_update_ =
false;
233 bool remove_grid = !grid.
used;
234 if (grid.
updated || remove_grid) {
235 volume_update_ =
true;
243 sphere_update_ =
false;
246 bool remove_cube = !cube.used;
247 if (cube.updated || remove_cube) {
248 sphere_update_ =
true;
250 cube.updated =
false;
256 planar_update_ =
false;
259 bool remove_plane = !plane.
used;
260 if (plane.
updated || remove_plane) {
261 planar_update_ =
true;
271 int layer_count = sphere_layer_count();
274 location_finder.mark_space_used(world_sphere_.
atlas_coord);
275 for (
const SphereProbe &probe : sphere_map_.values()) {
276 location_finder.mark_space_used(probe.atlas_coord);
278 return location_finder.first_free_spot();
281int LightProbeModule::sphere_layer_count()
const
284 for (
const SphereProbe &probe : sphere_map_.values()) {
285 max_layer =
max_ii(max_layer, probe.atlas_coord.atlas_layer);
287 int layer_count = max_layer + 1;
298 int subdivision_level)
300 subdivision_level_ = subdivision_level;
301 areas_per_dimension_ = 1 << subdivision_level_;
302 areas_per_layer_ =
square_i(areas_per_dimension_);
305 int area_len = (allocated_layer_count + 1) * areas_per_layer_;
306 areas_occupancy_.resize(area_len,
false);
319 const int2 pos_in_location_finder = (coord.
area_location() >> shift_right) << shift_left;
321 const int layer_offset = coord.
atlas_layer * areas_per_layer_;
322 const int areas_overlapped_per_dim = 1 << shift_left;
323 for (
const int y :
IndexRange(areas_overlapped_per_dim)) {
324 for (
const int x :
IndexRange(areas_overlapped_per_dim)) {
325 const int2 pos = pos_in_location_finder +
int2(
x,
y);
326 const int area_index = pos.x + pos.y * areas_per_dimension_;
327 areas_occupancy_[
area_index + layer_offset].set();
335 result.subdivision_lvl = subdivision_level_;
336 for (
int index : areas_occupancy_.index_range()) {
337 if (!areas_occupancy_[
index]) {
350 std::ostream &os = std::cout;
351 int layer = 0, row = 0, column = 0;
352 os <<
"subdivision " << subdivision_level_ <<
"\n";
353 for (
bool spot_taken : areas_occupancy_) {
354 if (row == 0 && column == 0) {
355 os <<
"layer " <<
layer <<
"\n";
357 os << (spot_taken ?
'X' :
'-');
359 if (column == areas_per_dimension_) {
364 if (row == areas_per_dimension_) {
#define BLI_assert_unreachable()
constexpr IndexRange()=default
MutableMapItem< Key, Value > MutableItem
float4x4 object_to_world(int instance_index) const
A running instance of the engine.
VolumeProbeModule volume_probes
uint get_recalc_flags(const ObjectRef &ob_ref)
friend class SphereProbeModule
LightProbeModule(Instance &inst)
void sync_world(const blender::World *world, bool has_update)
void sync_probe(const ObjectRef &ob_ref)
void mark_space_used(const SphereProbeAtlasCoord &coord)
LocationFinder(int allocated_layer_count, int subdivision_level)
SphereProbeAtlasCoord first_free_spot() const
void bricks_free(Vector< IrradianceBrickPacked > &bricks)
float3x3 scale(float3x3 mat, float2 scale)
static eLightProbeResolution resolution_to_probe_resolution_enum(int resolution)
MatBase< T, NumCol, NumRow > transpose(const MatBase< T, NumRow, NumCol > &mat)
MatBase< T, NumCol, NumRow > scale(const MatBase< T, NumCol, NumRow > &mat, const VectorT &scale)
T reduce_min(const VecBase< T, Size > &a)
CartesianBasis invert(const CartesianBasis &basis)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
VecBase< T, 3 > to_scale(const MatBase< T, NumCol, NumRow > &mat)
VecBase< T, 3 > transform_direction(const MatBase< T, 3, 3 > &mat, const VecBase< T, 3 > &direction)
T reduce_add(const VecBase< T, Size > &a)
T determinant(const MatBase< T, Size, Size > &mat)
MINLINE int square_i(int a)
MINLINE int max_ii(int a, int b)
MatBase< float, 4, 4 > float4x4
MatBase< float, 3, 4 > float3x4
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
VecBase< int32_t, 3 > int3
T & DRW_object_get_data_for_drawing(const Object &object)
@ LIGHT_PROBE_RESOLUTION_512
@ LIGHT_PROBE_RESOLUTION_4096
@ LIGHT_PROBE_RESOLUTION_2048
@ LIGHT_PROBE_RESOLUTION_256
@ LIGHT_PROBE_RESOLUTION_128
@ LIGHT_PROBE_RESOLUTION_1024
MatBase< float, 3, 3 > float3x3
MINLINE float max_ff(float a, float b)
VecBase< float, 3 > float3
@ LIGHTPROBE_FLAG_CUSTOM_PARALLAX
@ LIGHTPROBE_FLAG_SHOW_DATA
Point object_to_world(Point pt, float4x4 object_to_world)
struct LightProbeGridCacheFrame * grid_static_cache
static MatBase identity()
struct LightProbeObjectCache * lightprobe_cache
int gi_cubemap_resolution
float viewport_display_size
int2 area_location() const
struct SphereProbeUvArea atlas_coord
SphereProbeAtlasCoord atlas_coord
Vector< IrradianceBrickPacked > bricks
const LightProbeObjectCache * cache