FInd one of the issue with shadows for avatars

This commit is contained in:
Sam Gateau 2015-04-03 12:34:30 -07:00
parent 7718680091
commit 423434af10
4 changed files with 38 additions and 18 deletions

View file

@ -2716,6 +2716,10 @@ void Application::updateShadowMap() {
glLoadIdentity(); glLoadIdentity();
glOrtho(minima.x, maxima.x, minima.y, maxima.y, -maxima.z, -minima.z); 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); glMatrixMode(GL_MODELVIEW);
glPushMatrix(); glPushMatrix();
glLoadIdentity(); glLoadIdentity();

View file

@ -337,8 +337,13 @@ void Avatar::render(const glm::vec3& cameraPosition, RenderMode renderMode, bool
// simple frustum check // simple frustum check
float boundingRadius = getBillboardSize(); 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) { if (frustum->sphereInFrustum(getPosition(), boundingRadius) == ViewFrustum::OUTSIDE) {
return; return;
} }

View file

@ -1005,22 +1005,25 @@ void MyAvatar::renderBody(ViewFrustum* renderFrustum, RenderMode renderMode, boo
Camera *camera = Application::getInstance()->getCamera(); Camera *camera = Application::getInstance()->getCamera();
const glm::vec3 cameraPos = camera->getPosition(); 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. // Only tweak the frustum near far if it's not shadow
if (shouldRenderHead(cameraPos, renderMode) || !getHead()->getFaceModel().getURL().isEmpty()) { if (renderMode != SHADOW_RENDER_MODE) {
renderFrustum->setNearClip(DEFAULT_NEAR_CLIP); // Set near clip distance according to skeleton model dimensions if first person and there is no separate head model.
} else { if (shouldRenderHead(cameraPos, renderMode) || !getHead()->getFaceModel().getURL().isEmpty()) {
float clipDistance = _skeletonModel.getHeadClipDistance(); renderFrustum->setNearClip(DEFAULT_NEAR_CLIP);
if (OculusManager::isConnected()) { } else {
// If avatar is horizontally in front of camera, increase clip distance by the amount it is in front. float clipDistance = _skeletonModel.getHeadClipDistance();
glm::vec3 cameraToAvatar = _position - cameraPos; if (OculusManager::isConnected()) {
cameraToAvatar.y = 0.0f; // If avatar is horizontally in front of camera, increase clip distance by the amount it is in front.
glm::vec3 cameraLookAt = camera->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f); glm::vec3 cameraToAvatar = _position - cameraPos;
float headOffset = glm::dot(cameraLookAt, cameraToAvatar); cameraToAvatar.y = 0.0f;
if (headOffset > 0) { glm::vec3 cameraLookAt = camera->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f);
clipDistance += headOffset; float headOffset = glm::dot(cameraLookAt, cameraToAvatar);
if (headOffset > 0) {
clipDistance += headOffset;
}
} }
renderFrustum->setNearClip(clipDistance);
} }
renderFrustum->setNearClip(clipDistance);
} }
// Render the body's voxels and head // Render the body's voxels and head

View file

@ -673,7 +673,11 @@ bool Model::renderCore(float alpha, RenderMode mode, RenderArgs* args) {
// Setup the projection matrix // Setup the projection matrix
if (args && args->_viewFrustum) { if (args && args->_viewFrustum) {
glm::mat4 proj; 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); batch.setProjectionTransform(proj);
} }
@ -1759,7 +1763,11 @@ void Model::endScene(RenderMode mode, RenderArgs* args) {
if (args) { if (args) {
glm::mat4 proj; 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; gpu::Batch batch;
batch.setProjectionTransform(proj); batch.setProjectionTransform(proj);
backend.render(batch); backend.render(batch);