vFoV and clipping plane distances now come from config

This commit is contained in:
Zach Fox 2017-06-14 11:53:05 -07:00
parent ec3b488897
commit 03c61e2191
3 changed files with 24 additions and 3 deletions

View file

@ -42,6 +42,9 @@ void SecondaryCameraRenderTaskConfig::resetSizeSpectatorCamera(int width, int he
class BeginSecondaryCameraFrame { // Changes renderContext for our framebuffer and and view. class BeginSecondaryCameraFrame { // Changes renderContext for our framebuffer and and view.
glm::vec3 _position{}; glm::vec3 _position{};
glm::quat _orientation{}; glm::quat _orientation{};
float _vFoV{};
float _nearClipPlaneDistance{};
float _farClipPlaneDistance{};
public: public:
using Config = BeginSecondaryCameraFrameConfig; using Config = BeginSecondaryCameraFrameConfig;
using JobModel = render::Job::ModelO<BeginSecondaryCameraFrame, RenderArgsPointer, Config>; using JobModel = render::Job::ModelO<BeginSecondaryCameraFrame, RenderArgsPointer, Config>;
@ -53,6 +56,9 @@ public:
if (config.enabled || config.alwaysEnabled) { if (config.enabled || config.alwaysEnabled) {
_position = config.position; _position = config.position;
_orientation = config.orientation; _orientation = config.orientation;
_vFoV = config.vFoV;
_nearClipPlaneDistance = config.nearClipPlaneDistance;
_farClipPlaneDistance = config.farClipPlaneDistance;
} }
} }
@ -76,7 +82,7 @@ public:
auto srcViewFrustum = args->getViewFrustum(); auto srcViewFrustum = args->getViewFrustum();
srcViewFrustum.setPosition(_position); srcViewFrustum.setPosition(_position);
srcViewFrustum.setOrientation(_orientation); srcViewFrustum.setOrientation(_orientation);
srcViewFrustum.setProjection(glm::perspective(45.0f, ((float)args->_viewport.z / (float)args->_viewport.w), 0.1f, 100.0f)); 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, // 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. // which is not what we want here.
srcViewFrustum.calculate(); srcViewFrustum.calculate();

View file

@ -29,13 +29,19 @@ public:
void build(JobModel& task, const render::Varying& inputs, render::Varying& outputs, render::CullFunctor cullFunctor, bool isDeferred = true); void build(JobModel& task, const render::Varying& inputs, render::Varying& outputs, render::CullFunctor cullFunctor, bool isDeferred = true);
}; };
class BeginSecondaryCameraFrameConfig : public render::Task::Config { // Exposes view frustum position/orientation to javascript. class BeginSecondaryCameraFrameConfig : public render::Task::Config { // Exposes secondary camera parameters to JavaScript.
Q_OBJECT Q_OBJECT
Q_PROPERTY(glm::vec3 position MEMBER position NOTIFY dirty) // of viewpoint to render from 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(glm::quat orientation MEMBER orientation NOTIFY dirty) // 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: public:
glm::vec3 position{}; glm::vec3 position{};
glm::quat orientation{}; glm::quat orientation{};
float vFoV{};
float nearClipPlaneDistance{};
float farClipPlaneDistance{};
BeginSecondaryCameraFrameConfig() : render::Task::Config(false) {} BeginSecondaryCameraFrameConfig() : render::Task::Config(false) {}
signals: signals:
void dirty(); void dirty();

View file

@ -81,6 +81,9 @@
// function is wired. // function is wired.
// windowAspectRatio: The ratio of the Interface windows's sizeX/sizeY // windowAspectRatio: The ratio of the Interface windows's sizeX/sizeY
// previewAspectRatio: The ratio of the camera preview's sizeX/sizeY // previewAspectRatio: The ratio of the camera preview's sizeX/sizeY
// vFoV: The vertical field of view of the spectator camera
// nearClipPlaneDistance: The near clip plane distance of the spectator camera
// farClipPlaneDistance: The far clip plane distance of the spectator camera
// //
// Arguments: // Arguments:
// None // None
@ -91,7 +94,10 @@
// //
var isUpdateRenderWired = false; var isUpdateRenderWired = false;
var windowAspectRatio; var windowAspectRatio;
var previewAspectRatio = 16/9; var previewAspectRatio = 16 / 9;
var vFoV = 45.0;
var nearClipPlaneDistance = 0.1;
var farClipPlaneDistance = 100.0;
function spectatorCameraOn() { function spectatorCameraOn() {
// Set the special texture size based on the window in which it will eventually be displayed. // Set the special texture size based on the window in which it will eventually be displayed.
var size = Controller.getViewportDimensions(); // FIXME: Need a signal to hook into when the dimensions change. var size = Controller.getViewportDimensions(); // FIXME: Need a signal to hook into when the dimensions change.
@ -100,6 +106,9 @@
windowAspectRatio = sizeX/sizeY; windowAspectRatio = sizeX/sizeY;
spectatorFrameRenderConfig.resetSizeSpectatorCamera(sizeX, sizeY); spectatorFrameRenderConfig.resetSizeSpectatorCamera(sizeX, sizeY);
spectatorFrameRenderConfig.enabled = beginSpectatorFrameRenderConfig.enabled = true; spectatorFrameRenderConfig.enabled = beginSpectatorFrameRenderConfig.enabled = true;
beginSpectatorFrameRenderConfig.vFoV = vFoV;
beginSpectatorFrameRenderConfig.nearClipPlaneDistance = nearClipPlaneDistance;
beginSpectatorFrameRenderConfig.farClipPlaneDistance = farClipPlaneDistance;
var cameraRotation = MyAvatar.orientation, cameraPosition = inFrontOf(1, Vec3.sum(MyAvatar.position, { x: 0, y: 0.3, z: 0 })); var cameraRotation = MyAvatar.orientation, cameraPosition = inFrontOf(1, Vec3.sum(MyAvatar.position, { x: 0, y: 0.3, z: 0 }));
Script.update.connect(updateRenderFromCamera); Script.update.connect(updateRenderFromCamera);
isUpdateRenderWired = true; isUpdateRenderWired = true;