Merge pull request #4468 from ctrlaltdavid/20399

CR for 20399 - Fix near field clipping on avatars with large heads
This commit is contained in:
Brad Hefta-Gaub 2015-03-19 20:02:17 -07:00
commit 96bfb96936
3 changed files with 32 additions and 4 deletions

View file

@ -1028,7 +1028,28 @@ void MyAvatar::renderBody(ViewFrustum* renderFrustum, RenderMode renderMode, boo
if (!(_skeletonModel.isRenderable() && getHead()->getFaceModel().isRenderable())) { if (!(_skeletonModel.isRenderable() && getHead()->getFaceModel().isRenderable())) {
return; // wait until both models are loaded return; // wait until both models are loaded
} }
Camera *camera = Application::getInstance()->getCamera();
const glm::vec3 cameraPos = camera->getPosition();
// Set near clip distance according to skeleton model dimensions if first person and there is no separate head model.
if (shouldRenderHead(cameraPos, renderMode) || !getHead()->getFaceModel().getURL().isEmpty()) {
renderFrustum->setNearClip(DEFAULT_NEAR_CLIP);
} else {
float clipDistance = _skeletonModel.getHeadClipDistance();
if (OculusManager::isConnected()) {
// If avatar is horizontally in front of camera, increase clip distance by the amount it is in front.
glm::vec3 cameraToAvatar = _position - cameraPos;
cameraToAvatar.y = 0.0f;
glm::vec3 cameraLookAt = camera->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f);
float headOffset = glm::dot(cameraLookAt, cameraToAvatar);
if (headOffset > 0) {
clipDistance += headOffset;
}
}
renderFrustum->setNearClip(clipDistance);
}
// Render the body's voxels and head // Render the body's voxels and head
Model::RenderMode modelRenderMode = (renderMode == SHADOW_RENDER_MODE) ? Model::RenderMode modelRenderMode = (renderMode == SHADOW_RENDER_MODE) ?
Model::SHADOW_RENDER_MODE : Model::DEFAULT_RENDER_MODE; Model::SHADOW_RENDER_MODE : Model::DEFAULT_RENDER_MODE;
@ -1040,8 +1061,6 @@ void MyAvatar::renderBody(ViewFrustum* renderFrustum, RenderMode renderMode, boo
} }
// Render head so long as the camera isn't inside it // Render head so long as the camera isn't inside it
const Camera *camera = Application::getInstance()->getCamera();
const glm::vec3 cameraPos = camera->getPosition();
if (shouldRenderHead(cameraPos, renderMode)) { if (shouldRenderHead(cameraPos, renderMode)) {
getHead()->render(1.0f, renderFrustum, modelRenderMode, postLighting); getHead()->render(1.0f, renderFrustum, modelRenderMode, postLighting);
} }

View file

@ -37,7 +37,8 @@ SkeletonModel::SkeletonModel(Avatar* owningAvatar, QObject* parent) :
_defaultEyeModelPosition(glm::vec3(0.0f, 0.0f, 0.0f)), _defaultEyeModelPosition(glm::vec3(0.0f, 0.0f, 0.0f)),
_standingFoot(NO_FOOT), _standingFoot(NO_FOOT),
_standingOffset(0.0f), _standingOffset(0.0f),
_clampedFootPosition(0.0f) _clampedFootPosition(0.0f),
_headClipDistance(DEFAULT_NEAR_CLIP)
{ {
} }
@ -78,6 +79,10 @@ void SkeletonModel::setJointStates(QVector<JointState> states) {
buildShapes(); buildShapes();
} }
Extents meshExtents = getMeshExtents();
_headClipDistance = -(meshExtents.minimum.z / _scale.z - _defaultEyeModelPosition.z);
_headClipDistance = std::max(_headClipDistance, DEFAULT_NEAR_CLIP);
emit skeletonLoaded(); emit skeletonLoaded();
} }

View file

@ -110,6 +110,8 @@ public:
bool hasSkeleton(); bool hasSkeleton();
float getHeadClipDistance() const { return _headClipDistance; }
signals: signals:
void skeletonLoaded(); void skeletonLoaded();
@ -160,6 +162,8 @@ private:
int _standingFoot; int _standingFoot;
glm::vec3 _standingOffset; glm::vec3 _standingOffset;
glm::vec3 _clampedFootPosition; glm::vec3 _clampedFootPosition;
float _headClipDistance; // Near clip distance to use if no separate head model
}; };
#endif // hifi_SkeletonModel_h #endif // hifi_SkeletonModel_h