1
1
#define_import_path bevy_solari ::world_cache
2
2
3
- /// Controls how response the world cache is to changes in lighting
4
- const WORLD_CACHE_MAX_TEMPORAL_SAMPLES: f32 = 30 .0 ;
3
+ /// How responsive the world cache is to changes in lighting (higher is less responsive, lower is more responsive)
4
+ const WORLD_CACHE_MAX_TEMPORAL_SAMPLES: f32 = 10 .0 ;
5
5
/// Maximum amount of frames a cell can live for without being queried
6
6
const WORLD_CACHE_CELL_LIFETIME: u32 = 30u ;
7
7
/// Maximum amount of attempts to find a cache entry after a hash collision
8
8
const WORLD_CACHE_MAX_SEARCH_STEPS: u32 = 3u ;
9
9
10
- /// Controls the base size of each cache cell
11
- const WORLD_CACHE_POSITION_BASE_CELL_SIZE: f32 = 0.4 ;
10
+ /// The size of a cache cell at the lowest LOD in meters
11
+ const WORLD_CACHE_POSITION_BASE_CELL_SIZE: f32 = 0.25 ;
12
+ /// How fast the world cache transitions between LODs as a function of distance to the camera
13
+ const WORLD_CACHE_POSITION_LOD_SCALE: f32 = 30.0 ;
12
14
13
15
/// Marker value for an empty cell
14
16
const WORLD_CACHE_EMPTY_CELL: u32 = 0u ;
@@ -36,9 +38,9 @@ struct WorldCacheGeometryData {
36
38
37
39
#ifndef WORLD_CACHE_NON_ATOMIC_LIFE_BUFFER
38
40
fn query_world_cache (world_position : vec3 <f32 >, world_normal : vec3 <f32 >, view_position : vec3 <f32 >) -> vec3 <f32 > {
39
- let world_position_quantized = bitcast <vec3 <u32 >> (quantize_position (world_position , view_position ));
41
+ let cell_size = get_cell_size (world_position , view_position );
42
+ let world_position_quantized = bitcast <vec3 <u32 >> (quantize_position (world_position , cell_size ));
40
43
let world_normal_quantized = bitcast <vec3 <u32 >> (quantize_normal (world_normal ));
41
-
42
44
var key = compute_key (world_position_quantized , world_normal_quantized );
43
45
let checksum = compute_checksum (world_position_quantized , world_normal_quantized );
44
46
@@ -64,12 +66,13 @@ fn query_world_cache(world_position: vec3<f32>, world_normal: vec3<f32>, view_po
64
66
}
65
67
#endif
66
68
67
- fn quantize_position (world_position : vec3 <f32 >, view_position : vec3 <f32 >) -> vec3 < f32 > {
68
- let base_size = WORLD_CACHE_POSITION_BASE_CELL_SIZE ;
69
- let d = distance ( view_position , world_position );
70
- let step = max (( d * base_size ) / 7.0 , base_size ) ;
71
- let quantization_factor = exp2 ( floor ( log2 ( step )));
69
+ fn get_cell_size (world_position : vec3 <f32 >, view_position : vec3 <f32 >) -> f32 {
70
+ let camera_distance = distance ( view_position , world_position ) / WORLD_CACHE_POSITION_LOD_SCALE ;
71
+ let lod = exp2 ( floor ( log2 ( 1.0 + camera_distance )) );
72
+ return WORLD_CACHE_POSITION_BASE_CELL_SIZE * lod ;
73
+ }
72
74
75
+ fn quantize_position (world_position : vec3 <f32 >, quantization_factor : f32 ) -> vec3 <f32 > {
73
76
return floor (world_position / quantization_factor + 0.0001 );
74
77
}
75
78
0 commit comments