20 if (!trail_system_)
return;
22 auto& registry = collect_ctx.
registry;
23 auto& frustum = collect_ctx.
frustum;
29 const f32 now = trail_system_->now();
33 for (
auto entity : view) {
35 if (!
trail.enabled)
continue;
36 const f32 groupAlpha = groupOpacity.of(entity);
37 if (groupAlpha <= 0.0f)
continue;
40 if (!state || state->
points.empty())
continue;
44 const glm::vec3 headWorld =
rebased(transform.worldPosition);
47 const f32 invTime =
trail.time > 1e-6f ? 1.0f /
trail.time : 0.0f;
48 scratch_center_.clear();
49 glm::vec3 lo(std::numeric_limits<f32>::max());
50 glm::vec3 hi(std::numeric_limits<f32>::lowest());
51 auto extend = [&](
const glm::vec3& p) { lo = glm::min(lo, p); hi = glm::max(hi, p); };
53 for (
const auto& pt : state->
points) {
54 f32 age01 = std::min(std::max((now - pt.birth_time) * invTime, 0.0f), 1.0f);
55 const glm::vec3 at =
rebased(pt.position);
56 scratch_center_.push_back({at, age01});
63 glm::vec3 d = headWorld - scratch_center_.back().pos;
64 if (glm::dot(d, d) > 1e-4f) {
65 scratch_center_.push_back({headWorld, 0.0f});
68 scratch_center_.back().age01 = 0.0f;
72 const usize n = scratch_center_.size();
76 const f32 maxHalf = 0.5f * std::max(
trail.startWidth,
trail.endWidth);
77 const glm::vec3 aabbCenter = (lo + hi) * 0.5f;
78 const glm::vec3 halfExtents = (hi - lo) * 0.5f + maxHalf;
79 if (!frustum.intersectsAABB(aabbCenter, halfExtents)) { ++collect_ctx.
culled;
continue; }
82 u32 textureId =
ctx.white_texture_id;
83 if (
trail.texture.isValid()) {
85 textureId = tex->getId();
90 .stage =
ctx.current_stage,
92 .shaderId =
ctx.batch_shader_id,
94 .textureId = textureId,
100 if (
trail.material != 0) {
102 key.
shaderId = (m->shader != 0) ? m->shader :
ctx.batch_shader_id;
103 key.
blend = m->blend;
107 key.
cull =
static_cast<u8>(m->cull);
113 scratch_verts_.clear();
114 scratch_verts_.reserve(n * 2);
115 glm::vec3 lastTangent(1.0f, 0.0f, 0.0f);
116 glm::vec3 lastSide(0.0f, 1.0f, 0.0f);
117 for (
usize i = 0; i < n; ++i) {
120 const glm::vec3& a = scratch_center_[i == 0 ? 0 : i - 1].
pos;
121 const glm::vec3& b = scratch_center_[i + 1 == n ? i : i + 1].pos;
122 glm::vec3 seg = b - a;
123 f32 len = glm::length(seg);
124 glm::vec3 tangent = len > 1e-6f ? seg / len : lastTangent;
125 lastTangent = tangent;
130 glm::vec4 trailColor = glm::mix(
trail.startColor,
trail.endColor, c.
age01);
131 trailColor.a *= groupAlpha;
135 scratch_verts_.push_back({c.
pos + side * halfW, color, glm::vec2(u, 0.0f)});
136 scratch_verts_.push_back({c.
pos - side * halfW, color, glm::vec2(u, 1.0f)});
139 scratch_indices_.clear();
140 scratch_indices_.reserve((n - 1) * 6);
141 for (
u32 i = 0; i + 1 < n; ++i) {
142 u32 l0 = i * 2, r0 = l0 + 1, l1 = l0 + 2, r1 = l0 + 3;
143 scratch_indices_.push_back(l0);
144 scratch_indices_.push_back(r0);
145 scratch_indices_.push_back(r1);
146 scratch_indices_.push_back(l0);
147 scratch_indices_.push_back(r1);
148 scratch_indices_.push_back(l1);
152 scratch_verts_.data(),
static_cast<u32>(scratch_verts_.size()),
153 scratch_indices_.data(),
static_cast<u32>(scratch_indices_.size()), key);
GPU texture abstraction for 2D images.
2D texture for GPU rendering
void appendIndexedBatch(TransientBufferPool &pool, DrawList &drawList, const ClipState &clips, const BatchVertex *verts, u32 vertexCount, const u32 *localIndices, u32 indexCount, const BatchDrawKey &key)
Copies verts into the Batch stream, then pushes one DrawCommand spanning them.
u32 culled
How many renderables this collect's frustum rejected.
RenderFrameContext & frame_context
TransientBufferPool & buffer_pool