/* SPDX-License-Identifier: GPL-2.0-or-later * Copyright 2021 Blender Foundation. */ /** \file * \ingroup eevee */ #pragma once #include #include "DNA_object_types.h" #include "eevee_sampling.hh" #include "eevee_shader_shared.hh" namespace blender::eevee { class Instance; /* TODO(fclem) Might want to move to eevee_shader_shared.hh. */ static const float cubeface_mat[6][4][4] = { /* Pos X */ {{0.0f, 0.0f, -1.0f, 0.0f}, {0.0f, -1.0f, 0.0f, 0.0f}, {-1.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f, 1.0f}}, /* Neg X */ {{0.0f, 0.0f, 1.0f, 0.0f}, {0.0f, -1.0f, 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f, 1.0f}}, /* Pos Y */ {{1.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, -1.0f, 0.0f}, {0.0f, 1.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f, 1.0f}}, /* Neg Y */ {{1.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f, 0.0f}, {0.0f, -1.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f, 1.0f}}, /* Pos Z */ {{1.0f, 0.0f, 0.0f, 0.0f}, {0.0f, -1.0f, 0.0f, 0.0f}, {0.0f, 0.0f, -1.0f, 0.0f}, {0.0f, 0.0f, 0.0f, 1.0f}}, /* Neg Z */ {{-1.0f, 0.0f, 0.0f, 0.0f}, {0.0f, -1.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 0.0f, 1.0f}}, }; inline void cubeface_winmat_get(float4x4 &winmat, float near, float far) { /* Simple 90° FOV projection. */ perspective_m4(winmat.ptr(), -near, near, -near, near, near, far); } /* -------------------------------------------------------------------- */ /** \name CameraData operators * \{ */ inline bool operator==(const CameraData &a, const CameraData &b) { return compare_m4m4(a.persmat.ptr(), b.persmat.ptr(), FLT_MIN) && (a.uv_scale == b.uv_scale) && (a.uv_bias == b.uv_bias) && (a.equirect_scale == b.equirect_scale) && (a.equirect_bias == b.equirect_bias) && (a.fisheye_fov == b.fisheye_fov) && (a.fisheye_lens == b.fisheye_lens) && (a.filter_size == b.filter_size) && (a.type == b.type); } inline bool operator!=(const CameraData &a, const CameraData &b) { return !(a == b); } /** \} */ /* -------------------------------------------------------------------- */ /** \name Camera * \{ */ /** * Point of view in the scene. Can be init from viewport or camera object. */ class Camera { private: Instance &inst_; /** Double buffered to detect changes and have history for re-projection. */ CameraDataBuf data_[2]; /** Active data index in data_. */ int data_id_ = 0; /** Detects wrong usage. */ bool synced_ = false; public: Camera(Instance &inst) : inst_(inst){}; ~Camera(){}; void init(void); void sync(void); /** * Getters **/ const CameraData &data_get(void) const { BLI_assert(synced_); return data_[data_id_]; } const GPUUniformBuf *ubo_get(void) const { return data_[data_id_]; } bool is_panoramic(void) const { return eevee::is_panoramic(data_[data_id_].type); } bool is_orthographic(void) const { return data_[data_id_].type == CAMERA_ORTHO; } const float3 &position(void) const { return *reinterpret_cast(data_[data_id_].viewinv[3]); } const float3 &forward(void) const { return *reinterpret_cast(data_[data_id_].viewinv[2]); } }; /** \} */ } // namespace blender::eevee