|
| 1 | +class_name FoveaSplatSubsystem |
| 2 | +extends Node |
| 3 | + |
| 4 | +## FoveaSplatSubsystem — Pipeline de génération, tri, filtrage et rendu des Gaussian Splats. |
| 5 | +## Extrait de FoveaCoreManager pour respecter le principe de responsabilité unique. |
| 6 | +## Responsabilités : |
| 7 | +## - Génération de splats depuis les surfaces visibles |
| 8 | +## - Reprojection temporelle |
| 9 | +## - Tri back-to-front (GPU ou CPU) |
| 10 | +## - Injection dans le SplatRenderer |
| 11 | + |
| 12 | +## Splats du frame courant (post-tri, pré-rendu) |
| 13 | +var current_splats: Array[GaussianSplat] = [] |
| 14 | + |
| 15 | +## Config du générateur |
| 16 | +var splat_config: SplatGenerator.SplatConfig = null |
| 17 | + |
| 18 | +## Densité globale (multiplie la config locale de chaque FoveaSplattable) |
| 19 | +var global_splat_density: float = 1.0 |
| 20 | + |
| 21 | +## Références aux sous-systèmes partenaires (injectées par le manager) |
| 22 | +var temporal_reprojector: TemporalReprojector = null |
| 23 | +var occlusion_culler: OcclusionCuller = null |
| 24 | +var splat_sorter: SplatSorter = null |
| 25 | +var splat_renderer: SplatRenderer = null |
| 26 | + |
| 27 | +## Position caméra du frame précédent (pour reprojection temporelle) |
| 28 | +var _previous_camera_position: Vector3 = Vector3.ZERO |
| 29 | + |
| 30 | +func setup(density: float) -> void: |
| 31 | + global_splat_density = density |
| 32 | + |
| 33 | + splat_config = SplatGenerator.SplatConfig.new() |
| 34 | + splat_config.splats_per_triangle = 3 |
| 35 | + splat_config.min_radius = 0.02 |
| 36 | + splat_config.max_radius = 0.3 |
| 37 | + splat_config.depth_aware_blending = true |
| 38 | + |
| 39 | +## Traiter les résultats de visibilité pour un frame |
| 40 | +## Retourne le nombre de splats rendus |
| 41 | +func process_frame(visibility_result, camera: Camera3D, camera_pos: Vector3) -> int: |
| 42 | + _generate_and_filter(visibility_result, camera, camera_pos) |
| 43 | + _previous_camera_position = camera_pos |
| 44 | + return _submit_to_renderer() |
| 45 | + |
| 46 | +## Génération + reprojection temporelle + occlusion |
| 47 | +func _generate_and_filter(visibility_result, camera: Camera3D, camera_pos: Vector3) -> void: |
| 48 | + if temporal_reprojector: |
| 49 | + current_splats = [] |
| 50 | + for node in visibility_result.per_node_results: |
| 51 | + var extraction = visibility_result.per_node_results[node] |
| 52 | + var filtered_triangles = _filter_occlusion(extraction.visible_triangles, camera) |
| 53 | + var reprojected: Array[GaussianSplat] = temporal_reprojector.reproject_splats( |
| 54 | + node, [], camera_pos, _previous_camera_position, filtered_triangles) |
| 55 | + current_splats.append_array(reprojected) |
| 56 | + else: |
| 57 | + current_splats = SplatGenerator.generate_all_splats( |
| 58 | + visibility_result, camera_pos, splat_config, global_splat_density) |
| 59 | + |
| 60 | + current_splats = _sort_gpu_aware(current_splats, camera, camera_pos) |
| 61 | + |
| 62 | +## Filtre les triangles occultés via le Hi-Z culler CPU |
| 63 | +func _filter_occlusion(triangles: Array, camera: Camera3D) -> Array: |
| 64 | + if occlusion_culler == null or camera == null: |
| 65 | + return triangles |
| 66 | + var view_proj := camera.get_camera_projection() * Projection(camera.global_transform.affine_inverse()) |
| 67 | + var filtered: Array = [] |
| 68 | + for tri in triangles: |
| 69 | + if not occlusion_culler.is_occluded(tri.center, view_proj, camera.global_transform): |
| 70 | + filtered.append(tri) |
| 71 | + return filtered |
| 72 | + |
| 73 | +## Tri back-to-front : GPU si disponible, sinon CPU par profondeur |
| 74 | +func _sort_gpu_aware(splats: Array[GaussianSplat], camera: Camera3D, camera_pos: Vector3) -> Array[GaussianSplat]: |
| 75 | + if splat_sorter and splat_sorter.is_gpu_available() and splats.size() <= splat_sorter.get_max_supported_splats(): |
| 76 | + var indices := splat_sorter.sort_splats_back_to_front(splats, camera) |
| 77 | + if indices and not indices.is_empty(): |
| 78 | + var sorted: Array[GaussianSplat] = [] |
| 79 | + for idx in indices: |
| 80 | + if idx < splats.size(): |
| 81 | + sorted.append(splats[idx]) |
| 82 | + return sorted |
| 83 | + return SplatSorter.sort_by_depth(splats, camera_pos) |
| 84 | + |
| 85 | +## Soumettre les splats triés au renderer |
| 86 | +func _submit_to_renderer() -> int: |
| 87 | + if splat_renderer == null: |
| 88 | + return 0 |
| 89 | + return splat_renderer.render_splats(current_splats) |
| 90 | + |
| 91 | +## Appliquer les poids foveated et filtrer par opacité |
| 92 | +func apply_foveated_pass(foveated_controller: FoveatedController) -> void: |
| 93 | + if foveated_controller == null: |
| 94 | + return |
| 95 | + var foveated_splats: Array[GaussianSplat] = [] |
| 96 | + for splat in current_splats: |
| 97 | + var weight := foveated_controller.get_foveal_weight(splat.position) |
| 98 | + var density := foveated_controller.get_density_multiplier(splat.position) |
| 99 | + splat.apply_foveal_weight(weight * density / 2.0) |
| 100 | + if splat.opacity > 0.05: |
| 101 | + foveated_splats.append(splat) |
| 102 | + current_splats = foveated_splats |
| 103 | + current_splats = SplatSorter.minimize_overdraw(current_splats) |
0 commit comments