@@ -16,8 +16,9 @@ namespace Renderer {
1616// /
1717// / Each frame, the helper:
1818// / 1. Projects the light direction to a screen-space point.
19- // / 2. Uses a single PickQuery (slot `pickSlot`) on that pixel to test
19+ // / 2. When MAX_PICK_QUERIES > 0, uses a PickQuery on that pixel to test
2020// / whether any geometry occludes the "sun". No hit => sun visible.
21+ // / When picking is compiled out, the sun is treated as unobstructed.
2122// / 3. Repositions a fixed set of Sprite2D elements along the line that
2223// / passes through both the sun's screen position and the screen centre,
2324// / and sets their alpha to reflect the current visibility (with optional
@@ -40,12 +41,11 @@ namespace Renderer {
4041// / flare.update(dt);
4142// / @endcode
4243// /
43- // / @note Requires MAX_PICK_QUERIES > 0 in JetConfig.hpp.
44+ // / @note MAX_PICK_QUERIES > 0 enables occlusion testing; the flare still
45+ // / renders without occlusion when picking is compiled out.
4446// / @note The LensFlare registers all sprites with the scene on construction;
4547// / do not call scene->addSprite() for the same sprites separately.
4648
47- #if MAX_PICK_QUERIES > 0
48-
4949class LensFlare {
5050public:
5151 // / @brief One sprite element in the flare chain.
@@ -106,7 +106,7 @@ class LensFlare {
106106 }
107107
108108 // / @brief Call once per frame BEFORE scene->render() to submit the pick
109- // / query and compute sun screen position.
109+ // / query, when enabled, and compute sun screen position.
110110 // /
111111 // / @param camera Active camera. Must match what scene will render with.
112112 // / @param screenW Render width in pixels (framebuffer coords).
@@ -125,9 +125,13 @@ class LensFlare {
125125 if (!sunInFrustum) {
126126 // Disable all sprites immediately.
127127 for (int i = 0 ; i < elementCount; ++i) sprites[i].enabled = false ;
128+ #if MAX_PICK_QUERIES > 0
128129 // Still need to clear the pick slot so it doesn't report stale results.
129- PickQuery q; q.x = -1 ; q.y = -1 ;
130- scene->setPickQueries (&q, 1 ); // slot 0 only; see note below
130+ PickQuery queries[MAX_PICK_QUERIES ] = {};
131+ const int slot = pickSlot < 0 ? 0 : (pickSlot >= MAX_PICK_QUERIES ? MAX_PICK_QUERIES - 1 : pickSlot);
132+ for (int i = 0 ; i <= slot; ++i) { queries[i].x = -1 ; queries[i].y = -1 ; }
133+ scene->setPickQueries (queries, slot + 1 );
134+ #endif
131135 return ;
132136 }
133137
@@ -146,16 +150,19 @@ class LensFlare {
146150 const int pqx = sunScreenX < 0 ? 0 : (sunScreenX >= screenW ? screenW - 1 : sunScreenX);
147151 const int pqy = sunScreenY < 0 ? 0 : (sunScreenY >= screenH ? screenH - 1 : sunScreenY);
148152
149- // Submit pick query for the sun pixel.
150- PickQuery q;
151- q.x = (int16_t )pqx;
152- q.y = (int16_t )pqy;
153- // We only manage one slot; the caller specified which index to use.
154- // Scene::setPickQueries replaces all queries so we must submit all
155- // slots the caller wants active. For simplicity we take exclusive
156- // ownership of the whole query array here — if the caller also needs
157- // other pick queries they should subclass / extend this helper.
158- scene->setPickQueries (&q, 1 );
153+ #if MAX_PICK_QUERIES > 0
154+ // Submit pick query for the sun pixel. Scene::setPickQueries replaces
155+ // all queries, so fill disabled slots up through our selected slot.
156+ PickQuery queries[MAX_PICK_QUERIES ] = {};
157+ const int slot = pickSlot < 0 ? 0 : (pickSlot >= MAX_PICK_QUERIES ? MAX_PICK_QUERIES - 1 : pickSlot);
158+ for (int i = 0 ; i <= slot; ++i) { queries[i].x = -1 ; queries[i].y = -1 ; }
159+ queries[slot].x = (int16_t )pqx;
160+ queries[slot].y = (int16_t )pqy;
161+ scene->setPickQueries (queries, slot + 1 );
162+ #else
163+ (void )pqx;
164+ (void )pqy;
165+ #endif
159166 }
160167
161168 // / @brief Call once per frame AFTER scene->render() to read pick results,
@@ -199,10 +206,12 @@ class LensFlare {
199206 // Clamp to [0,1]: negative when sun is off-screen; sprites get alpha=0.
200207 if (edgeFade < 0 .0f ) edgeFade = 0 .0f ;
201208
202- // Read pick result for our slot.
203- // const PickResult* results = scene->getPickResults();
204- // const bool occluded = results && results[0].hit;
205- const bool occluded = false ; // TEST: always visible — re-enable pick check when confirmed working
209+ bool occluded = false ;
210+ #if MAX_PICK_QUERIES > 0
211+ const PickResult* results = scene->getPickResults ();
212+ const int slot = pickSlot < 0 ? 0 : (pickSlot >= MAX_PICK_QUERIES ? MAX_PICK_QUERIES - 1 : pickSlot);
213+ occluded = results && scene->getPickQueryCount () > slot && results[slot].hit ;
214+ #endif
206215
207216 // Fade visibility toward target.
208217 const float target = occluded ? 0 .0f : 1 .0f ;
@@ -303,6 +312,4 @@ class LensFlare {
303312 Sprite2D sprites[MAX_FLARE_ELEMENTS ];
304313};
305314
306- #endif // MAX_PICK_QUERIES > 0
307-
308315} // namespace Renderer
0 commit comments