mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 17:03:58 +02:00
FInd one of the issue with shadows for avatars
This commit is contained in:
parent
7718680091
commit
423434af10
4 changed files with 38 additions and 18 deletions
|
@ -2716,6 +2716,10 @@ void Application::updateShadowMap() {
|
|||
glLoadIdentity();
|
||||
glOrtho(minima.x, maxima.x, minima.y, maxima.y, -maxima.z, -minima.z);
|
||||
|
||||
glm::mat4 projAgain;
|
||||
glGetFloatv(GL_PROJECTION_MATRIX, (GLfloat*)&projAgain);
|
||||
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
|
|
|
@ -337,8 +337,13 @@ void Avatar::render(const glm::vec3& cameraPosition, RenderMode renderMode, bool
|
|||
|
||||
// simple frustum check
|
||||
float boundingRadius = getBillboardSize();
|
||||
ViewFrustum* frustum = (renderMode == Avatar::SHADOW_RENDER_MODE) ?
|
||||
Application::getInstance()->getShadowViewFrustum() : Application::getInstance()->getDisplayViewFrustum();
|
||||
|
||||
ViewFrustum* frustum = nullptr;
|
||||
if (renderMode == Avatar::SHADOW_RENDER_MODE) {
|
||||
frustum = Application::getInstance()->getShadowViewFrustum();
|
||||
} else {
|
||||
frustum = Application::getInstance()->getDisplayViewFrustum();
|
||||
}
|
||||
if (frustum->sphereInFrustum(getPosition(), boundingRadius) == ViewFrustum::OUTSIDE) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1005,22 +1005,25 @@ void MyAvatar::renderBody(ViewFrustum* renderFrustum, RenderMode renderMode, boo
|
|||
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;
|
||||
// Only tweak the frustum near far if it's not shadow
|
||||
if (renderMode != SHADOW_RENDER_MODE) {
|
||||
// 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);
|
||||
}
|
||||
renderFrustum->setNearClip(clipDistance);
|
||||
}
|
||||
|
||||
// Render the body's voxels and head
|
||||
|
|
|
@ -673,7 +673,11 @@ bool Model::renderCore(float alpha, RenderMode mode, RenderArgs* args) {
|
|||
// Setup the projection matrix
|
||||
if (args && args->_viewFrustum) {
|
||||
glm::mat4 proj;
|
||||
args->_viewFrustum->evalProjectionMatrix(proj);
|
||||
if (mode == RenderArgs::SHADOW_RENDER_MODE) {
|
||||
args->_viewFrustum->evalProjectionMatrix(proj);
|
||||
} else {
|
||||
args->_viewFrustum->evalProjectionMatrix(proj);
|
||||
}
|
||||
batch.setProjectionTransform(proj);
|
||||
}
|
||||
|
||||
|
@ -1759,7 +1763,11 @@ void Model::endScene(RenderMode mode, RenderArgs* args) {
|
|||
|
||||
if (args) {
|
||||
glm::mat4 proj;
|
||||
args->_viewFrustum->evalProjectionMatrix(proj);
|
||||
if (mode == RenderArgs::SHADOW_RENDER_MODE) {
|
||||
args->_viewFrustum->evalProjectionMatrix(proj);
|
||||
} else {
|
||||
args->_viewFrustum->evalProjectionMatrix(proj);
|
||||
}
|
||||
gpu::Batch batch;
|
||||
batch.setProjectionTransform(proj);
|
||||
backend.render(batch);
|
||||
|
|
Loading…
Reference in a new issue