33#include <glm/gtc/matrix_transform.hpp>
34#include <glm/gtc/matrix_inverse.hpp>
35#include <glm/gtc/matrix_access.hpp>
51 u32 r = (((a >> 0) & 0xFF) * ((b >> 0) & 0xFF)) / 255u;
52 u32 g = (((a >> 8) & 0xFF) * ((b >> 8) & 0xFF)) / 255u;
53 u32 bl = (((a >> 16) & 0xFF) * ((b >> 16) & 0xFF)) / 255u;
54 u32 al = (((a >> 24) & 0xFF) * ((b >> 24) & 0xFF)) / 255u;
55 return r | (g << 8) | (bl << 16) | (al << 24);
76u32 skinnedBy(
const Mesh& mesh,
usize joints,
bool& warnedBones) {
77 if (!mesh.isSkinned() || joints != mesh.inverseBind.size())
return 0;
85 ES_LOG_WARN(
"MeshSkin: {} joints exceeds the {} one draw can be posed by; drawing the"
90 return static_cast<u32>(joints);
95 return skin ? skinnedBy(mesh, skin->joints.size(), warnedBones) : 0;
103 const Mesh* resident = row.meshHandle != 0
105 facts.hasNormals = resident && resident->hasNormals;
106 facts.lit = row.lit != 0;
107 facts.materialId = row.materialId;
108 if (row.normalMapHandle != 0 && facts.lit && facts.hasNormals) {
110 facts.normalTextureId = tex->getId();
113 facts.skinned = resident && skinnedBy(*resident, row.jointCount, warnedBones) > 0;
114 facts.lightmapped = resident && resident->hasLightmapUV;
115 facts.tangents = resident && resident->hasTangents;
120 std::vector<glm::mat4>& out,
bool& warnedBones) {
121 const u32 count = skinJointCount(registry, entity, mesh, warnedBones);
122 if (count == 0)
return 0;
126 for (
u32 i = 0; i < count; ++i) {
130 if (!joint) { out[i] = glm::mat4(1.0f);
continue; }
135 const glm::mat4
world = glm::translate(glm::mat4(1.0f),
rebased(joint->worldPosition))
136 * glm::mat4_cast(joint->worldRotation)
137 * glm::scale(glm::mat4(1.0f), joint->worldScale);
138 out[i] =
world * mesh.inverseBind[i];
153 glm::vec3& centre, glm::vec3& half) {
154 const u32 count = skinJointCount(registry, entity, mesh, warnedBones);
155 if (count == 0)
return false;
157 const glm::vec3 bindCentre = (mesh.localMin + mesh.localMax) * 0.5f;
158 const f32 bindRadius = glm::length(mesh.localMax - mesh.localMin) * 0.5f;
159 glm::vec3 lo(std::numeric_limits<f32>::max()), hi(std::numeric_limits<f32>::lowest());
160 for (
u32 i = 0; i < count; ++i) {
162 if (!joint)
continue;
164 const glm::vec3 scale = glm::abs(joint->worldScale);
165 const f32 reach = (glm::length(glm::vec3(mesh.inverseBind[i] * glm::vec4(bindCentre, 1.0f))) + bindRadius)
166 * std::max({scale.x, scale.y, scale.z});
167 const glm::vec3 at =
rebased(joint->worldPosition);
168 lo = glm::min(lo, at - reach);
169 hi = glm::max(hi, at + reach);
171 if (lo.x > hi.x)
return false;
172 centre = (lo + hi) * 0.5f;
173 half = (hi - lo) * 0.5f;
189 if (!mesh.isMorphable())
return false;
191 if (!morph)
return false;
195 const u32 count = std::min(
static_cast<u32>(morph->weights.size()), mesh.morphTargetCount);
197 for (
u32 t = 0; t < count; ++t) {
198 const f32 weight = morph->weights[t];
199 if (weight == 0.0f)
continue;
201 out.shape[live++] = glm::vec4(
static_cast<f32>(t), weight, 0.0f, 0.0f);
209 if (std::abs(out.shape[i].y) < std::abs(out.shape[lightest].y)) lightest = i;
211 if (std::abs(weight) > std::abs(out.shape[lightest].y)) {
212 out.shape[lightest] = glm::vec4(
static_cast<f32>(t), weight, 0.0f, 0.0f);
215 if (live == 0)
return false;
216 out.info = glm::vec4(
static_cast<f32>(live),
static_cast<f32>(mesh.vertexCount),
217 mesh.morphHasNormals ? 2.0f : 1.0f,
223void reportLodAuthoring(
const LodLevels& levels,
bool& warned) {
224 if (warned || !(levels.gap || levels.disordered || levels.skinMismatch))
return;
227 ES_LOG_WARN(
"LODGroup: a stand-in slot is empty, so every slot after it is unreachable —"
228 " fill lod1, then lod2, then lod3");
230 if (levels.disordered) {
231 ES_LOG_WARN(
"LODGroup: the screen sizes do not descend, so a level is handed over to"
232 " before the one before it");
234 if (levels.skinMismatch) {
235 ES_LOG_WARN(
"LODGroup: a stand-in has a different joint count from level 0; every level of"
236 " a skinned group must share the skeleton");
240u32 meshVariant(
bool normals,
bool lit,
bool normalMapped,
bool skinned,
bool depthOnly,
241 bool envMapped,
bool lightmapped,
bool weightHeat =
false,
bool gbuffer =
false,
242 bool motion =
false,
bool tangents =
false,
bool direct =
false) {
243 return (normals ? 1u : 0u) | (lit ? 2u : 0u) | (normalMapped ? 4u : 0u)
244 | (skinned ? 8u : 0u) | (depthOnly ? 16u : 0u) | (envMapped ? 32u : 0u)
245 | (lightmapped ? 64u : 0u) | (weightHeat ? 128u : 0u) | (gbuffer ? 256u : 0u)
246 | (motion ? 512u : 0u) | (tangents ? 1024u : 0u) | (direct ? 2048u : 0u);
259constexpr glm::vec4 kWireFill{0.075f, 0.075f, 0.08f, 1.0f};
260constexpr glm::vec4 kWireInk{0.9f, 0.9f, 0.9f, 1.0f};
263constexpr i16 kWireFillBias = 4;
278 mesh.color = kWireFill;
283 mesh.color = glm::vec4(0.74f, 0.74f, 0.76f, 1.0f);
294glm::vec4 clusterInk(
u32 id) {
295 u32 h =
id * 0x9E3779B1u;
297 const f32 hue =
static_cast<f32>(h & 0xFFFFu) / 65536.0f * 6.0f;
298 const f32 rise = hue - std::floor(hue);
299 const f32 low = 0.28f, high = 0.95f;
300 const f32 up = low + (high - low) * rise, down = high - (high - low) * rise;
301 switch (
static_cast<u32>(hue) % 6u) {
302 case 0:
return {high, up, low, 1.0f};
303 case 1:
return {down, high, low, 1.0f};
304 case 2:
return {low, high, up, 1.0f};
305 case 3:
return {low, down, high, 1.0f};
306 case 4:
return {up, low, high, 1.0f};
307 default:
return {high, low, down, 1.0f};
313 u32 normalTextureId = 0;
316u32 meshVariantFrom(
const MeshProgramFacts& facts,
bool envMapped,
bool shadowDepth,
bool direct,
bool weightHeat =
false,
317 bool gbuffer =
false) {
321 const bool heat = weightHeat && facts.skinned && !shadowDepth;
322 const bool lit = facts.lit && !shadowDepth && !heat;
324 return meshVariant(facts.hasNormals, lit,
325 facts.normalTextureId != 0 && !shadowDepth && !heat, facts.skinned, shadowDepth,
326 envMapped, facts.lightmapped, heat, gbuffer && lit,
false, facts.tangents, direct && lit);
332 const Mesh* resident,
bool& warnedBones) {
334 facts.
hasNormals = resident && resident->hasNormals;
335 facts.lit = mesh.lit;
336 facts.opaque = mesh.opaque;
337 facts.materialId = mesh.material;
339 if (mesh.normalMap.isValid() && mesh.lit && resident && resident->hasNormals) {
340 if (
Texture* tex =
ctx.resources.getTexture(mesh.normalMap)) {
341 facts.normalTextureId = tex->getId();
344 facts.skinned = resident && skinJointCount(registry, entity, *resident, warnedBones) > 0;
345 facts.lightmapped = resident && resident->hasLightmapUV;
346 facts.tangents = resident && resident->hasTangents;
352 bool weightHeat =
false) {
353 return { meshVariantFrom(facts,
ctx.environment_texture_id != 0
354 || (!shadowDepth &&
ctx.frame &&
ctx.frame->planarTextureFor(entity) != 0), shadowDepth,
ctx.lighting_direct, weightHeat,
355 ctx.gbuffer && !shadowDepth),
356 facts.normalTextureId };
361 bool& warnedBones,
bool weightHeat =
false) {
362 return meshDrawFrom(
ctx, entity, meshFactsFromEntity(
ctx, registry, entity, mesh, resident, warnedBones), shadowDepth,
368 if (!mesh.normalMap.isValid() || !facts.lit || !facts.hasNormals)
return 0;
369 Texture* tex =
ctx.resources.getTexture(mesh.normalMap);
370 return tex ? tex->getId() : 0;
392 if (latest == 0 || (t != 0 &&
ecs::tickAfter(t, latest))) latest = t;
401 for (
const Entity entity : registry.view<ecs::MeshRenderer, ecs::MeshSkin>()) {
402 const auto& skin = registry.get<ecs::MeshSkin>(entity);
403 const auto usage =
static_cast<SkinCacheUsage>(std::clamp(skin.skinCache, 0, 2));
404 if (!cache.wants(usage))
continue;
405 const auto& renderer = registry.get<ecs::MeshRenderer>(entity);
406 if (!renderer.enabled || !renderer.mesh.isValid())
continue;
407 const Mesh* resident =
ctx.resources.getMesh(renderer.mesh);
408 if (!resident || !resident->isDrawable())
continue;
411 const u32 joints = skinPose(registry, entity, *resident, pose_scratch_, warned_bones_);
412 if (joints == 0)
continue;
413 cache.schedule(entity, *resident, pose_scratch_.data(), joints);
421 for (
auto& shader : mesh_shaders_) {
422 if (shader.isValid())
ctx.resources.releaseShader(shader);
428 if (std::any_of(mesh_compiled_.begin(), mesh_compiled_.end(), [](
bool c) { return c; })) {
429 ctx.render_context.advanceProgramEpoch();
431 mesh_compiled_.fill(
false);
432 mesh_programs_.fill(0);
451 const bool normals = (variant & 1u) != 0, lit = (variant & 2u) != 0;
452 const bool normalMapped = (variant & 4u) != 0, skinned = (variant & 8u) != 0;
453 const bool depthOnly = (variant & 16u) != 0, envMapped = (variant & 32u) != 0;
454 const bool lightmapped = (variant & 64u) != 0, weightHeat = (variant & 128u) != 0;
455 const bool gbuffer = (variant & 256u) != 0, motion = (variant & 512u) != 0;
456 const bool tangents = (variant & 1024u) != 0, direct = (variant & 2048u) != 0;
457 if (mesh_compiled_[variant])
return mesh_programs_[variant];
458 mesh_compiled_[variant] =
true;
463 ++compiled_this_frame_;
465 last_compiled_variant_ = variant;
467 std::vector<std::string> features;
468 if (normals) features.emplace_back(
"MESH_NORMALS");
469 if (lit) features.emplace_back(
"LIT");
470 if (normalMapped) features.emplace_back(
"NORMAL_MAP");
471 if (skinned) features.emplace_back(
"SKINNED");
472 if (lightmapped) features.emplace_back(
"MESH_LIGHTMAP");
474 if (tangents && normals && lit && !depthOnly) features.emplace_back(
"MESH_TANGENTS");
475 if (weightHeat) features.emplace_back(
"WEIGHT_HEAT");
476 if (depthOnly) features.emplace_back(
"SHADOW_DEPTH");
477 if (motion) features.emplace_back(
"ES_VELOCITY");
482 features.emplace_back(
"ES_RECEIVE_SHADOW");
483 if (envMapped) features.emplace_back(
"ES_ENV_MAP");
487 features.emplace_back(
"ES_SURFACE_3D");
491 if (gbuffer) features.emplace_back(
"ES_GBUFFER");
492 if (direct) features.emplace_back(
"ES_LIGHT_DIRECT");
496 const auto target =
ctx.resources.preferredShaderTarget();
498 auto compile = [&](std::vector<std::string> features) ->
u32 {
499 const bool normalMapped = std::find(features.begin(), features.end(),
"NORMAL_MAP")
502 handle =
ctx.resources.createShaderWithBindings(
505 {},
ctx.resources.preferredShaderLanguage(),
ctx.resources.deferLinks() && !compile_in_place_);
506 Shader* shader =
ctx.resources.getShader(handle);
507 if (!shader || !shader->isValid())
return 0;
510 shader->whenLinked([normalMapped](
Shader& s) {
513 if (s.hasUniform(
"u_texture")) s.setUniform(
"u_texture", 0);
515 if (normalMapped) s.setUniform(
"u_normalMap", 1);
519 return shader->getProgramId();
521 mesh_programs_[variant] = compile(features);
523 if (gbuffer && mesh_programs_[variant] != 0 &&
ctx.materials)
ctx.materials->markGBufferProgram(mesh_programs_[variant],
true);
524 return mesh_programs_[variant];
531 const u32 preview = variant & (1u | 8u | 64u | 256u);
532 if (mesh_compiled_[preview])
return mesh_programs_[preview];
533 compile_in_place_ =
true;
534 const u32 program = meshProgram(
ctx, preview);
535 compile_in_place_ =
false;
541 bool shadowPasses,
bool residentGeometry) {
543 const u32 materialsBefore =
ctx.materials ?
ctx.materials->builtVariantCount() : 0;
544 const bool envMapped =
ctx.environment_texture_id != 0;
545 for (
u32 i = 0; i < count; ++i) {
549 for (
u32 pass = 0; pass < 2; ++pass) {
550 const bool shadowDepth = pass == 1;
551 if (shadowDepth && (!shadowPasses || !residentGeometry))
continue;
552 const u32 variant = meshVariantFrom(facts[i], envMapped, shadowDepth,
ctx.lighting_direct);
555 if (!mesh_compiled_[variant]) ++out.
compiles;
556 meshProgram(
ctx, variant);
560 if (facts[i].materialId != 0 &&
ctx.materials) {
563 facts[i].materialId, facts[i].hasNormals, facts[i].skinned, envMapped,
564 facts[i].lightmapped, facts[i].tangents));
565 ctx.materials->meshProgram(facts[i].materialId,
ctx.resources, facts[i].
hasNormals,
573 compiled_this_frame_ = 0;
580 std::vector<MeshProgramFacts> facts;
581 facts.reserve(count);
582 bool anyResident =
false;
583 for (
u32 i = 0; i < count; ++i) {
584 if (rows[i].meshHandle == 0)
continue;
585 anyResident = anyResident
587 facts.push_back(meshFactsFromDocument(
ctx, rows[i], warned_bones_));
594 const Entity* entities,
u32 count,
bool shadowPasses) {
595 std::vector<MeshProgramFacts> facts;
596 facts.reserve(count);
597 bool anyResident =
false;
598 for (
u32 i = 0; i < count; ++i) {
599 const Entity entity = entities[i];
601 if (!mesh || !mesh->enabled)
continue;
602 if (mesh->indices.empty() && !mesh->mesh.isValid())
continue;
603 const Mesh* resident = mesh->mesh.isValid() ?
ctx.resources.getMesh(mesh->mesh) :
nullptr;
604 anyResident = anyResident || resident !=
nullptr;
606 meshFactsFromEntity(
ctx, registry, entity, *mesh, resident, warned_bones_));
613 const u64 key = poseKey(
ctx, entity);
614 if (kept && kept->pose && kept->poseKey == key && kept->poseGeneration == pose_generation_)
return kept->pose;
615 Pose* pose =
nullptr;
619 const auto found = poses_.find(key);
620 if (found != poses_.end()) pose = &found->second;
625 kept->poseGeneration = pose_generation_;
631 const std::vector<glm::mat4>* bones) {
634 const bool continued = pose.frame != 0 && pose.frame + 1 ==
ctx.motion_frame;
638 pose.bonesPrevious = pose.bonesCurrent;
639 for (glm::mat4& bone : pose.bonesPrevious) bone =
modelFromOrigin(bone, pose.origin);
640 }
else if (pose.frame !=
ctx.motion_frame) {
641 pose.previous = model;
642 if (bones) pose.bonesPrevious = *bones;
643 else pose.bonesPrevious.clear();
645 pose.current = model;
646 if (bones) pose.bonesCurrent = *bones;
647 else pose.bonesCurrent.clear();
648 pose.frame =
ctx.motion_frame;
652void MeshPlugin::addMover(
Entity entity) {
653 const u32 index = entity.index();
654 if (index >= mover_at_.size()) mover_at_.resize(
static_cast<usize>(index) + 1, 0);
655 movers_.push_back(entity);
656 mover_at_[index] =
static_cast<u32>(movers_.size());
659void MeshPlugin::clearMovers() {
660 for (
const Entity e : movers_) mover_at_[e.index()] = 0;
664bool MeshPlugin::dropStillMovers() {
665 constexpr u32 kStillLooks = 240;
666 bool dropped =
false;
667 for (
usize i = 0; i < movers_.size();) {
668 const Entity e = movers_[i];
669 const u32 index = e.index();
670 const u64 seen = index < cast_changed_at_.size() ? cast_changed_at_[index] : 0;
671 const bool same =
static_cast<u32>(seen >> 32) == e.id();
672 if (same && cast_look_ -
static_cast<u32>(seen) < kStillLooks) { ++i;
continue; }
673 mover_at_[index] = 0;
674 movers_[i] = movers_.back();
676 if (i < movers_.size()) mover_at_[movers_[i].index()] =
static_cast<u32>(i + 1);
683 key = cast_held_key_;
684 return cast_held_vouched_;
689 if (++cast_look_ == 0) cast_look_ = 1;
691 bool heldMoved =
false;
692 if (registry.
identity() != cast_registry_) {
695 cast_changed_at_.clear();
699 const u32 since = cast_tick_;
709 }
else if (why == 0) {
710 constexpr u32 kRecentLooks = 8;
714 const u32 index = e.index();
715 if (index >= cast_changed_at_.size()) cast_changed_at_.resize(
static_cast<usize>(index) + 1, 0);
716 const u64 seen = cast_changed_at_[index];
717 const bool recent =
static_cast<u32>(seen >> 32) == e.id() && cast_look_ -
static_cast<u32>(seen) <= kRecentLooks;
718 cast_changed_at_[index] = (
static_cast<u64>(e.id()) << 32) | cast_look_;
719 if (isMover(e))
return false;
721 if (recent) addMover(e);
726 if ((why & 63u) || heldMoved) ++cast_held_serial_;
727 if (!movers_.empty() && cast_look_ % 60 == 0 && dropStillMovers()) ++cast_held_serial_;
731 if (why & 127u) ++cast_serial_;
732 cast_registry_ = registry.
identity();
735 cast_held_vouched_ =
false;
741 mix(
ctx.materials ?
ctx.materials->revision() : 0);
742 mix(
ctx.materials ?
ctx.materials->builtVariantCount() : 0);
743 mix(
ctx.resources.meshesRevision());
744 mix(programs_built_);
745 mix(
ctx.render_context.programEpoch());
746 mix(
ctx.environment_texture_id != 0 ? 1u : 0u);
747 mix(
ctx.batch_shader_id);
748 mix(
ctx.white_texture_id);
751 std::memcpy(bits, &origin,
sizeof(bits));
752 mix(bits[0]); mix(bits[1]); mix(bits[2]);
754 std::memcpy(eye, &
ctx.view_eye,
sizeof(eye));
755 mix(
ctx.has_view_eye ? (
static_cast<u64>(eye[0]) << 32 | eye[1]) ^ (
static_cast<u64>(eye[2]) << 16) : 0u);
758 cast_held_vouched_ =
true;
766 proxy.entity = entity;
768 proxy.presentAt = now;
769 proxy.epoch = proxy_epoch_;
770 proxy.present = present;
772 proxy.meshRevision = proxy.resident ? proxy.resident->revision : 0;
773 proxy.materialStore =
ctx.materials ?
ctx.materials->revision() : 0;
775 proxy.materialRevision = proxy.material ? proxy.material->revision : 0;
776 const ecs::MeshInstances* set = present == 2u ?
collect.registry.
tryGet<ecs::MeshInstances>(entity) :
nullptr;
777 proxy.kept = (present == 0 || set !=
nullptr) && proxy.resident !=
nullptr && mesh.
parallax == glm::vec2(1.0f);
778 if (!proxy.kept)
return;
783 proxy.bend = proxy.material ?
ctx.materials->vertexBounds(mesh.
material) : 0.0f;
784 proxy.depthTested = mesh.
opaque || (proxy.material && proxy.material->depthTest);
785 proxy.model = glm::translate(glm::mat4(1.0f), proxy.position) * glm::mat4_cast(proxy.rotation)
786 * glm::scale(glm::mat4(1.0f), proxy.scale);
787 proxy.normalRows = glm::transpose(glm::inverse(glm::mat3(proxy.model)));
788 proxy.facts = meshFactsFromEntity(
ctx,
collect.registry, entity, mesh, proxy.resident, warned_bones_);
789 proxy.facts.normalTextureId = 0;
791 const glm::vec3 padding(proxy.bend);
792 orientedWorldAabb(proxy.position, proxy.rotation, proxy.scale, proxy.resident->localMin - padding,
793 proxy.resident->localMax + padding, proxy.boxCentre, proxy.boxHalf);
798 proxy.coarseRevision = proxy.coarse ? proxy.coarse->revision : 0;
802 const glm::vec3 localCentre = (lo + hi) * 0.5f;
803 const glm::vec3 localHalf = (hi - lo) * 0.5f;
804 const glm::vec3 reach(placementRadius * set->maxScale);
805 orientedWorldAabb(proxy.position, proxy.rotation, proxy.scale, set->originMin - reach, set->originMax + reach,
806 proxy.boxCentre, proxy.boxHalf);
807 const glm::mat4& entityModel = proxy.model;
808 const glm::mat3 entityLinear(entityModel);
809 const u32 count =
static_cast<u32>(set->transforms.size() / 16);
810 proxy.instances.resize(count);
812 for (
u32 i = 0; i < count; ++i) {
813 const f32* r = set->transforms.data() +
static_cast<usize>(i) * 16;
814 PlacedInstance& inst = proxy.instances[i];
815 inst.at = glm::vec3(entityModel * glm::vec4(r[3], r[7], r[11], 1.0f));
817 inst.radius = glm::length(inst.half);
818 inst.grow = std::sqrt(std::max({r[0] * r[0] + r[4] * r[4] + r[8] * r[8], r[1] * r[1] + r[5] * r[5] + r[9] * r[9],
819 r[2] * r[2] + r[6] * r[6] + r[10] * r[10]}));
821 glm::mat4 placed(1.0f);
822 placed[0] = {r[0], r[4], r[8], 0.0f};
823 placed[1] = {r[1], r[5], r[9], 0.0f};
824 placed[2] = {r[2], r[6], r[10], 0.0f};
825 placed[3] = {r[3], r[7], r[11], 1.0f};
826 const glm::mat4 model = entityModel * placed;
827 for (
u32 row = 0; row < 3; ++row) {
828 const glm::vec4 m{model[0][row], model[1][row], model[2][row], model[3][row]};
831 const glm::vec4 tint = mesh.
color * glm::vec4(r[12], r[13], r[14], r[15]);
833 if (proxy.resident->hasNormals) {
834 const glm::mat3 nrm = glm::transpose(glm::inverse(glm::mat3(model)));
842 auto& registry =
collect.registry;
844 const u32 index = entity.index();
845 if (index >= proxy_slot_.size()) proxy_slot_.resize(
static_cast<usize>(index) + 1, ~0u);
846 u32& slot = proxy_slot_[index];
848 slot =
static_cast<u32>(proxies_.size());
849 proxies_.emplace_back();
851 MeshProxy& proxy = proxies_[slot];
853 const Mesh* resident = mesh.mesh.isValid() ?
ctx.resources.getMesh(mesh.mesh) :
nullptr;
854 bool stale = proxy.entity != entity || proxy.epoch != proxy_epoch_
855 || resident != proxy.resident || (resident && resident->revision != proxy.meshRevision)
856 || registry.changedSince<ecs::Transform>(entity, proxy.builtAt)
857 || registry.changedSince<ecs::MeshRenderer>(entity, proxy.builtAt)
858 || (proxy.placed && registry.changedSince<ecs::MeshInstances>(entity, proxy.builtAt));
859 if (!stale && proxy.placed) {
860 const auto* set = registry.tryGet<ecs::MeshInstances>(entity);
862 stale = !set || coarse != proxy.coarse || (coarse && coarse->revision != proxy.coarseRevision);
864 const u64 store =
ctx.materials ?
ctx.materials->revision() : 0;
865 if (!stale && store != proxy.materialStore) {
866 const MaterialRecord* material = mesh.material != 0 &&
ctx.materials ?
ctx.materials->find(mesh.material) :
nullptr;
867 stale = material != proxy.material || (material && material->revision != proxy.materialRevision);
868 if (!stale) proxy.materialStore = store;
871 u8 present = proxy.present;
873 if (!stale && rulesChangedAt != 0 &&
ecs::tickAfter(rulesChangedAt, proxy.presentAt)) {
874 present = ruledOut(registry, entity);
876 stale = present != proxy.present;
877 proxy.presentAt = now;
880 deriveProxy(
collect, proxy, entity, mesh, transform, looked ? present : ruledOut(registry, entity), now);
882 }
else if (proxy.kept) {
886 if (registry.changeAuditEnabled()) {
888 deriveProxy(
collect, fresh, entity, mesh, transform, ruledOut(registry, entity), now);
891 const auto bits = [](
const auto& a,
const auto& b) {
return std::memcmp(&a, &b,
sizeof(a)) == 0; };
892 const bool same = fresh.kept && fresh.resident == proxy.resident && fresh.material == proxy.material
893 && bits(fresh.position, proxy.position) && bits(fresh.rotation, proxy.rotation) && bits(fresh.scale, proxy.scale)
894 && bits(fresh.boxCentre, proxy.boxCentre) && bits(fresh.boxHalf, proxy.boxHalf) && bits(fresh.model, proxy.model)
895 && bits(fresh.normalRows, proxy.normalRows) && bits(fresh.bend, proxy.bend) && fresh.depthTested == proxy.depthTested
896 && fresh.facts.hasNormals == proxy.facts.hasNormals && fresh.facts.lit == proxy.facts.lit
897 && fresh.facts.skinned == proxy.facts.skinned && fresh.facts.lightmapped == proxy.facts.lightmapped
898 && fresh.facts.tangents == proxy.facts.tangents && fresh.facts.opaque == proxy.facts.opaque
899 && fresh.facts.materialId == proxy.facts.materialId
900 && fresh.placed == proxy.placed && fresh.coarse == proxy.coarse && fresh.records == proxy.records
901 && fresh.instances.size() == proxy.instances.size()
902 && (fresh.instances.empty()
903 || std::memcmp(fresh.instances.data(), proxy.instances.data(), fresh.instances.size() *
sizeof(PlacedInstance)) == 0);
905 ++proxies_stale_total_;
906 if (!warned_stale_) {
907 warned_stale_ =
true;
908 ES_LOG_WARN(
"change audit: a kept mesh draw (entity {}) is not what its components derive now - something it"
909 " is derived from changed without a stamp or a revision", entity.index());
915 return proxy.kept ? &proxy :
nullptr;
927 Entity entity,
const glm::vec3& centre,
f32 radius,
const glm::quat& rotation) {
928 const glm::vec4 eye = collect.camera.eye;
929 glm::vec3 toward = eye.w > 0.5f ? glm::vec3(eye) - centre : glm::vec3(eye);
930 if (glm::dot(toward, toward) < 1e-12f)
return;
931 const glm::vec3 local = glm::inverse(rotation) * glm::normalize(toward);
935 const glm::vec3 up = rotation * upLocal *
radius;
936 const glm::vec3 right = rotation * glm::cross(upLocal, d) *
radius;
937 const f32 n =
static_cast<f32>(atlas.frames);
938 const f32 u0 =
static_cast<f32>(frame.x) / n, u1 =
static_cast<f32>(frame.x + 1u) / n;
939 const f32 v0 =
static_cast<f32>(frame.y) / n, v1 =
static_cast<f32>(frame.y + 1u) / n;
941 {centre - right - up, 0xFFFFFFFFu, {u0, v0}},
942 {centre + right - up, 0xFFFFFFFFu, {u1, v0}},
943 {centre + right + up, 0xFFFFFFFFu, {u1, v1}},
944 {centre - right + up, 0xFFFFFFFFu, {u0, v1}},
950 .shaderId = collect.frame_context.batch_shader_id,
952 .textureId = atlas.texture,
953 .depth = collect.camera.viewDepth(centre),
959 key.depthWrite =
false;
960 appendQuad(collect.buffer_pool, collect.draw_list, collect.clip_state, quad, key);
978struct PlacementReach {
984constexpr f32 kWholeTexture = 1.0e9f;
994 if (!(sizeOverDistance > 0.0f) || !
ctx.frame)
return 0.0f;
997 if (!(uvDensity > 0.0f))
return kWholeTexture;
998 const glm::mat4& vp =
ctx.view_projection;
999 const f32 ndcPerUnit = glm::length(glm::vec3(vp[0][1], vp[1][1], vp[2][1]));
1000 return ndcPerUnit * 0.5f *
ctx.frame->viewHeightPx() * sizeOverDistance / uvDensity;
1005 if (!(side > 0.0f) || !
ctx.frame)
return;
1006 if (mesh.texture.isValid())
ctx.frame->wantTextureSide(mesh.texture.id(), side);
1007 if (mesh.normalMap.isValid())
ctx.frame->wantTextureSide(mesh.normalMap.id(), side);
1008 if (material)
for (
const auto& b : material->textures)
if (b.texture.isValid())
ctx.frame->wantTextureSide(b.texture.id(), side);
1011template <
typename Emit>
1013 const ecs::MeshRenderer& mesh,
const glm::vec3& position,
const glm::quat& rotation,
1014 const glm::vec3& scale,
const Mesh& fine,
const Mesh* coarse,
1015 const glm::vec3& localCentre,
const glm::vec3& localHalf,
u32& records, PlacementReach& reach,
1017 static thread_local std::vector<u32> nearList, farList;
1020 const glm::mat4 entityModel = glm::translate(glm::mat4(1.0f), position) * glm::mat4_cast(rotation) * glm::scale(glm::mat4(1.0f), scale);
1021 const glm::mat3 entityLinear(entityModel);
1022 const bool eyeKnown =
ctx.has_view_eye;
1023 const u32 count =
static_cast<u32>(set.transforms.size() / 16);
1024 u32 tooFar = 0, outside = 0;
1027 const f32 entityGrow = std::max({std::abs(scale.x), std::abs(scale.y), std::abs(scale.z)});
1029 for (
u32 i = 0; i < count; ++i) {
1030 const f32* r = set.transforms.data() +
static_cast<usize>(i) * 16;
1031 const glm::vec3 at = glm::vec3(entityModel * glm::vec4(r[3], r[7], r[11], 1.0f));
1032 glm::vec3 centre, half;
1035 f32 distance = 0.0f;
1037 distance = glm::distance(at,
ctx.view_eye);
1038 const f32 centreDistance = glm::distance(centre,
ctx.view_eye);
1039 if (set.drawDistance > 0.0f && centreDistance - radius > set.drawDistance) { ++tooFar;
continue; }
1040 if (centreDistance + radius < set.minDistance)
continue;
1043 if (!collect.visible(centre, half,
false)) { ++outside;
continue; }
1045 const bool far = coarse && eyeKnown && set.lodDistance > 0.0f && distance > set.lodDistance;
1046 (far ? farList : nearList).push_back(i);
1049 const f32 placedGrow = std::sqrt(std::max({r[0] * r[0] + r[4] * r[4] + r[8] * r[8],
1050 r[1] * r[1] + r[5] * r[5] + r[9] * r[9],
1051 r[2] * r[2] + r[6] * r[6] + r[10] * r[10]}));
1052 const f32 gap = std::max(glm::distance(centre,
ctx.view_eye) - radius, 1e-3f);
1053 f32& best = far ? reach.coarse : reach.fine;
1054 best = std::max(best, entityGrow * placedGrow / gap);
1064 if (nearList.size() > room) nearList.resize(room);
1065 if (farList.size() > room - nearList.size()) farList.resize(room - nearList.size());
1066 records +=
static_cast<u32>(nearList.size() + farList.size());
1068 auto& buffers = collect.buffer_pool;
1069 const auto write = [&](
const std::vector<u32>& list,
const Mesh& geo) {
1070 if (list.empty())
return;
1074 for (
const u32 i : list) {
1075 const f32* r = set.transforms.data() +
static_cast<usize>(i) * 16;
1076 glm::mat4 placed(1.0f);
1077 placed[0] = {r[0], r[4], r[8], 0.0f};
1078 placed[1] = {r[1], r[5], r[9], 0.0f};
1079 placed[2] = {r[2], r[6], r[10], 0.0f};
1080 placed[3] = {r[3], r[7], r[11], 1.0f};
1081 const glm::mat4 model = entityModel * placed;
1082 for (
u32 row = 0; row < 3; ++row) {
1083 const glm::vec4 m{model[0][row], model[1][row], model[2][row], model[3][row]};
1086 const glm::vec4 tint = mesh.color * glm::vec4(r[12], r[13], r[14], r[15]);
1088 if (geo.hasNormals) {
1089 const glm::mat3 nrm = glm::transpose(glm::inverse(glm::mat3(model)));
1094 emit(geo, offset,
static_cast<u32>(list.size()));
1096 write(nearList, fine);
1097 if (coarse) write(farList, *coarse);
1100template <
typename Instance,
typename Emit>
1102 const std::vector<Instance>& instances,
const std::vector<u8>& cached,
const glm::vec3& scale,
1103 const Mesh& fine,
const Mesh* coarse,
u32& records, PlacementReach& reach, Emit&& emit) {
1104 static thread_local std::vector<u32> nearList, farList;
1107 const bool eyeKnown =
ctx.has_view_eye;
1108 const u32 count =
static_cast<u32>(instances.size());
1109 u32 tooFar = 0, outside = 0;
1111 const f32 entityGrow = std::max({std::abs(scale.x), std::abs(scale.y), std::abs(scale.z)});
1113 for (
u32 i = 0; i < count; ++i) {
1114 const Instance& inst = instances[i];
1115 f32 distance = 0.0f;
1117 distance = glm::distance(inst.at,
ctx.view_eye);
1118 const f32 centreDistance = glm::distance(inst.centre,
ctx.view_eye);
1119 if (set.drawDistance > 0.0f && centreDistance - inst.radius > set.drawDistance) { ++tooFar;
continue; }
1120 if (centreDistance + inst.radius < set.minDistance)
continue;
1123 if (!collect.visible(inst.centre, inst.half,
false)) { ++outside;
continue; }
1125 const bool far = coarse && eyeKnown && set.lodDistance > 0.0f && distance > set.lodDistance;
1126 (far ? farList : nearList).push_back(i);
1128 const f32 gap = std::max(glm::distance(inst.centre,
ctx.view_eye) - inst.radius, 1e-3f);
1129 f32& best = far ? reach.coarse : reach.fine;
1130 best = std::max(best, entityGrow * inst.grow / gap);
1139 if (nearList.size() > room) nearList.resize(room);
1140 if (farList.size() > room - nearList.size()) farList.resize(room - nearList.size());
1141 records +=
static_cast<u32>(nearList.size() + farList.size());
1143 auto& buffers = collect.buffer_pool;
1144 const auto write = [&](
const std::vector<u32>& list,
const Mesh& geo) {
1145 if (list.empty())
return;
1148 for (
const u32 i : list) {
1152 emit(geo, offset,
static_cast<u32>(list.size()));
1154 write(nearList, fine);
1155 if (coarse) write(farList, *coarse);
1168 const auto it = cluster_cuts_.find(entityId);
1169 if (it == cluster_cuts_.end() || !it->second.picked || it->second.usedAt +
kClusterCutFreshCollects < cluster_serial_) {
1172 triangles = it->second.indexCount / 3;
1173 clusters = it->second.clusters;
1178 const glm::vec3& position,
const glm::quat& rotation,
const glm::vec3& scale) {
1182 ClusterCut& cut = cluster_cuts_[entity.
id()];
1183 cut.usedAt = cluster_serial_;
1187 const glm::vec3 grow = glm::max(glm::abs(scale), glm::vec3(1e-12f));
1188 const f32 largest = std::max({grow.x, grow.y, grow.z});
1189 lod::ClusterEye eye;
1190 eye.flat = cluster_flat_;
1191 eye.scale = cluster_flat_ ? cluster_scale_ * largest : cluster_scale_;
1193 if (
ctx.has_view_eye) {
1194 const glm::vec3 offset = glm::inverse(rotation) * (
ctx.view_eye - position);
1195 eye.position = glm::vec3(scale.x < 0.0f ? -offset.x : offset.x, scale.y < 0.0f ? -offset.y : offset.y,
1196 scale.z < 0.0f ? -offset.z : offset.z) / grow;
1200 eye.scale = std::numeric_limits<f32>::max();
1205 if (stored && cut.picked && cut.eye.position == eye.position && cut.eye.scale == eye.scale
1206 && cut.eye.threshold == eye.threshold && cut.eye.flat == eye.flat) {
1212 if (!stored || signature != cut.signature || indexCount != cut.indexCount) {
1214 const u32 bytes = indexCount *
static_cast<u32>(
sizeof(
u32));
1216 device.
updateBuffer(cut.buffer, 0, cluster_indices_.data(), bytes);
1220 const u32 capacity = std::min(indexCount + indexCount / 2 + 3 * 128,
static_cast<u32>(hierarchy.
indices.size()));
1221 cluster_indices_.resize(capacity, 0);
1224 desc.size = capacity *
static_cast<u32>(
sizeof(
u32));
1225 desc.dynamic =
true;
1227 device.
resizeBuffer(cut.buffer, desc.size, cluster_indices_.data());
1236 cut.capacity = capacity;
1238 cut.signature = signature;
1239 cut.indexCount = indexCount;
1240 cut.clusters =
static_cast<u32>(cluster_picked_.size());
1241 cut.ids = cluster_picked_;
1253 auto& registry = collect_ctx.
registry;
1256 auto& draw_list = collect_ctx.
draw_list;
1264 const bool depthPass = shadowDepth || motion;
1270 const glm::mat4& vp =
ctx.view_projection;
1271 cluster_scale_ = glm::length(glm::vec3(vp[0][1], vp[1][1], vp[2][1])) * 0.5f * (
ctx.frame ?
ctx.frame->viewHeightPx() : 1080.0f);
1272 cluster_flat_ = glm::length(glm::vec3(vp[0][3], vp[1][3], vp[2][3])) < 1e-12f;
1273 cluster_meshes_ = cluster_triangles_ = cluster_source_triangles_ = cluster_rebuilt_ = cluster_drawn_ = 0;
1274 waiting_materials_ = 0;
1275 if (cluster_serial_ % 256 == 0 && !cluster_cuts_.empty()) {
1277 for (
auto it = cluster_cuts_.begin(); it != cluster_cuts_.end();) {
1280 it = cluster_cuts_.erase(it);
1287 if (!motion &&
ctx.track_motion &&
ctx.motion_frame % 256 == 0) {
1288 for (
auto it = poses_.begin(); it != poses_.end();) {
1289 if (it->second.frame + 8 <
ctx.motion_frame) {
1290 it = poses_.erase(it);
1306 u32 now = 0, rulesChangedAt = 0;
1307 proxies_kept_ = proxies_built_ = 0;
1309 if (
renderOrigin() != proxy_origin_ ||
ctx.materials != proxy_materials_ || registry.identity() != proxy_registry_) {
1310 if (registry.identity() != proxy_registry_) {
1312 proxy_slot_.clear();
1316 proxy_materials_ =
ctx.materials;
1317 proxy_registry_ = registry.identity();
1319 now = registry.beginChangeRead();
1320 rulesChangedAt = ruledOutChangedAt(registry);
1328#ifdef ES_PROFILE_COLLECT_PHASES
1329 constexpr bool phases =
true;
1331 constexpr bool phases =
false;
1333 f64 phase[5] = {0, 0, 0, 0, 0};
1335 f64 mark = timing && phases ? walkStart : 0.0;
1336 u32 walked = 0, coldDecompose = 0, lodGathers = 0, programAsks = 0, instanceRecords = 0;
1338 u32 prepassTaken = 0, prepassCutout = 0, prepassBent = 0, prepassNoProgram = 0;
1339 const auto tick = [&](
int slot) {
1340 if (!phases || !timing)
return;
1342 phase[slot] += now - mark;
1349 const bool selecting = motion && collect_ctx.
selection !=
nullptr;
1350 for (
auto entity : meshView) {
1351 if (split && !
ctx.causticReceivers && isMover(entity) != wantMovers)
continue;
1352 if (selecting && !collect_ctx.
selection->count(entity.
id()))
continue;
1356 const bool heated = !depthPass && collect_ctx.
weights.
entity == entity;
1362 described = &shaded;
1365 applyShading(shaded, shading);
1366 described = &shaded;
1368 const auto& mesh = *described;
1371 if (!mesh.enabled || (mesh.
indices.empty() && !mesh.mesh.isValid()))
continue;
1375 MeshProxy* kept = keeping && !heated ? retain(collect_ctx, entity, mesh, transform, now, rulesChangedAt) :
nullptr;
1376 glm::vec3 position, scale;
1381 if (selecting && kept->placed)
continue;
1382 if (motion && !selecting) {
1383 if (kept->placed)
continue;
1384 const Pose* pose = poseOf(
ctx, entity, kept,
false);
1385 if (!mesh.opaque || !pose || pose->frame !=
ctx.motion_frame || pose->previous == pose->current)
continue;
1387 position = kept->position;
1388 rotation = kept->rotation;
1389 scale = kept->scale;
1391 if (!transform.decomposed_) ++coldDecompose;
1395 transform.ensureDecomposed();
1396 position = shadowDepth
1397 ?
rebased(transform.worldPosition)
1404 : transform.worldRotation;
1405 scale = transform.worldScale;
1412 const Mesh* resident = kept ? kept->resident : mesh.mesh.isValid() ?
ctx.resources.getMesh(mesh.mesh) :
nullptr;
1416 if (depthPass && !resident)
continue;
1419 if (placements && (placements->
transforms.empty() || motion))
continue;
1423 if (
ctx.causticReceivers) {
1424 if (!mesh.opaque || (
ctx.materials &&
ctx.materials->usesSceneColor(mesh.material)))
continue;
1426 || (
ctx.materials &&
ctx.materials->hasUntrackedDepthHook(mesh.material));
1427 if (split && (isMover(entity) || deforming) != wantMovers)
continue;
1428 }
else if (shadowDepth && !mesh.castShadows && !(
ctx.rainCover && !mesh.opaque))
continue;
1431 if (motion && !selecting && !mesh.opaque)
continue;
1438 if (collect_ctx.
lod.
state && resident && !placements && !kept) {
1439 const auto* declared = registry.tryGet<
ecs::LODGroup>(entity);
1440 if (declared && declared->enabled) {
1444 reportLodAuthoring(levels, warned_lod_);
1460 emitImpostorCard(collect_ctx, *atlas, mesh, entity, centre, radius, transform.worldRotation);
1470 : (mesh.material != 0 &&
ctx.materials) ?
ctx.materials->find(mesh.material) :
nullptr;
1473 const f32 bend = kept ? kept->bend : material ?
ctx.materials->vertexBounds(mesh.material) : 0.0f;
1474 const bool depthTested = kept ? kept->depthTested : mesh.opaque || (material && material->
depthTest);
1477 f32 placementRadius = 0.0f;
1478 glm::vec3 placementCentre(0.0f), placementHalf(0.0f);
1479 if (placements && !kept) {
1483 placementCentre = (lo + hi) * 0.5f;
1484 placementHalf = (hi - lo) * 0.5f;
1487 const glm::vec3 reach(placements ? placementRadius * placements->
maxScale : 0.0f);
1488 const glm::vec3 localMin = placements ? placements->
originMin - reach
1491 const glm::vec3 localMax = placements ? placements->
originMax + reach
1494 const glm::vec3 padding(placements ? 0.0f : bend);
1496 glm::vec3 aabbCenter(0.0f), halfExtents(0.0f);
1498 aabbCenter = kept->boxCentre;
1499 halfExtents = kept->boxHalf;
1501 orientedWorldAabb(position, rotation, scale, localMin - padding, localMax + padding,
1502 aabbCenter, halfExtents);
1504 if (resident && !placements && !group && !kept) {
1505 skinnedWorldBounds(registry, entity, *resident, warned_bones_, aabbCenter, halfExtents);
1510 if (!collect_ctx.
visible(aabbCenter, halfExtents, depthTested)) {
1515 if (shadowDepth && !collect_ctx.
castsIntoView(aabbCenter, glm::length(halfExtents))) {
1527 const auto& state = *collect_ctx.
lod.
state;
1528 if (!state.recent(collect_ctx.
lod.
view, entity, 2, settled)) settled = 0;
1531 resident = levels.
mesh[shown];
1533 glm::vec3 centre(0.0f);
1537 auto& state = *collect_ctx.
lod.
state;
1544 state.remember(view, entity, level, unbiased, levels.
set.
count, screenSize);
1549 const u8 shown = state.drawn(view, entity, level, levels.
set.
count);
1551 resident = levels.
mesh[shown];
1559 glm::vec3 centre(0.0f);
1562 const glm::vec4 eye = collect_ctx.
camera.
eye;
1563 const f32 distance = eye.w > 0.5f ? std::max(glm::length(glm::vec3(eye) - centre) - radius, 1e-3f) : 1.0f;
1564 const f32 grow = std::max({std::abs(scale.x), std::abs(scale.y), std::abs(scale.z)});
1565 wantTexturesOf(
ctx, mesh, material, textureSideFor(
ctx, grow / distance, resident->
uvDensity));
1568 u32 textureId =
ctx.white_texture_id;
1569 if (mesh.texture.isValid()) {
1570 if (
Texture* tex =
ctx.resources.getTexture(mesh.texture)) {
1571 textureId = tex->getId();
1574 MeshDrawKeys keys{};
1579 kept ? kept->facts : meshFactsFromEntity(
ctx, registry, entity, mesh, resident, warned_bones_);
1580 if (facts.
skinned || !resident)
continue;
1581 keys = { meshVariant(facts.
hasNormals,
false,
false,
false,
false,
false,
false,
false,
false,
true, facts.
tangents), 0 };
1582 }
else if (motion) {
1585 const Pose* pose = poseOf(
ctx, entity, kept,
false);
1586 if (!pose || pose->frame !=
ctx.motion_frame
1587 || (pose->previous == pose->current && pose->bonesPrevious == pose->bonesCurrent)) {
1591 kept ? kept->facts : meshFactsFromEntity(
ctx, registry, entity, mesh, resident, warned_bones_);
1593 if (facts.
skinned && pose->bonesPrevious.size() != pose->bonesCurrent.size())
continue;
1594 keys = { meshVariant(facts.
hasNormals,
false,
false, facts.
skinned,
false,
false,
false,
false,
false,
true, facts.
tangents), 0 };
1598 keys = meshDrawFrom(
ctx, entity, facts, shadowDepth);
1600 keys = meshDrawFor(
ctx, registry, entity, mesh, resident, shadowDepth, warned_bones_, heated);
1602 const u32 normalTextureId = keys.normalTextureId;
1605 .stage =
ctx.current_stage,
1606 .layer = mesh.layer,
1607 .shaderId =
ctx.batch_shader_id,
1609 .textureId = textureId,
1610 .normalTextureId = normalTextureId,
1611 .shadowTextureId =
ctx.shadow_texture_id,
1612 .envTextureId =
ctx.environment_texture_id,
1619 if (!depthPass &&
ctx.frame) {
1620 const u32 reflection =
ctx.frame->planarTextureFor(entity);
1621 if (reflection != 0) {
1623 key.
planarIndex = draw_list.addPlanar(
ctx.frame->planarConstants());
1641 if (mesh.material != 0) {
1643 key.
shaderId = (m->shader != 0) ? m->shader :
ctx.batch_shader_id;
1651 key.
depthTest = mesh.opaque || m->depthTest;
1652 key.
depthWrite = mesh.opaque || m->depthWrite;
1653 key.
cull =
static_cast<u8>(m->cull);
1656 }
else if (mesh.lit &&
ctx.frame) {
1658 if (litProgram != 0) key.
shaderId = litProgram;
1677 if (resident && mesh_programs_[0] != 0) {
1681 const u32 poseSize = kept ? 0u : skinPose(registry, entity, *resident, pose_scratch_, warned_bones_);
1686 if (poseSize > 0 && !motion && !heated && !placements &&
ctx.frame) {
1688 cachedSkin = cache->bufferFor(entity);
1693 const bool skinned = poseSize > 0 && !cached;
1694 const u32 drawVariant = cached ? (keys.variant & ~8u) : keys.variant;
1701 const u32 residentShader = meshProgram(
ctx, drawVariant);
1703 if (resident->
isDrawable() && residentShader != 0) {
1707 const bool lightmapped = resident->
hasLightmapUV && !motion;
1711 const bool chunked = skinned && resident->
isChunked();
1712 const u32 paletteRecords = motion && skinned && !chunked
1714 static thread_local std::vector<u8> unplaced;
1719 dst = unplaced.data();
1732 if (!kept && morphShapes(registry, entity, *resident, shapes)) {
1733 key.
morphIndex = draw_list.addMorphShapes(shapes);
1740 key.
skinOffset = draw_list.addSkinMatrices(pose_scratch_.data(), poseSize);
1744 const glm::mat4 model = cached ? glm::mat4(1.0f)
1745 : kept ? kept->model
1746 : glm::translate(glm::mat4(1.0f), position)
1747 * glm::mat4_cast(rotation)
1748 * glm::scale(glm::mat4(1.0f), scale);
1751 for (
u32 row = 0; row < 3; ++row) {
1752 const glm::vec4 r{model[0][row], model[1][row], model[2][row], model[3][row]};
1758 const glm::mat3 nrm = cached ? glm::mat3(1.0f)
1759 : kept ? kept->normalRows : glm::transpose(glm::inverse(glm::mat3(model)));
1760 for (
u32 row = 0; row < 3; ++row) {
1768 glm::vec4 rect{0.0f};
1770 if (
Texture* atlas =
ctx.resources.getTexture(baked->lightmap)) {
1771 rect = baked->scaleOffset;
1781 const glm::vec4 still{0.0f};
1783 const glm::mat4 model = kept ? kept->model
1784 : glm::translate(glm::mat4(1.0f), position) * glm::mat4_cast(rotation) * glm::scale(glm::mat4(1.0f), scale);
1785 const glm::mat4 now =
ctx.motion_prev_view_projection * model;
1786 for (
u32 row = 0; row < 4; ++row) {
1787 const glm::vec4 r{now[0][row], now[1][row], now[2][row], now[3][row]};
1790 }
else if (motion) {
1794 const Pose& pose = *poseOf(
ctx, entity, kept,
false);
1795 const glm::vec4 jitter{
ctx.motion_prev_jitter, 0.0f, 0.0f};
1799 const glm::mat4 before = skinned ?
ctx.motion_prev_view_projection
1800 :
ctx.motion_prev_view_projection * pose.previous;
1801 for (
u32 row = 0; row < 4; ++row) {
1802 const glm::vec4 r{before[0][row], before[1][row], before[2][row], before[3][row]};
1805 if (skinned && !chunked) {
1806 for (
u32 bone = 0; bone < poseSize; ++bone) {
1807 const glm::mat4& m = pose.bonesPrevious[bone];
1808 for (
u32 row = 0; row < 3; ++row) {
1809 const glm::vec4 r{m[0][row], m[1][row], m[2][row], m[3][row]};
1814 }
else if (
ctx.track_motion && !shadowDepth) {
1815 trackPose(*poseOf(
ctx, entity, kept,
true),
ctx,
1816 poseSize > 0 ? glm::mat4(1.0f)
1817 : kept ? kept->model
1818 : glm::translate(glm::mat4(1.0f), position)
1819 * glm::mat4_cast(rotation)
1820 * glm::scale(glm::mat4(1.0f), scale),
1821 poseSize > 0 ? &pose_scratch_ :
nullptr);
1837 const u32 slot =
ctx.render_context.reflections().slotForBox(aabbCenter, halfExtents);
1839 if (volume || slot != 0) key.
probeIndex = draw_list.addProbe(probe);
1845 u32 materialProgram = 0;
1847 materialProgram =
ctx.materials->meshProgram(key.
materialId,
ctx.resources,
1851 ctx.gbuffer && !shadowDepth,
1854 if (materialProgram == 0) {
1855 if (!warned_material_) {
1856 warned_material_ =
true;
1857 ES_LOG_WARN(
"MeshRenderer: material {} has no mesh variant; using the mesh shader",
1863 key.
shaderId = materialProgram != 0 ? materialProgram : residentShader;
1868 bool previewing =
false;
1869 if (!depthPass && !motion && key.
shaderId != 0) {
1872 const u32 preview = previewProgram(
ctx, drawVariant);
1884 if (shadowDepth && material &&
ctx.materials
1885 && (
ctx.materials->hasVertexHook(mesh.material) ||
ctx.materials->castsCutoutShadow(mesh.material))) {
1886 const u32 bentDepth =
ctx.materials->shadowProgram(mesh.material,
ctx.resources,
1888 if (bentDepth != 0) {
1901 }
else if (cutout) {
1905 if (key.
depthShaderId != 0) ++prepassTaken;
else ++prepassCutout;
1911 if (key.
depthShaderId != 0) ++prepassTaken;
else ++prepassBent;
1913 u32 depthVariant = kept ? meshDrawFrom(
ctx, entity, kept->facts,
true).variant
1914 : meshDrawFor(
ctx, registry, entity, mesh, resident,
true, warned_bones_).variant;
1915 if (cached) depthVariant &= ~8u;
1917 if (key.
depthShaderId != 0) ++prepassTaken;
else ++prepassNoProgram;
1925 if (wire) key.
depthBias = kWireFillBias;
1931 u32 cutIndexCount = 0;
1933 const auto emitRange = [&](
const Mesh& geo,
u32 offset,
u32 count,
u32 firstIndex,
u32 indexCount) {
1939 pushBatchDraw(draw_list, clips, offset, 0, firstIndex, indexCount, drawn);
1941 const u32 tipProgram =
ctx.materials->meshProgram(key.
materialId,
ctx.resources, geo.hasNormals, skinned,
1943 geo.hasTangents,
true,
false);
1944 if (tipProgram != 0) {
1950 pushBatchDraw(draw_list, clips, offset, 0, firstIndex, indexCount, tips);
1954 const auto emit = [&](
const Mesh& geo,
u32 offset,
u32 count) {
1959 PlacementReach reach;
1961 emitKeptPlacements(
ctx, collect_ctx, *placements, kept->instances, kept->records, scale, *resident,
1962 placementCoarse, instanceRecords, reach, emit);
1964 emitPlacements(
ctx, collect_ctx, *placements, mesh, position, rotation, scale, *resident, placementCoarse,
1965 placementCentre, placementHalf, instanceRecords, reach, emit);
1967 const f32 fineSide = textureSideFor(
ctx, reach.fine, resident->
uvDensity);
1968 const f32 coarseSide = placementCoarse ? textureSideFor(
ctx, reach.coarse, placementCoarse->
uvDensity) : 0.0f;
1969 wantTexturesOf(
ctx, mesh, material, std::max(fineSide, coarseSide));
1979 if (
const ClusterCut* cut = clusterCut(collect_ctx, entity, *resident, position, rotation, scale)) {
1980 cutBuffer = cut->buffer;
1981 cutIndexCount = cut->indexCount;
1984 cluster_drawn_ += cut->clusters;
1985 cluster_triangles_ += cut->indexCount / 3;
1986 cluster_source_triangles_ += resident->
indexCount / 3;
1993 for (
const u32 id : cut->ids) {
1994 const u32 count = hierarchy.
clusters[id].indexCount;
1998 const glm::vec4 ink = clusterInk(
id);
2002 pushBatchDraw(draw_list, clips, offset, 0, first, count, drawn);
2013 static thread_local std::vector<glm::mat4> chunkPose;
2019 u32 record = instOffset;
2026 const Pose& pose = *poseOf(
ctx, entity, kept,
false);
2029 for (
u32 row = 0; row < 3; ++row) {
2030 const glm::vec4 r{m[0][row], m[1][row], m[2][row], m[3][row]};
2039 }
else if (!inked) {
2040 emit(*resident, instOffset, 1);
2044 if (wire && resident->
hasEdges()) {
2067 f32 angle = 2.0f * std::atan2(rotation.z, rotation.w);
2068 bool rotated = std::abs(angle) > 0.001f;
2069 f32 cosA = 1.0f, sinA = 0.0f;
2071 cosA = std::cos(angle);
2072 sinA = std::sin(angle);
2076 bool tinted = tint != 0xFFFFFFFFu;
2078 scratch_.resize(mesh.
vertices.size());
2081 glm::vec2 local(in.position.x * scale.x, in.position.y * scale.y);
2082 glm::vec3 world = rotated
2083 ? glm::vec3(position.x + local.x * cosA - local.y * sinA,
2084 position.y + local.x * sinA + local.y * cosA,
2086 : glm::vec3(position.x + local.x, position.y + local.y, position.z);
2087 scratch_[v] = { world, tinted ? mulColor(in.color, tint) : in.color, in.uv };
2091 scratch_.data(),
static_cast<u32>(scratch_.size()),
2099 profiler.add(
"render.collect.mesh.decompose", phase[0]);
2100 profiler.add(
"render.collect.mesh.lod", phase[1]);
2101 profiler.add(
"render.collect.mesh.bounds", phase[2]);
2102 profiler.add(
"render.collect.mesh.program", phase[3]);
2103 profiler.add(
"render.collect.mesh.emit", phase[4]);
2109 switch (
ctx.purpose) {
2111 profiler.add(
"render.collect.mesh.scene.walks", 1.0);
2112 profiler.add(
"render.collect.mesh.scene.visits",
static_cast<f64>(walked));
2113 profiler.add(
"render.collect.mesh.scene.ms", spent);
2116 profiler.add(
"render.collect.mesh.depth.walks", 1.0);
2117 profiler.add(
"render.collect.mesh.depth.visits",
static_cast<f64>(walked));
2118 profiler.add(
"render.collect.mesh.depth.ms", spent);
2121 profiler.add(
"render.collect.mesh.motion.walks", 1.0);
2122 profiler.add(
"render.collect.mesh.motion.visits",
static_cast<f64>(walked));
2123 profiler.add(
"render.collect.mesh.motion.ms", spent);
2126 profiler.add(
"render.collect.mesh.other.walks", 1.0);
2127 profiler.add(
"render.collect.mesh.other.visits",
static_cast<f64>(walked));
2128 profiler.add(
"render.collect.mesh.other.ms", spent);
2165 if (
ctx.materials !=
nullptr) {
2168 if (compiled_this_frame_ > 0) {
2171 compiled_this_frame_ = 0;
The single submission face: the ONLY place a DrawCommand is assembled.
The rotation that turns a card to a view.
A mesh that turns to whoever looks at it.
Per-frame CPU scope timing (ES_PROFILE_SCOPE) read by the editor profiler.
#define ES_PROFILE_COUNTER(name, value)
Which direction each picture of an impostor atlas is taken from, and which picture a view is shown.
A picture of a mesh, taken from many directions, drawn in its place once it is small.
The cheaper geometry that may stand in for a MeshRenderer once it is small.
Logging utilities for ESEngine.
#define ES_LOG_WARN(...)
Logs a warning message.
Engine-side material registry — the resolved "how to draw" for a material handle.
Shared mesh LOD eligibility and local bounds for drawing and shadow fitting.
Arbitrary-geometry 2D mesh renderable (deformed sprites, polygons, water surfaces,...
Geometry that lives on the GPU rather than in a frame.
The shapes one draw is blended towards: which targets, and how far.
Conservative mesh reach and affine stretch for native placements.
The indirect light where ONE draw stands, when a grid was baked for it.
Rendering context containing all renderer state.
Frame resources and the shared scene rendering contract.
Parser for unified .esshader file format.
Skinned meshes posed once a frame by a compute shader, into vertices every pass then draws as they ar...
GPU texture abstraction for 2D images.
static FrameProfiler & get()
static constexpr GfxContent transient()
Abstract graphics device interface.
BufferHandle createBuffer(const BufferDesc &desc, GfxContent content, const void *initialData)
Creates a buffer with fixed capacity and optional initial contents.
bool programReady(ShaderHandle program)
Whether program can be drawn with now, without waiting: linked, or finished linking in the background...
bool skipPendingPrograms() const
void deleteBuffer(BufferHandle buffer)
Deletes a buffer.
void updateBuffer(BufferHandle buffer, u32 offsetBytes, const void *data, u32 sizeBytes)
Updates a sub-range of a buffer; must fit within its capacity.
void resizeBuffer(BufferHandle buffer, u32 sizeBytes, const void *data)
Re-specifies a buffer's store with a new capacity, discarding prior contents.
u64 deviceGeneration() const
Which generation of the device the live GPU objects belong to.
void collect(RenderCollectContext &ctx) override
bool castInputs(RenderFrameContext &ctx, ecs::Registry ®istry, u64 &key) override
For a plugin that casts: one number for everything its depth collect reads apart from the shadow view...
bool clusterInspect(u32 entityId, u32 &triangles, u32 &clusters) const override
What the last frames drew of the Cluster LOD mesh of the entity entityId.
RenderPrewarmResult prewarm(RenderFrameContext &ctx, ecs::Registry ®istry, const Entity *entities, u32 count, bool shadowPasses) override
RenderPrewarmResult prewarmFacts(RenderFrameContext &ctx, const MeshProgramFacts *facts, u32 count, bool shadowPasses, bool residentGeometry)
Ready programs from facts already gathered — the door a PREPARED cell comes through,...
RenderPrewarmResult prewarmDocument(RenderFrameContext &ctx, const MeshDocumentRecord *rows, u32 count, bool shadowPasses) override
The same readiness, asked of a PREPARED cell's own description.
void init(RenderFrameContext &ctx) override
bool castHeldInputs(u64 &key) const override
Buffers, the layout that describes them, and the bounds culling reads.
std::vector< MeshSkinChunk > skinChunks
VertexLayoutHandle layout
BufferHandle vertexBuffer
resource::VertexBufferHandle vertices
resource::IndexBufferHandle indices
std::shared_ptr< const lod::ClusterHierarchy > clusters
BufferHandle edgeIndexBuffer
std::vector< u16 > skinChunkBones
TextureHandle morphTexture
The frame's probe volumes, and the trilinear read through them.
bool sampleBox(const glm::vec3 ¢re, const glm::vec3 &half, ProbeConstants &out, bool perPixel=false) const
The volume a whole object stands in, by its world box rather than its origin.
void noteDraw(bool perPixel) const
Counts a draw that read a volume this frame, per pixel or per object: what the stats say a frame paid...
2D texture for GPU rendering
Central container for all entities and components.
bool anyChangedSince(u32 tick) const
Whether any T was written, added or removed after tick: the question a frame that may skip its walk a...
u32 activityEpoch() const
usize countOf() const
How many entities have a T.
bool anyChangedSinceWhere(u32 tick, Visit &&visit) const
Calls visit(entity) for each T written or added after tick, until it returns true; returns whether on...
bool has(Entity entity) const
Checks if an entity has a specific component.
u32 beginChangeRead()
For a reader about to look: the tick it is looking at, after which the clock moves on.
u64 identity() const
Which registry this is, never shared with another made in this process (a registry assigned over this...
T * tryGet(Entity entity)
Tries to get a component from an entity.
bool isValid() const
Checks if the handle references a valid resource.
static ParsedShader parse(const std::string &source)
Parses shader source into structured format (no include support).
static std::string assembleStage(const ParsedShader &parsed, ShaderStage stage, const std::string &platform="", const std::vector< std::string > &features={}, ShaderTargetLanguage target=ShaderTargetLanguage::GLSL_ES300)
Assembles final GLSL source for a specific stage.
constexpr const char * MESH
glm::quat facing(i32 mode, const glm::mat4 &viewProjection, const glm::vec4 &eye, const glm::vec3 &position)
The rotation a card standing at position is drawn with in this view.
bool tickAfter(u32 a, u32 b)
Whether stamp a is later than tick b, across a wrap of the counter (stamps are kept within half its r...
constexpr u64 combine(u64 h, u64 v)
constexpr u64 kFnv64Offset
glm::uvec2 nearestFrame(const glm::vec3 &d, u32 frames)
The frame taken nearest d, a direction from the object toward the viewer in the object's own space.
glm::vec3 frameDirection(u32 i, u32 j, u32 frames)
The direction, from the object toward the camera, that frame (i, j) is taken from.
glm::vec3 pictureUp(const glm::vec3 &d)
The up a picture is taken with from d: world up laid flat across the view.
u8 selectLevel(const LevelSet &set, f32 size, u8 current)
The level size asks for, given the one shown last.
f32 screenRelativeSize(const glm::mat4 &viewProjection, const glm::vec3 ¢re, f32 radius)
How much of the viewport's HEIGHT a sphere covers: 1 = one screen high.
u32 selectClusters(const ClusterHierarchy &hierarchy, const ClusterEye &eye, std::vector< u32 > &out)
The clusters eye draws, in the hierarchy's order, into out. Returns the indices they hold together.
u64 cutSignature(const std::vector< u32 > &picked)
A number that changes when the picked clusters do: two cuts with the same one are drawn from the same...
constexpr u8 kCulled
The level of an object small enough that nothing is drawn for it.
void boundingSphere(const glm::vec3 &position, const glm::quat &rotation, const glm::vec3 &scale, const glm::vec3 &localMin, const glm::vec3 &localMax, glm::vec3 &outCentre, f32 &outRadius)
The sphere a group is measured by: its centre in the world and its radius.
void assembleCut(const ClusterHierarchy &hierarchy, const std::vector< u32 > &picked, u32 vertexBase, std::vector< u32 > &out)
The picked clusters' indices, one run after another, into out.
void transformedBox(const glm::mat3 &parent, const f32 *rows, const glm::vec3 &origin, const glm::vec3 &localCentre, const glm::vec3 &localHalf, glm::vec3 ¢re, glm::vec3 &half)
f32 radius(const glm::vec3 &lo, const glm::vec3 &hi, f32 displacement)
Handle< esengine::Shader > ShaderHandle
Handle to a shader resource.
Handle< esengine::Texture > TextureHandle
Handle to a texture resource.
Handle< esengine::Mesh > MeshHandle
Handle to GPU-resident geometry.
static constexpr u32 MORPH_TEXTURE_WIDTH
void appendQuad(TransientBufferPool &pool, DrawList &drawList, const ClipState &clips, const BatchVertex quad[4], const BatchDrawKey &key)
void meshLocalBounds(const Mesh &base, const Mesh *coarse, f32 displacement, glm::vec3 &lo, glm::vec3 &hi)
static constexpr u32 MESH_INSTANCE_STRIDE
double es_profile_now_ms()
std::uint64_t u64
Unsigned 64-bit integer.
constexpr u64 kClusterCutIdleCollects
Collects a cut may go undrawn before its buffer is given back. A frame has several: the scene's,...
static constexpr u32 MESH_INSTANCE_TEXELS
void pushBatchDraw(DrawList &drawList, const ClipState &clips, u32 vertexByteOffset, u32 vertexCount, u32 indexOffset, u32 indexCount, const BatchDrawKey &key)
Atomic primitive: assemble + clip + push one DrawCommand for an index range ALREADY written into (or,...
std::size_t usize
Size type for indexing and sizes.
static constexpr u32 MESH_INSTANCE_TEXEL_LIGHTMAP
static constexpr u32 MESH_INSTANCE_TEXEL_TINT
static constexpr u32 MESH_INSTANCE_MAX_RECORDS
std::int16_t i16
Signed 16-bit integer.
glm::vec3 parallaxedWorldPosition(ecs::Transform &transform, const glm::vec2 ¶llax, const CameraView &camera)
u32 packColor(f32 r, f32 g, f32 b, f32 a)
bool shadesAsClay(ShadingMode mode)
Whether a mode draws meshes as clay (the lit neutral surface).
constexpr f32 kClusterPixelError
The error a clustered mesh may show, in pixels of the scene view, before a finer cluster is drawn.
std::uint32_t u32
Unsigned 32-bit integer.
glm::mat4 modelFromOrigin(const glm::mat4 &model, const glm::dvec3 &origin)
A model placed from origin, as it is placed from the origin now.
glm::vec3 rebased(const glm::vec3 &world)
A world position as the frame draws it: from the origin.
std::uint8_t u8
Unsigned 8-bit integer.
ShadingMode
What a mesh is drawn WITH in a view, whatever its own material says.
@ Wireframe
A dark surface with every triangle edge drawn on it, hidden edges hidden.
@ Shaded
Each mesh as authored: its material, its textures, its light.
@ Albedo
Base colour and texture with no light and no material: what was painted.
static constexpr u32 MESH_MAX_ACTIVE_MORPHS
glm::dvec3 & renderOrigin()
The origin, in world units. A double, as the world positions it is taken from are far from zero.
SkinCacheUsage
A mesh's own word on the cache (MeshSkin::skinCache).
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.
double f64
64-bit floating point
static constexpr u32 MESH_INSTANCE_TEXEL_NORMAL
constexpr u64 kClusterCutFreshCollects
void orientedWorldAabb(const glm::vec3 &position, const glm::quat &rotation, const glm::vec3 &scale, const glm::vec3 &localMin, const glm::vec3 &localMax, glm::vec3 &outCentre, glm::vec3 &outHalf)
The world AABB of a turned box: its centre and half-extents, from a local box and the position,...
bool gatherLodLevels(resource::ResourceManager &resources, const ecs::LODGroup &group, const Mesh &base, LodLevels &out)
static constexpr u32 MESH_INSTANCE_TEXEL_MODEL
const Mesh * placementCoarseMesh(resource::ResourceManager &resources, const Mesh &base, const ecs::MeshInstances &placements)
static EstellaContext & ctx()
@ Lines
Every two indices a line segment: a mesh's edges, for a diagnostic view.
float f32
32-bit floating point
static constexpr u32 MESH_MAX_BONES
Non-geometry attributes of a batch draw — everything needed to build the sort key + DrawCommand.
i16 depthBias
Depth-buffer units toward the eye.
GfxTopology topology
How the indices assemble.
BufferHandle vertexBuffer
u8 cull
CullMode: 0 = none, 1 = back, 2 = front.
VertexLayoutHandle vertexLayout
One vertex of the shared batch stream.
f32 viewDepth(const glm::vec3 &worldPos) const
How near worldPos is to the viewer, larger = nearer — the order the sort key wants,...
Entity identifier with packed index + generation.
constexpr u32 id() const
Returns the raw packed value for FFI serialization.
bool intersectsAABB(const glm::vec3 ¢er, const glm::vec3 &halfExtents) const
const Mesh * mesh[lod::kMaxStandIns+1]
A material's resolved render state (P0) plus its packed std140 constants (P1).
What a renderable's program key is made of, with no say in where the facts came from — a live entity'...
One piece a skinned mesh is drawn in, when its bones are more than one draw can carry.
One draw's shapes, laid out as the texels they are written as.
The indirect light one instance stands in — both halves of it.
bool follow
Read the level view settled on instead of choosing one: what a shadow cast for that view's picture is...
lod::SelectionCounts * counts
lod::LodViewState * state
const ClipState & clip_state
u32 culled
How many renderables this collect's frustum rejected.
WeightTarget weights
The one skinned draw this view colours by a joint's weights, if any.
RenderFrameContext & frame_context
ShadingMode shading
How the meshes of THIS collect are shaded. Shaded unless the view asked for another mode; a collect t...
bool castsIntoView(const glm::vec3 ¢re, f32 radius)
Whether a caster bounded by a sphere can shade anything the camera sees. True where this collect asks...
bool visible(const glm::vec3 ¢re, const glm::vec3 &halfExtents, bool depthTested)
Whether a renderable bounded by centre / halfExtents is drawn.
TransientBufferPool & buffer_pool
const std::unordered_set< u32 > * selection
A motion collect that draws the editor's selection mask instead (RenderFrame::collectSelection): only...
An impostor's pictures: the atlas texture and how many frames along its side.
What readying a set of renderables' programs found. Counts, not JSON: this crosses no boundary and pa...
bool addKey(u32 variant)
Whether this key is already in the set; adds it if not.
static u64 materialKey(u32 materialId, bool normals, bool skinned, bool envMapped, bool lightmapped, bool tangents=false)
What a material program is asked for, as one comparable value.
void addMaterialKey(u64 key)
Turns the MeshRenderer beside it to face each view that draws it.
Stands a card in for the MeshRenderer beside it once the object covers less than screenSize of the vi...
Stand-in geometry chosen by how much of the screen the object covers.
Many placements of the one mesh a MeshRenderer draws, as ONE renderable.
glm::vec3 originMin
The corners of the instances' ORIGINS and the greatest scale among them: with the mesh's own reach,...
std::vector< f32 > transforms
Sixteen floats an instance: the model's three rows (translation in .w) then its tint RGBA,...
Where a MeshRenderer's BAKED light comes from: the atlas, and the rectangle of it this object occupie...
What SHAPE a MeshRenderer is in: how far it is blended towards each of the shapes its mesh carries.
u32 material
Custom material ID (0 = use default batch shader).
glm::vec4 color
Color tint multiplied with per-vertex colors (white = unchanged).
resource::TextureHandle texture
Texture sampled by the mesh UVs (invalid = untextured, vertex colors only).
glm::vec2 parallax
Parallax scroll factor per axis. 1 = moves with the world (default, no parallax); <1 = scrolls slower...
bool opaque
Drawn as an opaque surface: no blending, and it takes part in depth — which is what lets one mesh hid...
resource::MeshHandle mesh
Geometry from an .esmesh, drawn INSTEAD of the inline vertices.
What deforms a MeshRenderer: the entities its Joints channel indexes.
A mesh's clusters and the indices they name, every level together.
std::vector< u32 > indices
std::vector< Cluster > clusters