Skip to content

Commit d6d9cff

Browse files
Merge remote-tracking branch 'overte/master' into application
2 parents 343a8ac + 09f8d07 commit d6d9cff

File tree

201 files changed

+4936
-2212
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

201 files changed

+4936
-2212
lines changed

interface/resources/qml/hifi/dialogs/graphics/GraphicsSettings.qml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,36 @@ Flickable {
658658
}
659659
}
660660
}
661+
Item {
662+
Layout.preferredWidth: parent.width
663+
Layout.preferredHeight: 35
664+
Layout.topMargin: 16
665+
666+
HifiStylesUit.RalewayRegular {
667+
id: enableCameraClippingHeader
668+
text: "3rd Person Camera Clipping"
669+
anchors.left: parent.left
670+
anchors.top: parent.top
671+
width: 200
672+
height: parent.height
673+
size: 16
674+
color: "#FFFFFF"
675+
}
676+
677+
HifiControlsUit.CheckBox {
678+
id: enableCameraClipping
679+
checked: Render.cameraClippingEnabled
680+
boxSize: 16
681+
spacing: -1
682+
colorScheme: hifi.colorSchemes.dark
683+
anchors.left: enableCameraClippingHeader.right
684+
anchors.leftMargin: 20
685+
anchors.top: parent.top
686+
onCheckedChanged: {
687+
Render.cameraClippingEnabled = enableCameraClipping.checked;
688+
}
689+
}
690+
}
661691
}
662692

