Loading...
Searching...
No Matches
SceneResourceRoute.hpp
1#pragma once
2#include <halp/controls.hpp>
3#include <halp/meta.hpp>
4#include <halp/texture.hpp>
5
6#include <ossia/dataflow/geometry_port.hpp>
7
8#include <cstdint>
9#include <memory>
10
11namespace Threedim
12{
13
14// Level 1 of the "resource → scene field" routing design. Takes a GPU
15// texture handle from any upstream producer (CSF shader output, video,
16// ISF post-pass, asset loader, …) and stamps it onto a named field of
17// `scene_spec`. The emitted scene_spec is a partial contribution with
18// only that one field populated — `merge_scenes` overlays it onto the
19// rest of the scene_state the ScenePreprocessor receives from other
20// producers, so this node composes freely with EnvironmentLoader /
21// CubemapLoader / further SceneResourceRoute instances.
22//
23// Core use case is IBL wiring: an irradiance-convolution, GGX-prefilter
24// or BRDF-LUT shader's output plugs in here and lands on
25// `scene_environment.{irradiance_map, prefiltered_map, brdf_lut}` with
26// no per-target glue code. Shadow-map generation passes will target
27// `scene_state.shadow_cascades.shadow_map_array` the same way.
28//
29// Pattern mirrors CubemapComposer / InjectTexture: CPU-side producer,
30// port-driven rebuild + handle-change detection in operator()().
31enum class SceneResourceTarget : int
32{
33 Skybox, // scene_environment.skybox_texture
34 IrradianceMap, // scene_environment.irradiance_map
35 PrefilteredMap, // scene_environment.prefiltered_map
36 BRDFLut, // scene_environment.brdf_lut
37 ShadowMapArray, // scene_state.shadow_cascades.shadow_map_array
38};
39
41{
42public:
43 halp_meta(name, "Scene Resource Route")
44 halp_meta(category, "Visuals/3D/Scene")
45 halp_meta(c_name, "scene_resource_route")
46 halp_meta(description, "Route a GPU texture into a selected scene environment or shadow resource field.")
47 halp_meta(authors, "ossia team")
48 halp_meta(
49 manual_url,
50 "https://ossia.io/score-docs/processes/scene-resource-route.html")
51 halp_meta(uuid, "c2f7a341-8e69-4b0d-b3f8-2d7e4c5a9f1b")
52
53 struct ins
54 {
55 // Accepts any GPU texture kind. A texture is routed only when its kind
56 // matches the target's sampler: cubemap for Skybox / IrradianceMap /
57 // PrefilteredMap, 2D for BRDFLut, array for ShadowMapArray.
58 halp::gpu_texture_input<"Texture"> texture;
59
60 // Port-driven rebuild: target changes fire rebuild(); upstream
61 // handle flips are caught by operator()() since the halp GPU-texture
62 // input doesn't emit a port-update event when only the native
63 // handle swaps.
64 struct : halp::enum_t<SceneResourceTarget, "Target Field">
65 {
66 void update(SceneResourceRoute& n) { n.rebuild(); }
67 } target;
68 } inputs;
69
70 struct outs
71 {
72 struct
73 {
74 halp_meta(name, "Scene");
75 ossia::scene_spec scene;
76 uint8_t dirty{0};
77 } scene_out;
78 } outputs;
79
80 void rebuild();
81 void operator()();
82
83 // Cached output scene_state — stable identity across frames (so
84 // downstream scene-identity caches stay hot) and mutated in place on
85 // target / handle changes.
86 std::shared_ptr<ossia::scene_state> m_state;
87 int64_t m_version{0};
88 void* m_cached_handle{};
89 SceneResourceTarget m_cached_target{SceneResourceTarget::Skybox};
90 uint8_t m_pending_dirty{0xFF};
91};
92
93}
Definition SceneResourceRoute.hpp:41
Definition SceneResourceRoute.hpp:54
Definition SceneResourceRoute.hpp:71