2#include "Foundation/Logging/Logger.h"
4#include "Utilities/Math.h"
5#include "Systems/Core/CameraSystem.h"
6#include "Systems/Core/TransformSystem.h"
8#include "Image360System.h"
12 using namespace Cogs::Core::Image360;
16 void cubemapDecode(
int& f, glm::vec2& uv,
const glm::vec3& d)
19 if (m.x > m.y && m.x > m.z) {
20 f = 0.f <= d.x ? 0 : 1;
25 f = 0.f <= d.y ? 2 : 3;
30 f = 0.f <= d.z ? 4 : 5;
34 uv = 0.5f * (uv + glm::vec2(1.0));
41 cubemapDecode(f, uv_, dir);
44 int ix = lodTree.data[f];
45 for (
size_t l = 0; ix < -1 && l <= conf.treeMaxSize; l++) {
47 glm::vec2 o = glm::floor(uv);
49 ix = -ix + 2 * int(o.y) + int(o.x);
50 ix = lodTree.data[ix];
59 uv = 0.5f * (uv + glm::vec2(ix & 1, (ix >> 1) & 1));
65 if (
size_t(ix) < rendererData.depth.tilesData.size()) {
69 glm::ivec2 loc = glm::clamp(glm::ivec2(glm::vec2(
float(conf.
baseSize)) * uv), glm::ivec2(0), glm::ivec2(conf.
baseSize-1));
71 uint16_t value = ((
const uint16_t*)buffer->data())[loc.y * conf.
baseSize + loc.x];
72 if (value == rendererData.noDataDepth) {
75 dist = rendererData.depth.scale * float(value) + rendererData.depth.bias;
85Cogs::Core::Image360::RayPickExtension::RayPickExtension(
Image360System* im360System) : im360System(im360System) {}
89 const glm::vec2& normPosition,
95 std::vector<RayPicking::RayPickHit>& hits)
97 const CameraData& cameraData = context->cameraSystem->getData(&camera);
98 const float clipSpaceNearPlane = context->
variables->get(
"renderer.reverseDepth",
false) ? 1.f : -1.f;
102 bool hitSomething =
false;
110 if (data.state != Image360Data::State::Running) {
continue; }
111 if (!data.config.hasDepth) {
continue; }
112 if (data.rendererData.depth.tilesData.empty()) {
continue; }
114 const glm::mat3 localFromView = data.rendererData.localFromWorld * glm::mat3(cameraData.inverseViewMatrix);
115 const glm::mat3 viewFromLocal = glm::mat3(cameraData.viewMatrix) * data.rendererData.worldFromLocal;
117 const glm::mat4 localFromClip = glm::mat4(localFromView) * cameraData.inverseProjectionMatrix;
118 const glm::vec3 dir = glm::normalize(euclidean(localFromClip * glm::vec4(normPosition, clipSpaceNearPlane, 1)));
121 if (lookupDistance(dist, data.rendererData, data.lodTree, data.config, dir)) {
125 glm::vec3 posView = viewFromLocal * (dist * dir);
128 glm::vec4 posWorld_h = cameraData.inverseViewMatrix * glm::vec4(posView, 1.f);
129 float depth = -posView.z;
132 if (depth < hits[0].distance) {
133 hits[0] = {comp, returnChildEntity, euclidean(posWorld_h), depth};
139 hits.emplace_back(comp, returnChildEntity, euclidean(posWorld_h), depth);
148 std::sort(hits.begin(), hits.end());
ComponentType * getComponent() const
ComponentPool< ComponentType > pool
Pool of components managed by the system.
A Context instance contains all the services, systems and runtime components needed to use Cogs.
std::unique_ptr< class Variables > variables
Variables service instance.
Base component for all rendering content.
constexpr bool isVisibleInLayer(RenderLayers layerMask) const
Check if the entity should be visible in the given layer mask.
constexpr bool isPickable() const
Check if the entity is pickable or not.
Log implementation class.
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
PicksReturned
* Options for returning picking hits.
@ Closest
Return just the closest hit.
@ AllSorted
Return all hits sorted based on distance from the ray start, closest first.
PickingFlags
Options for COGS picking.
@ ReturnChildEntity
Return ID if sub-entity picked, not set: return root parent entity.
constexpr Log getLogger(const char(&name)[LEN]) noexcept
Contains data describing a Camera instance and its derived data structured such as matrix data and vi...
glm::mat4 rawProjectionMatrix
Projection matrix that has not been adjusted by the renderer, and is thus appropriate for direct scre...
uint32_t baseSize
Base image size of a cached tile. From json.
bool pickCamera(Context *context, const CameraComponent &camera, const glm::vec2 &normPosition, float, float, PickingFlags pickingFlags, PicksReturned returnFlag, const RayPicking::RayPickFilter &filter, std::vector< RayPicking::RayPickHit > &hits) override
Do a ray pick from a normalized screen space position in the camera direction and return all hits.
bool isUnwantedType(const ComponentModel::Component &comp) const
Helper function used to determine if a given component belongs to an accepted entity type.
RenderLayers layerMask
Limit picking to the specified render layers. Pick all layers by default.