663693
ColumnLayout {
@@ -683,7 +713,7 @@ Flickable {
683713
ListModel {
684714
id: antialiasingModel
685715

686-
// Maintain same order as "AntialiasingConfig::Mode".
716+
// Maintain same order as "AntialiasingSetupConfig::Mode".
687717
ListElement {
688718
text: "None"
689719
}

interface/src/Application.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ Application::Application(
234234
_maxOctreePacketsPerSecond("maxOctreePPS", DEFAULT_MAX_OCTREE_PPS),
235235
_maxOctreePPS(_maxOctreePacketsPerSecond.get()),
236236
// Camera
237-
_fieldOfView("fieldOfView", DEFAULT_FIELD_OF_VIEW_DEGREES)
237+
_fieldOfView("fieldOfView", DEFAULT_FIELD_OF_VIEW_DEGREES),
238+
_cameraClippingEnabled("cameraClippingEnabled", false)
238239
{
239240
setProperty(hifi::properties::CRASHED, _previousSessionCrashed);
240241

interface/src/Application.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,9 @@ class Application : public QApplication,
300300
float getFieldOfView() { return _fieldOfView.get(); }
301301
void setFieldOfView(float fov);
302302

303+
bool getCameraClippingEnabled() { return _cameraClippingEnabled.get(); }
304+
void setCameraClippingEnabled(bool enabled);
305+
303306
void updateMyAvatarLookAtPosition(float deltaTime);
304307

305308

@@ -880,6 +883,10 @@ private slots:
880883
ConicalViewFrustums _lastQueriedViews; // last views used to query servers
881884

882885
Setting::Handle<float> _fieldOfView;
886+
Setting::Handle<float> _cameraClippingEnabled;
887+
888+
bool _prevCameraClippingEnabled { false };
889+
unsigned int _cameraClippingRayPickID;
883890

884891

885892
// Graphics

interface/src/Application_Camera.cpp

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include <glm/gtx/transform.hpp>
1919

2020
#include <controllers/UserInputMapper.h>
21+
#include <PickManager.h>
22+
#include <raypick/RayPick.h>
2123
#include <SecondaryCamera.h>
2224

2325
#include "avatar/MyAvatar.h"
@@ -40,9 +42,7 @@ void Application::updateCamera(RenderArgs& renderArgs, float deltaTime) {
4042
PROFILE_RANGE(render, __FUNCTION__);
4143
PerformanceTimer perfTimer("updateCamera");
4244

43-
glm::vec3 boomOffset;
4445
auto myAvatar = getMyAvatar();
45-
boomOffset = myAvatar->getModelScale() * myAvatar->getBoomLength() * -IDENTITY_FORWARD;
4646

4747
// The render mode is default or mirror if the camera is in mirror mode, assigned further below
4848
renderArgs._renderMode = RenderArgs::DEFAULT_RENDER_MODE;
@@ -81,6 +81,16 @@ void Application::updateCamera(RenderArgs& renderArgs, float deltaTime) {
8181
_myCamera.setOrientation(glm::normalize(glmExtractRotation(worldCameraMat)));
8282
_myCamera.setPosition(extractTranslation(worldCameraMat));
8383
} else {
84+
float boomLength = myAvatar->getBoomLength();
85+
if (getCameraClippingEnabled()) {
86+
auto result =
87+
DependencyManager::get<PickManager>()->getPrevPickResultTyped<RayPickResult>(_cameraClippingRayPickID);
88+
if (result && result->doesIntersect()) {
89+
const float CAMERA_CLIPPING_EPSILON = 0.1f;
90+
boomLength = std::min(boomLength, result->distance - CAMERA_CLIPPING_EPSILON);
91+
}
92+
}
93+
glm::vec3 boomOffset = myAvatar->getModelScale() * boomLength * -IDENTITY_FORWARD;
8494
_thirdPersonHMDCameraBoomValid = false;
8595
if (mode == CAMERA_MODE_THIRD_PERSON) {
8696
_myCamera.setOrientation(myAvatar->getHead()->getOrientation());
@@ -158,7 +168,19 @@ void Application::updateCamera(RenderArgs& renderArgs, float deltaTime) {
158168
_myCamera.update();
159169
}
160170

161-
renderArgs._cameraMode = (int8_t)_myCamera.getMode();
171+
renderArgs._cameraMode = (int8_t)mode;
172+
173+
const bool shouldEnableCameraClipping =
174+
(mode == CAMERA_MODE_THIRD_PERSON || mode == CAMERA_MODE_LOOK_AT || mode == CAMERA_MODE_SELFIE) && !isHMDMode() &&
175+
getCameraClippingEnabled();
176+
if (_prevCameraClippingEnabled != shouldEnableCameraClipping) {
177+
if (shouldEnableCameraClipping) {
178+
DependencyManager::get<PickManager>()->enablePick(_cameraClippingRayPickID);
179+
} else {
180+
DependencyManager::get<PickManager>()->disablePick(_cameraClippingRayPickID);
181+
}
182+
_prevCameraClippingEnabled = shouldEnableCameraClipping;
183+
}
162184
}
163185

164186
void Application::updateSecondaryCameraViewFrustum() {
@@ -277,6 +299,16 @@ void Application::setFieldOfView(float fov) {
277299
}
278300
}
279301

302+
void Application::setCameraClippingEnabled(bool enabled) {
303+
_cameraClippingEnabled.set(enabled);
304+
_prevCameraClippingEnabled = enabled;
305+
if (enabled) {
306+
DependencyManager::get<PickManager>()->enablePick(_cameraClippingRayPickID);
307+
} else {
308+
DependencyManager::get<PickManager>()->disablePick(_cameraClippingRayPickID);
309+
}
310+
}
311+
280312
// Called during Application::update immediately before AvatarManager::updateMyAvatar, updating my data that is then sent
281313
// to everyone.
282314
// The principal result is to call updateLookAtTargetAvatar() and then setLookAtPosition().

interface/src/Application_Setup.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <AutoUpdater.h>
3636
#include <avatar/AvatarManager.h>
3737
#include <BuildInfo.h>
38+
#include <CameraRootTransformNode.h>
3839
#include <crash-handler/CrashHandler.h>
3940
#include <DebugDraw.h>
4041
#include <DeferredLightingEffect.h>
@@ -1277,6 +1278,17 @@ void Application::initialize(const QCommandLineParser &parser) {
12771278
DependencyManager::get<EntityTreeRenderer>()->setMouseRayPickID(mouseRayPickID);
12781279
}
12791280

1281+
// Setup the camera clipping ray pick
1282+
{
1283+
_prevCameraClippingEnabled = _cameraClippingEnabled.get();
1284+
auto cameraRayPick = std::make_shared<RayPick>(Vectors::ZERO, -Vectors::UP,
1285+
PickFilter(PickScriptingInterface::getPickEntities() |
1286+
PickScriptingInterface::getPickLocalEntities()),
1287+
MyAvatar::ZOOM_MAX, 0.0f, _prevCameraClippingEnabled);
1288+
cameraRayPick->parentTransform = std::make_shared<CameraRootTransformNode>();
1289+
_cameraClippingRayPickID = DependencyManager::get<PickManager>()->addPick(PickQuery::Ray, cameraRayPick);
1290+
}
1291+
12801292
// Preload Tablet sounds
12811293
DependencyManager::get<EntityScriptingInterface>()->setEntityTree(qApp->getEntities()->getTree());
12821294
DependencyManager::get<TabletScriptingInterface>()->preloadSounds();
@@ -1656,8 +1668,10 @@ void Application::setupSignalsAndOperators() {
16561668
return nullptr;
16571669
});
16581670

1659-
Procedural::opaqueStencil = [](gpu::StatePointer state) { PrepareStencil::testMaskDrawShape(*state); };
1660-
Procedural::transparentStencil = [](gpu::StatePointer state) { PrepareStencil::testMask(*state); };
1671+
Procedural::opaqueStencil = [](gpu::StatePointer state, bool useAA) {
1672+
useAA ? PrepareStencil::testMaskDrawShape(*state) : PrepareStencil::testMaskDrawShapeNoAA(*state);
1673+
};
1674+
Procedural::transparentStencil = [](gpu::StatePointer state) { PrepareStencil::testMaskResetNoAA(*state); };
16611675

16621676
EntityTree::setGetEntityObjectOperator([this](const QUuid& id) -> QObject* {
16631677
auto entities = getEntities();
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//
2+
// Created by HifiExperiments on 10/30/2024
3+
// Copyright 2024 Overte e.V.
4+
//
5+
// Distributed under the Apache License, Version 2.0.
6+
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
7+
//
8+
9+
#include "CameraRootTransformNode.h"
10+
11+
#include "Application.h"
12+
#include "DependencyManager.h"
13+
#include "avatar/AvatarManager.h"
14+
#include "avatar/MyAvatar.h"
15+
16+
Transform CameraRootTransformNode::getTransform() {
17+
auto myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
18+
19+
glm::vec3 pos;
20+
glm::quat ori;
21+
22+
CameraMode mode = qApp->getCamera().getMode();
23+
if (mode == CAMERA_MODE_FIRST_PERSON || mode == CAMERA_MODE_THIRD_PERSON) {
24+
pos = myAvatar->getDefaultEyePosition();
25+
ori = myAvatar->getHeadOrientation();
26+
} else if (mode == CAMERA_MODE_FIRST_PERSON_LOOK_AT) {
27+
pos = myAvatar->getCameraEyesPosition(0.0f);
28+
ori = myAvatar->getLookAtRotation();
29+
} else {
30+
ori = myAvatar->getLookAtRotation();
31+
pos = myAvatar->getLookAtPivotPoint();
32+
33+
if (mode == CAMERA_MODE_SELFIE) {
34+
ori = ori * glm::angleAxis(PI, ori * Vectors::UP);
35+
}
36+
}
37+
38+
ori = ori * glm::angleAxis(-PI / 2.0f, Vectors::RIGHT);
39+
40+
glm::vec3 scale = glm::vec3(myAvatar->scaleForChildren());
41+
return Transform(ori, scale, pos);
42+
}
43+
44+
QVariantMap CameraRootTransformNode::toVariantMap() const {
45+
QVariantMap map;
46+
map["joint"] = "CameraRoot";
47+
return map;
48+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// Created by HifiExperiments on 10/30/2024
3+
// Copyright 2024 Overte e.V.
4+
//
5+
// Distributed under the Apache License, Version 2.0.
6+
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
7+
//
8+
#ifndef hifi_CameraRootTransformNode_h
9+
#define hifi_CameraRootTransformNode_h
10+
11+
#include "TransformNode.h"
12+
13+
class CameraRootTransformNode : public TransformNode {
14+
public:
15+
CameraRootTransformNode() {}
16+
Transform getTransform() override;
17+
QVariantMap toVariantMap() const override;
18+
};
19+
20+
#endif // hifi_CameraRootTransformNode_h

interface/src/SecondaryCamera.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ class EndSecondaryCameraFrame { // Restores renderContext.
274274
void SecondaryCameraRenderTask::build(JobModel& task, const render::Varying& inputs, render::Varying& outputs, render::CullFunctor cullFunctor) {
275275
const auto cachedArg = task.addJob<SecondaryCameraJob>("SecondaryCamera");
276276

277-
task.addJob<RenderViewTask>("RenderSecondView", cullFunctor, render::ItemKey::TAG_BITS_1, render::ItemKey::TAG_BITS_1);
277+
task.addJob<RenderViewTask>("RenderSecondView", cullFunctor, render::ItemKey::TAG_BITS_1, render::ItemKey::TAG_BITS_1, RenderViewTask::TransformOffset::SECONDARY_VIEW);
278278

279279
task.addJob<EndSecondaryCameraFrame>("EndSecondaryCamera", cachedArg);
280280
}

interface/src/graphics/GraphicsEngine.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,14 +262,14 @@ void GraphicsEngine::render_performFrame() {
262262
batch.enableStereo(isStereo);
263263
batch.clearDepthStencilFramebuffer(1.0, 0);
264264
batch.setViewportTransform({ 0, 0, finalFramebuffer->getSize() });
265-
_splashScreen->render(batch, viewFrustum, renderArgs._renderMethod == RenderArgs::RenderMethod::FORWARD);
265+
_splashScreen->render(batch, viewFrustum, renderArgs._renderMethod == RenderArgs::RenderMethod::FORWARD, render::RenderEngine::TS_BACKGROUND_VIEW);
266266
});
267267
} else {
268268
{
269269
PROFILE_RANGE(render, "/renderOverlay");
270270
PerformanceTimer perfTimer("renderOverlay");
271271
// NOTE: There is no batch associated with this renderArgs
272-
// the ApplicationOverlay class assumes it's viewport is set up to be the device size
272+
// the ApplicationOverlay class assumes its viewport is set up to be the device size
273273
renderArgs._viewport = glm::ivec4(0, 0, qApp->getDeviceSize());
274274
qApp->getApplicationOverlay().renderOverlay(&renderArgs);
275275
}

interface/src/raypick/ParabolaPointer.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,10 @@ void ParabolaPointer::RenderState::ParabolaRenderItem::render(RenderArgs* args)
446446

447447
Transform transform;
448448
transform.setTranslation(_origin);
449-
batch.setModelTransform(transform);
449+
batch.setModelTransform(transform, _prevRenderTransform);
450+
if (args->_renderMode == RenderArgs::RenderMode::DEFAULT_RENDER_MODE || args->_renderMode == RenderArgs::RenderMode::MIRROR_RENDER_MODE) {
451+
_prevRenderTransform = transform;
452+
}
450453

451454
batch.setPipeline(getParabolaPipeline(args->_renderMethod == render::Args::RenderMethod::FORWARD));
452455

@@ -481,4 +484,4 @@ namespace render {
481484
template <> const ShapeKey shapeGetShapeKey(const ParabolaPointer::RenderState::ParabolaRenderItem::Pointer& payload) {
482485
return ShapeKey::Builder::ownPipeline();
483486
}
484-
}
487+
}

0 commit comments

Comments
 (0)