mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 09:44:21 +02:00
Merge pull request #10856 from zfox23/spectatorCamera_positionSpeedup
Spectator Camera position/orientation update speedup
This commit is contained in:
commit
fcc131187d
4 changed files with 103 additions and 78 deletions
|
@ -1957,7 +1957,7 @@ void Application::initializeGL() {
|
|||
render::CullFunctor cullFunctor = LODManager::shouldRender;
|
||||
static const QString RENDER_FORWARD = "HIFI_RENDER_FORWARD";
|
||||
bool isDeferred = !QProcessEnvironment::systemEnvironment().contains(RENDER_FORWARD);
|
||||
_renderEngine->addJob<SecondaryCameraRenderTask>("SecondaryCameraFrame", cullFunctor);
|
||||
_renderEngine->addJob<SecondaryCameraRenderTask>("SecondaryCameraJob", cullFunctor);
|
||||
_renderEngine->addJob<RenderViewTask>("RenderMainView", cullFunctor, isDeferred);
|
||||
_renderEngine->load();
|
||||
_renderEngine->registerScene(_main3DScene);
|
||||
|
|
|
@ -9,9 +9,11 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include "Application.h"
|
||||
#include "SecondaryCamera.h"
|
||||
#include <TextureCache.h>
|
||||
#include <gpu/Context.h>
|
||||
#include <EntityScriptingInterface.h>
|
||||
|
||||
using RenderArgsPointer = std::shared_ptr<RenderArgs>;
|
||||
|
||||
|
@ -27,39 +29,32 @@ void MainRenderTask::build(JobModel& task, const render::Varying& inputs, render
|
|||
}
|
||||
}
|
||||
|
||||
void SecondaryCameraRenderTaskConfig::resetSize(int width, int height) { // FIXME: Add an arg here for "destinationFramebuffer"
|
||||
bool wasEnabled = isEnabled();
|
||||
setEnabled(false);
|
||||
auto textureCache = DependencyManager::get<TextureCache>();
|
||||
textureCache->resetSpectatorCameraFramebuffer(width, height); // FIXME: Call the correct reset function based on the "destinationFramebuffer" arg
|
||||
setEnabled(wasEnabled);
|
||||
}
|
||||
|
||||
void SecondaryCameraRenderTaskConfig::resetSizeSpectatorCamera(int width, int height) { // Carefully adjust the framebuffer / texture.
|
||||
resetSize(width, height);
|
||||
}
|
||||
|
||||
class BeginSecondaryCameraFrame { // Changes renderContext for our framebuffer and view.
|
||||
class SecondaryCameraJob { // Changes renderContext for our framebuffer and view.
|
||||
QUuid _attachedEntityId{};
|
||||
glm::vec3 _position{};
|
||||
glm::quat _orientation{};
|
||||
float _vFoV{};
|
||||
float _nearClipPlaneDistance{};
|
||||
float _farClipPlaneDistance{};
|
||||
EntityPropertyFlags _attachedEntityPropertyFlags;
|
||||
QSharedPointer<EntityScriptingInterface> _entityScriptingInterface;
|
||||
public:
|
||||
using Config = BeginSecondaryCameraFrameConfig;
|
||||
using JobModel = render::Job::ModelO<BeginSecondaryCameraFrame, RenderArgsPointer, Config>;
|
||||
BeginSecondaryCameraFrame() {
|
||||
using Config = SecondaryCameraJobConfig;
|
||||
using JobModel = render::Job::ModelO<SecondaryCameraJob, RenderArgsPointer, Config>;
|
||||
SecondaryCameraJob() {
|
||||
_cachedArgsPointer = std::make_shared<RenderArgs>(_cachedArgs);
|
||||
_entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
|
||||
_attachedEntityPropertyFlags += PROP_POSITION;
|
||||
_attachedEntityPropertyFlags += PROP_ROTATION;
|
||||
}
|
||||
|
||||
void configure(const Config& config) {
|
||||
if (config.enabled || config.alwaysEnabled) {
|
||||
_position = config.position;
|
||||
_orientation = config.orientation;
|
||||
_vFoV = config.vFoV;
|
||||
_nearClipPlaneDistance = config.nearClipPlaneDistance;
|
||||
_farClipPlaneDistance = config.farClipPlaneDistance;
|
||||
}
|
||||
_attachedEntityId = config.attachedEntityId;
|
||||
_position = config.position;
|
||||
_orientation = config.orientation;
|
||||
_vFoV = config.vFoV;
|
||||
_nearClipPlaneDistance = config.nearClipPlaneDistance;
|
||||
_farClipPlaneDistance = config.farClipPlaneDistance;
|
||||
}
|
||||
|
||||
void run(const render::RenderContextPointer& renderContext, RenderArgsPointer& cachedArgs) {
|
||||
|
@ -83,8 +78,14 @@ public:
|
|||
});
|
||||
|
||||
auto srcViewFrustum = args->getViewFrustum();
|
||||
srcViewFrustum.setPosition(_position);
|
||||
srcViewFrustum.setOrientation(_orientation);
|
||||
if (!_attachedEntityId.isNull()) {
|
||||
EntityItemProperties entityProperties = _entityScriptingInterface->getEntityProperties(_attachedEntityId, _attachedEntityPropertyFlags);
|
||||
srcViewFrustum.setPosition(entityProperties.getPosition());
|
||||
srcViewFrustum.setOrientation(entityProperties.getRotation());
|
||||
} else {
|
||||
srcViewFrustum.setPosition(_position);
|
||||
srcViewFrustum.setOrientation(_orientation);
|
||||
}
|
||||
srcViewFrustum.setProjection(glm::perspective(glm::radians(_vFoV), ((float)args->_viewport.z / (float)args->_viewport.w), _nearClipPlaneDistance, _farClipPlaneDistance));
|
||||
// Without calculating the bound planes, the secondary camera will use the same culling frustum as the main camera,
|
||||
// which is not what we want here.
|
||||
|
@ -99,6 +100,41 @@ protected:
|
|||
RenderArgsPointer _cachedArgsPointer;
|
||||
};
|
||||
|
||||
void SecondaryCameraJobConfig::setPosition(glm::vec3 pos) {
|
||||
if (attachedEntityId.isNull()) {
|
||||
position = pos;
|
||||
emit dirty();
|
||||
} else {
|
||||
qDebug() << "ERROR: Cannot set position of SecondaryCamera while attachedEntityId is set.";
|
||||
}
|
||||
}
|
||||
|
||||
void SecondaryCameraJobConfig::setOrientation(glm::quat orient) {
|
||||
if (attachedEntityId.isNull()) {
|
||||
orientation = orient;
|
||||
emit dirty();
|
||||
} else {
|
||||
qDebug() << "ERROR: Cannot set orientation of SecondaryCamera while attachedEntityId is set.";
|
||||
}
|
||||
}
|
||||
|
||||
void SecondaryCameraJobConfig::enableSecondaryCameraRenderConfigs(bool enabled) {
|
||||
qApp->getRenderEngine()->getConfiguration()->getConfig<SecondaryCameraRenderTask>()->setEnabled(enabled);
|
||||
setEnabled(enabled);
|
||||
}
|
||||
|
||||
void SecondaryCameraJobConfig::resetSizeSpectatorCamera(int width, int height) { // Carefully adjust the framebuffer / texture.
|
||||
qApp->getRenderEngine()->getConfiguration()->getConfig<SecondaryCameraRenderTask>()->resetSize(width, height);
|
||||
}
|
||||
|
||||
void SecondaryCameraRenderTaskConfig::resetSize(int width, int height) { // FIXME: Add an arg here for "destinationFramebuffer"
|
||||
bool wasEnabled = isEnabled();
|
||||
setEnabled(false);
|
||||
auto textureCache = DependencyManager::get<TextureCache>();
|
||||
textureCache->resetSpectatorCameraFramebuffer(width, height); // FIXME: Call the correct reset function based on the "destinationFramebuffer" arg
|
||||
setEnabled(wasEnabled);
|
||||
}
|
||||
|
||||
class EndSecondaryCameraFrame { // Restores renderContext.
|
||||
public:
|
||||
using JobModel = render::Job::ModelI<EndSecondaryCameraFrame, RenderArgsPointer>;
|
||||
|
@ -119,7 +155,7 @@ public:
|
|||
};
|
||||
|
||||
void SecondaryCameraRenderTask::build(JobModel& task, const render::Varying& inputs, render::Varying& outputs, render::CullFunctor cullFunctor) {
|
||||
const auto cachedArg = task.addJob<BeginSecondaryCameraFrame>("BeginSecondaryCamera");
|
||||
const auto cachedArg = task.addJob<SecondaryCameraJob>("SecondaryCamera");
|
||||
const auto items = task.addJob<RenderFetchCullSortTask>("FetchCullSort", cullFunctor);
|
||||
assert(items.canCast<RenderFetchCullSortTask::Output>());
|
||||
task.addJob<RenderDeferredTask>("RenderDeferredTask", items);
|
||||
|
|
|
@ -28,34 +28,40 @@ public:
|
|||
void build(JobModel& task, const render::Varying& inputs, render::Varying& outputs, render::CullFunctor cullFunctor, bool isDeferred = true);
|
||||
};
|
||||
|
||||
class BeginSecondaryCameraFrameConfig : public render::Task::Config { // Exposes secondary camera parameters to JavaScript.
|
||||
class SecondaryCameraJobConfig : public render::Task::Config { // Exposes secondary camera parameters to JavaScript.
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(glm::vec3 position MEMBER position NOTIFY dirty) // of viewpoint to render from
|
||||
Q_PROPERTY(glm::quat orientation MEMBER orientation NOTIFY dirty) // of viewpoint to render from
|
||||
Q_PROPERTY(QUuid attachedEntityId MEMBER attachedEntityId NOTIFY dirty) // entity whose properties define camera position and orientation
|
||||
Q_PROPERTY(glm::vec3 position READ getPosition WRITE setPosition) // of viewpoint to render from
|
||||
Q_PROPERTY(glm::quat orientation READ getOrientation WRITE setOrientation) // of viewpoint to render from
|
||||
Q_PROPERTY(float vFoV MEMBER vFoV NOTIFY dirty) // Secondary camera's vertical field of view. In degrees.
|
||||
Q_PROPERTY(float nearClipPlaneDistance MEMBER nearClipPlaneDistance NOTIFY dirty) // Secondary camera's near clip plane distance. In meters.
|
||||
Q_PROPERTY(float farClipPlaneDistance MEMBER farClipPlaneDistance NOTIFY dirty) // Secondary camera's far clip plane distance. In meters.
|
||||
public:
|
||||
QUuid attachedEntityId{};
|
||||
glm::vec3 position{};
|
||||
glm::quat orientation{};
|
||||
float vFoV{ 45.0f };
|
||||
float nearClipPlaneDistance{ 0.1f };
|
||||
float farClipPlaneDistance{ 100.0f };
|
||||
BeginSecondaryCameraFrameConfig() : render::Task::Config(false) {}
|
||||
SecondaryCameraJobConfig() : render::Task::Config(false) {}
|
||||
signals:
|
||||
void dirty();
|
||||
public slots:
|
||||
glm::vec3 getPosition() { return position; }
|
||||
void setPosition(glm::vec3 pos);
|
||||
glm::quat getOrientation() { return orientation; }
|
||||
void setOrientation(glm::quat orient);
|
||||
void enableSecondaryCameraRenderConfigs(bool enabled);
|
||||
void resetSizeSpectatorCamera(int width, int height);
|
||||
};
|
||||
|
||||
class SecondaryCameraRenderTaskConfig : public render::Task::Config {
|
||||
Q_OBJECT
|
||||
public:
|
||||
SecondaryCameraRenderTaskConfig() : render::Task::Config(false) {}
|
||||
private:
|
||||
void resetSize(int width, int height);
|
||||
signals:
|
||||
void dirty();
|
||||
public slots:
|
||||
void resetSizeSpectatorCamera(int width, int height);
|
||||
};
|
||||
|
||||
class SecondaryCameraRenderTask {
|
||||
|
|
|
@ -28,33 +28,6 @@
|
|||
Vec3.multiply(distance, Quat.getForward(orientation || MyAvatar.orientation)));
|
||||
}
|
||||
|
||||
// Function Name: updateRenderFromCamera()
|
||||
//
|
||||
// Description:
|
||||
// -The update function for the spectator camera. Modifies the camera's position
|
||||
// and orientation.
|
||||
//
|
||||
// Relevant Variables:
|
||||
// -spectatorFrameRenderConfig: The render configuration of the spectator camera
|
||||
// render job. It controls the rendered texture size of the spectator camera.
|
||||
// -beginSpectatorFrameRenderConfig: The render configuration of the spectator camera
|
||||
// render job. It controls the orientation and position of the secondary camera whose viewport is rendered to
|
||||
// the texture.
|
||||
// -viewFinderOverlay: The in-world overlay that displays the spectator camera's view.
|
||||
// -camera: The in-world entity that corresponds to the spectator camera.
|
||||
// -cameraIsDynamic: "false" for now while we figure out why dynamic, parented overlays
|
||||
// drift with respect to their parent.
|
||||
var spectatorFrameRenderConfig = Render.getConfig("SecondaryCameraFrame");
|
||||
var beginSpectatorFrameRenderConfig = Render.getConfig("BeginSecondaryCamera");
|
||||
var viewFinderOverlay = false;
|
||||
var camera = false;
|
||||
var cameraIsDynamic = false;
|
||||
function updateRenderFromCamera() {
|
||||
var cameraData = Entities.getEntityProperties(camera, ['position', 'rotation']);
|
||||
beginSpectatorFrameRenderConfig.orientation = cameraData.rotation;
|
||||
beginSpectatorFrameRenderConfig.position = cameraData.position;
|
||||
}
|
||||
|
||||
// Function Name: spectatorCameraOn()
|
||||
//
|
||||
// Description:
|
||||
|
@ -62,6 +35,19 @@
|
|||
// spawn the camera entity.
|
||||
//
|
||||
// Relevant Variables:
|
||||
// -spectatorCameraConfig: The render configuration of the spectator camera
|
||||
// render job. It controls various attributes of the Secondary Camera, such as:
|
||||
// -The entity ID to follow
|
||||
// -Position
|
||||
// -Orientation
|
||||
// -Rendered texture size
|
||||
// -Vertical field of view
|
||||
// -Near clip plane distance
|
||||
// -Far clip plane distance
|
||||
// -viewFinderOverlay: The in-world overlay that displays the spectator camera's view.
|
||||
// -camera: The in-world entity that corresponds to the spectator camera.
|
||||
// -cameraIsDynamic: "false" for now while we figure out why dynamic, parented overlays
|
||||
// drift with respect to their parent.
|
||||
// -vFoV: The vertical field of view of the spectator camera.
|
||||
// -nearClipPlaneDistance: The near clip plane distance of the spectator camera (aka "camera").
|
||||
// -farClipPlaneDistance: The far clip plane distance of the spectator camera.
|
||||
|
@ -71,8 +57,10 @@
|
|||
// -viewFinderOverlayDim: The x, y, and z dimensions of the viewFinderOverlay.
|
||||
// -camera: The camera model which is grabbable.
|
||||
// -viewFinderOverlay: The preview of what the spectator camera is viewing, placed inside the glass pane.
|
||||
// -cameraUpdateInterval: Used when setting Script.setInterval()
|
||||
// -CAMERA_UPDATE_INTERVAL_MS: Defines the time between calls to updateRenderFromCamera()
|
||||
var spectatorCameraConfig = Render.getConfig("SecondaryCamera");
|
||||
var viewFinderOverlay = false;
|
||||
var camera = false;
|
||||
var cameraIsDynamic = false;
|
||||
var vFoV = 45.0;
|
||||
var nearClipPlaneDistance = 0.1;
|
||||
var farClipPlaneDistance = 100.0;
|
||||
|
@ -83,17 +71,14 @@
|
|||
// draws textures, but should be looked into at some point. Also the z dimension shouldn't affect
|
||||
// the overlay since it is an Image3DOverlay so it is set to 0.
|
||||
var viewFinderOverlayDim = { x: glassPaneWidth, y: -glassPaneWidth, z: 0 };
|
||||
var cameraUpdateInterval;
|
||||
var CAMERA_UPDATE_INTERVAL_MS = 11; // Result of (1000 (ms/s)) / (90 (hz)) rounded down
|
||||
function spectatorCameraOn() {
|
||||
// Sets the special texture size based on the window it is displayed in, which doesn't include the menu bar
|
||||
spectatorFrameRenderConfig.resetSizeSpectatorCamera(Window.innerWidth, Window.innerHeight);
|
||||
spectatorFrameRenderConfig.enabled = beginSpectatorFrameRenderConfig.enabled = true;
|
||||
beginSpectatorFrameRenderConfig.vFoV = vFoV;
|
||||
beginSpectatorFrameRenderConfig.nearClipPlaneDistance = nearClipPlaneDistance;
|
||||
beginSpectatorFrameRenderConfig.farClipPlaneDistance = farClipPlaneDistance;
|
||||
spectatorCameraConfig.enableSecondaryCameraRenderConfigs(true);
|
||||
spectatorCameraConfig.resetSizeSpectatorCamera(Window.innerWidth, Window.innerHeight);
|
||||
spectatorCameraConfig.vFoV = vFoV;
|
||||
spectatorCameraConfig.nearClipPlaneDistance = nearClipPlaneDistance;
|
||||
spectatorCameraConfig.farClipPlaneDistance = farClipPlaneDistance;
|
||||
cameraRotation = MyAvatar.orientation, cameraPosition = inFrontOf(1, Vec3.sum(MyAvatar.position, { x: 0, y: 0.3, z: 0 }));
|
||||
cameraUpdateInterval = Script.setInterval(updateRenderFromCamera, 11); // Update every 11ms (90.9hz)
|
||||
camera = Entities.addEntity({
|
||||
"angularDamping": 1,
|
||||
"damping": 1,
|
||||
|
@ -112,6 +97,7 @@
|
|||
"type": "Model",
|
||||
"userData": "{\"grabbableKey\":{\"grabbable\":true}}"
|
||||
}, true);
|
||||
spectatorCameraConfig.attachedEntityId = camera;
|
||||
updateOverlay();
|
||||
setDisplay(monitorShowsCameraView);
|
||||
}
|
||||
|
@ -122,11 +108,8 @@
|
|||
// -Call this function to shut down the spectator camera and
|
||||
// destroy the camera entity.
|
||||
function spectatorCameraOff() {
|
||||
spectatorFrameRenderConfig.enabled = beginSpectatorFrameRenderConfig.enabled = false;
|
||||
if (cameraUpdateInterval) {
|
||||
Script.clearInterval(cameraUpdateInterval);
|
||||
cameraUpdateInterval = false;
|
||||
}
|
||||
spectatorCameraConfig.attachedEntityId = false;
|
||||
spectatorCameraConfig.enableSecondaryCameraRenderConfigs(false);
|
||||
if (camera) {
|
||||
Entities.deleteEntity(camera);
|
||||
}
|
||||
|
@ -235,7 +218,7 @@
|
|||
// 4. Camera is on; "Monitor Shows" is "Camera View": "url" is "resource://spectatorCameraFrame"
|
||||
function setDisplay(showCameraView) {
|
||||
// It would be fancy if the app would show instructions when (url === ""), but that's out of scope for now.
|
||||
var url = (camera && showCameraView && cameraUpdateInterval) ? "resource://spectatorCameraFrame" : "";
|
||||
var url = (camera && showCameraView) ? "resource://spectatorCameraFrame" : "";
|
||||
Window.setDisplayTexture(url);
|
||||
}
|
||||
const MONITOR_SHOWS_CAMERA_VIEW_DEFAULT = false;
|
||||
|
@ -299,7 +282,7 @@
|
|||
viewFinderOverlayDim = { x: glassPaneWidth, y: -glassPaneWidth, z: 0 };
|
||||
}
|
||||
updateOverlay();
|
||||
spectatorFrameRenderConfig.resetSizeSpectatorCamera(geometryChanged.width, geometryChanged.height);
|
||||
spectatorCameraConfig.resetSizeSpectatorCamera(geometryChanged.width, geometryChanged.height);
|
||||
setDisplay(monitorShowsCameraView);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue