17#include <unordered_set>
26#include <glm/gtc/matrix_access.hpp>
27#include <glm/gtc/quaternion.hpp>
32#include <unordered_map>
33#include <unordered_set>
120 glm::vec4
eye{0.0f, 0.0f, 1.0f, 0.0f};
129 if (
eye.w < 0.5f)
return glm::dot(worldPos, glm::vec3(
eye));
130 return -glm::length(worldPos - glm::vec3(
eye));
153 glm::mat4 invVP = glm::inverse(viewProjection);
154 glm::vec4 bl = invVP * glm::vec4(-1.0f, -1.0f, 0.0f, 1.0f);
155 glm::vec4 tr = invVP * glm::vec4( 1.0f, 1.0f, 0.0f, 1.0f);
157 view.
left = bl.x / bl.w;
158 view.
bottom = bl.y / bl.w;
159 view.
right = tr.x / tr.w;
160 view.
top = tr.y / tr.w;
220 u64& word =
keys[variant / 64];
221 const u64 bit = 1ull << (variant % 64);
222 if (word & bit)
return false;
233 bool lightmapped,
bool tangents =
false) {
234 return (
static_cast<u64>(materialId) << 5) | (tangents ? 16u : 0u) | (lightmapped ? 8u : 0u) | (normals ? 4u : 0u)
235 | (skinned ? 2u : 0u) | (envMapped ? 1u : 0u);
254 std::sort(sorted.begin(), sorted.end());
257 for (
u64 word :
keys) mix(word);
258 for (
u64 k : sorted) mix(k);
362 if (entity ==
excluded)
return false;
378 bool visible(
const glm::vec3& centre,
const glm::vec3& halfExtents,
bool depthTested) {
382 if (!
frustum.intersectsAABB(centre, halfExtents))
return false;
466 return camera.
eye.w < 0.5f ? glm::vec3(camera.
eye) : glm::vec3(camera.
eye) - worldPos;
476inline glm::vec3
ribbonSide(
const glm::vec3& tangent,
const glm::vec3& worldPos,
477 const CameraView& camera,
const glm::vec3& lastSide) {
478 const glm::vec3 side = glm::cross(
towardViewer(worldPos, camera), tangent);
479 const f32 len2 = glm::dot(side, side);
480 return len2 > 1e-12f ? side / std::sqrt(len2) : lastSide;
497 const f32 n = rotation.w * rotation.w + rotation.z * rotation.z;
498 if (n <= 1e-12f)
return {1.0f, 0.0f};
499 return {(rotation.w * rotation.w - rotation.z * rotation.z) / n,
500 2.0f * rotation.w * rotation.z / n};
512 const glm::vec3& scale,
const glm::vec3& localMin,
513 const glm::vec3& localMax, glm::vec3& outCentre,
514 glm::vec3& outHalf) {
515 const glm::mat3 basis = glm::mat3_cast(rotation);
516 const glm::vec3 scaledHalf = glm::abs((localMax - localMin) * 0.5f * scale);
517 outCentre = position + basis * ((localMin + localMax) * 0.5f * scale);
519 glm::dot(glm::abs(glm::row(basis, 0)), scaledHalf),
520 glm::dot(glm::abs(glm::row(basis, 1)), scaledHalf),
521 glm::dot(glm::abs(glm::row(basis, 2)), scaledHalf),
531 const f32 c = std::abs(turn.x), s = std::abs(turn.y);
532 const glm::vec3 extent = glm::abs(half);
533 return {c * extent.x + s * extent.y, s * extent.x + c * extent.y, extent.z};
590 (void)
ctx; (void)registry; (void)cache;
594 const Entity* entities,
u32 count,
bool shadowPasses) {
595 (void)
ctx; (void)registry; (void)entities; (void)count; (void)shadowPasses;
609 (void)
ctx; (void)rows; (void)count; (void)shadowPasses;
620 virtual const char*
collectScope()
const {
return "render.collect.other"; }
Per-frame shader constants shared via a single Uniform Buffer Object.
The six planes a projection bounds, and the box test against them.
Which representation an object's size on screen asks for.
What a view knows about an object's level: what it chose, why, and whether something is being held up...
What this view already has something solid in front of.
Central ECS registry for entity and component management.
The point the frame is drawn relative to: a world far from zero loses precision in single floats,...
Central resource management system.
Core type definitions and utilities for ESEngine.
How a view shades the meshes it draws: as authored, clay, flat albedo, wireframe, or one part of the ...
Maps a material handle to its resolved record. Owned by RenderContext so it is reachable from both th...
The depths this view is blocked at, and the test a bound asks it.
virtual ~RenderTypePlugin()=default
virtual bool castsShadows() const
Whether what this plugin draws belongs in a shadow map.
virtual const char * collectScope() const
What this plugin's collect is called in a frame profile.
virtual bool drawsScreenUI() const
Whether this plugin can draw an entity that lives in a UI tree.
virtual void collect(RenderCollectContext &ctx)=0
virtual u32 castMoverCount() const
virtual bool castHeldInputs(u64 &) const
virtual void init(RenderFrameContext &ctx)
virtual bool drawsMotion() const
virtual bool castInputs(RenderFrameContext &, ecs::Registry &, u64 &)
For a plugin that casts: one number for everything its depth collect reads apart from the shadow view...
virtual RenderPrewarmResult prewarmDocument(RenderFrameContext &ctx, const MeshDocumentRecord *rows, u32 count, bool shadowPasses)
The same readiness, asked of a PREPARED cell's own description.
virtual RenderPrewarmResult prewarm(RenderFrameContext &ctx, ecs::Registry ®istry, const Entity *entities, u32 count, bool shadowPasses)
virtual bool clusterInspect(u32, u32 &, u32 &) const
What the last frames drew of the Cluster LOD mesh of the entity entityId.
virtual void scheduleSkins(RenderFrameContext &ctx, ecs::Registry ®istry, SkinCache &cache)
Make ready the programs entities will be asked for, drawing none.
Central container for all entities and components.
Levels remembered per (view, entity) pair.
Central manager for GPU resources.
u64 fnv1aBytes(u64 h, const void *data, usize bytes)
constexpr u64 kFnv64Offset
RenderPurpose
What a collect is FOR — the phase, not a feature the geometry has.
std::int32_t i32
Signed 32-bit integer.
std::uint64_t u64
Unsigned 64-bit integer.
glm::vec3 flatHalfExtents(const glm::vec2 &turn, const glm::vec3 &half)
World AABB half-extents of a flat box turned by turn (from flatTurnZ). |R| * half,...
std::size_t usize
Size type for indexing and sizes.
constexpr Entity INVALID_ENTITY
Invalid entity sentinel value.
glm::vec3 parallaxedWorldPosition(ecs::Transform &transform, const glm::vec2 ¶llax, const CameraView &camera)
ParallaxAnchor & parallaxAnchor()
glm::vec3 towardViewer(const glm::vec3 &worldPos, const CameraView &camera)
Decomposes transform and returns its world position shifted toward the camera by (1 - parallax); fact...
std::uint32_t u32
Unsigned 32-bit integer.
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.
static constexpr u32 MESH_VARIANTS
ShadingMode
What a mesh is drawn WITH in a view, whatever its own material says.
@ Shaded
Each mesh as authored: its material, its textures, its light.
glm::dvec3 & renderOrigin()
The origin, in world units. A double, as the world positions it is taken from are far from zero.
CameraView computeCameraView(const glm::mat4 &viewProjection)
glm::vec2 flatTurnZ(const glm::quat &rotation)
The cos/sin of the turn a plane renderable draws with: its entity's rotation about Z,...
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,...
static EstellaContext & ctx()
glm::vec3 ribbonSide(const glm::vec3 &tangent, const glm::vec3 &worldPos, const CameraView &camera, const glm::vec3 &lastSide)
The side vector a ribbon widens along: perpendicular to both its path and the viewer,...
glm::vec4 cameraFromViewProjection(const glm::mat4 &viewProjection)
Where the frame is seen from, read out of the matrix that projects it.
float f32
32-bit floating point
What every plugin needs to know about the camera, derived once per collect from the inverse view-proj...
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.
constexpr u32 index() const
Gets the entity index.
What a renderable's program key is made of, with no say in where the facts came from — a live entity'...
Where parallax is measured from, when it is not the camera drawing the frame.
Which view is looking, where its level choices are kept, and where the selections it makes are counte...
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
u32 only_root
Nonzero: this collect is one screen root's, and an entity of the domain under any other root is not i...
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.
u32 occluded
How many of those culled an OCCLUDER refused.
const OcclusionView * occlusion
What this view is already blocked by, or null for a collect that must not ask — a shadow face looks f...
f32 sortDepth(const glm::vec3 &worldPos) const
The sort depth of a draw anchored at worldPos.
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 accepts(Entity entity) const
Whether entity belongs to THIS collect.
const std::vector< u32 > * screen_root_by_index
With only_root: by entity index, the screen root each entity of the domain draws under (ecs::UISystem...
const std::unordered_map< u32, i32 > * ui_tree_layers
The layer of each emitter and plain Sprite a Canvas holds, by entity id, or null.
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...
i32 treeLayer(Entity entity, i32 authored) const
The layer entity draws at: its place in a Canvas's tree, unless its author named one.
const Frustum * shadowReceivers
A sun's shadow map only: the camera's frustum, which is what its shadows are worth drawing for,...
bool visible(const glm::vec3 ¢re, const glm::vec3 &halfExtents, bool depthTested)
Whether a renderable bounded by centre / halfExtents is drawn.
bool isOverlay() const
Whether this collect is the frame's screen overlay.
TransientBufferPool & buffer_pool
u32 lightsSpared
Light slots the lit quads of this collect were spared: per quad, the loop lights that cannot reach it...
u32 shadowCulled
How many casters that left out.
const std::unordered_set< u32 > * selection
A motion collect that draws the editor's selection mask instead (RenderFrame::collectSelection): only...
const std::unordered_set< u32 > * screen_ui
The entities the SCREEN owns (UISystem::screenDomain), or null.
glm::mat4 motion_prev_view_projection
const MaterialStore * materials
u32 environment_texture_id
The frame environment's prefiltered reflection atlas (0 = none this frame).
resource::ResourceManager & resources
glm::vec2 motion_prev_jitter
u32 shadow_texture_id
The map that pass produced, handed to the meshes that receive it (0 = none).
bool causticReceivers
Opaque geometry seen by refracted sunlight, including objects with shadow casting disabled.
glm::mat4 view_projection
RenderStage current_stage
RenderFrame * frame
The owning frame, for lazily-compiled batch variants (RenderFrame::batchProgram).
RenderContext & render_context
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.
std::array< u64, MESH_VARIANTS/64 > keys
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.
u64 requirementDigest() const
A stable name for the SET of program requirements described here.
RenderPrewarmResult & operator+=(const RenderPrewarmResult &other)
std::vector< u64 > materialKeys
void addMaterialKey(u64 key)
The one skinned entity a view colours by a joint's weights, and which joint.
What a frame's selections came to, counted where each one is made.