Showing the changes to interface/src/Application.cpp (1 of 6 files). Show all
Unified · Split
| @@ -2138,6 +2138,7 @@ void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) { · 2137 unmodified lines | ||
| 2138 | 2138 | viewFrustum.setOrientation(rotation); |
| 2139 | 2139 | |
| 2140 | 2140 | // Also make sure it's got the correct lens details from the camera |
| 2141 | + viewFrustum.setOrthographic(false); | |
| 2141 | 2142 | viewFrustum.setAspectRatio(aspectRatio); |
| 2142 | 2143 | viewFrustum.setFieldOfView(fov); // degrees |
| 2143 | 2144 | viewFrustum.setNearClip(nearClip); |
| @@ -2163,21 +2164,22 @@ void Application::updateShadowMap() { · 19 unmodified lines | ||
| 2163 | 2164 | glViewport(0, 0, fbo->width(), fbo->height()); |
| 2164 | 2165 | |
| 2165 | 2166 | glm::vec3 lightDirection = -getSunDirection(); |
| 2166 | − glm::quat rotation = glm::inverse(rotationBetween(IDENTITY_FRONT, lightDirection)); | |
| 2167 | − glm::vec3 translation = glm::vec3(); | |
| 2167 | + glm::quat rotation = rotationBetween(IDENTITY_FRONT, lightDirection); | |
| 2168 | + glm::quat inverseRotation = glm::inverse(rotation); | |
| 2168 | 2169 | float nearScale = 0.0f; |
| 2169 | 2170 | const float MAX_SHADOW_DISTANCE = 2.0f; |
| 2170 | − float farScale = (MAX_SHADOW_DISTANCE - _viewFrustum.getNearClip()) / (_viewFrustum.getFarClip() - _viewFrustum.getNearClip()); | |
| 2171 | + float farScale = (MAX_SHADOW_DISTANCE - _viewFrustum.getNearClip()) / | |
| 2172 | + (_viewFrustum.getFarClip() - _viewFrustum.getNearClip()); | |
| 2171 | 2173 | loadViewFrustum(_myCamera, _viewFrustum); |
| 2172 | 2174 | glm::vec3 points[] = { |
| 2173 | − rotation * (glm::mix(_viewFrustum.getNearTopLeft(), _viewFrustum.getFarTopLeft(), nearScale) + translation), | |
| 2174 | − rotation * (glm::mix(_viewFrustum.getNearTopRight(), _viewFrustum.getFarTopRight(), nearScale) + translation), | |
| 2175 | − rotation * (glm::mix(_viewFrustum.getNearBottomLeft(), _viewFrustum.getFarBottomLeft(), nearScale) + translation), | |
| 2176 | − rotation * (glm::mix(_viewFrustum.getNearBottomRight(), _viewFrustum.getFarBottomRight(), nearScale) + translation), | |
| 2177 | − rotation * (glm::mix(_viewFrustum.getNearTopLeft(), _viewFrustum.getFarTopLeft(), farScale) + translation), | |
| 2178 | − rotation * (glm::mix(_viewFrustum.getNearTopRight(), _viewFrustum.getFarTopRight(), farScale) + translation), | |
| 2179 | − rotation * (glm::mix(_viewFrustum.getNearBottomLeft(), _viewFrustum.getFarBottomLeft(), farScale) + translation), | |
| 2180 | − rotation * (glm::mix(_viewFrustum.getNearBottomRight(), _viewFrustum.getFarBottomRight(), farScale) + translation) }; | |
| 2175 | + inverseRotation * (glm::mix(_viewFrustum.getNearTopLeft(), _viewFrustum.getFarTopLeft(), nearScale)), | |
| 2176 | + inverseRotation * (glm::mix(_viewFrustum.getNearTopRight(), _viewFrustum.getFarTopRight(), nearScale)), | |
| 2177 | + inverseRotation * (glm::mix(_viewFrustum.getNearBottomLeft(), _viewFrustum.getFarBottomLeft(), nearScale)), | |
| 2178 | + inverseRotation * (glm::mix(_viewFrustum.getNearBottomRight(), _viewFrustum.getFarBottomRight(), nearScale)), | |
| 2179 | + inverseRotation * (glm::mix(_viewFrustum.getNearTopLeft(), _viewFrustum.getFarTopLeft(), farScale)), | |
| 2180 | + inverseRotation * (glm::mix(_viewFrustum.getNearTopRight(), _viewFrustum.getFarTopRight(), farScale)), | |
| 2181 | + inverseRotation * (glm::mix(_viewFrustum.getNearBottomLeft(), _viewFrustum.getFarBottomLeft(), farScale)), | |
| 2182 | + inverseRotation * (glm::mix(_viewFrustum.getNearBottomRight(), _viewFrustum.getFarBottomRight(), farScale)) }; | |
| 2181 | 2183 | glm::vec3 minima(FLT_MAX, FLT_MAX, FLT_MAX), maxima(-FLT_MAX, -FLT_MAX, -FLT_MAX); |
| 2182 | 2184 | for (size_t i = 0; i < sizeof(points) / sizeof(points[0]); i++) { |
| 2183 | 2185 | minima = glm::min(minima, points[i]); |
| @@ -2190,9 +2192,20 @@ void Application::updateShadowMap() { · 6 unmodified lines | ||
| 2190 | 2192 | |
| 2191 | 2193 | // save the combined matrix for rendering |
| 2192 | 2194 | _shadowMatrix = glm::transpose(glm::translate(glm::vec3(0.5f, 0.5f, 0.5f)) * glm::scale(glm::vec3(0.5f, 0.5f, 0.5f)) * |
| 2193 | − glm::ortho(minima.x, maxima.x, minima.y, maxima.y, -maxima.z, -minima.z) * | |
| 2194 | − glm::mat4_cast(rotation) * glm::translate(translation)); | |
| 2195 | − | |
| 2195 | + glm::ortho(minima.x, maxima.x, minima.y, maxima.y, -maxima.z, -minima.z) * glm::mat4_cast(inverseRotation)); | |
| 2196 | + | |
| 2197 | + // update the shadow view frustum | |
| 2198 | + _shadowViewFrustum.setPosition(rotation * ((minima + maxima) * 0.5f)); | |
| 2199 | + _shadowViewFrustum.setOrientation(rotation); | |
| 2200 | + _shadowViewFrustum.setOrthographic(true); | |
| 2201 | + _shadowViewFrustum.setWidth(maxima.x - minima.x); | |
| 2202 | + _shadowViewFrustum.setHeight(maxima.y - minima.y); | |
| 2203 | + _shadowViewFrustum.setNearClip(minima.z); | |
| 2204 | + _shadowViewFrustum.setFarClip(maxima.z); | |
| 2205 | + _shadowViewFrustum.setEyeOffsetPosition(glm::vec3()); | |
| 2206 | + _shadowViewFrustum.setEyeOffsetOrientation(glm::quat()); | |
| 2207 | + _shadowViewFrustum.calculate(); | |
| 2208 | + | |
| 2196 | 2209 | glMatrixMode(GL_PROJECTION); |
| 2197 | 2210 | glPushMatrix(); |
| 2198 | 2211 | glLoadIdentity(); |
| @@ -2206,9 +2219,7 @@ void Application::updateShadowMap() { · 7 unmodified lines | ||
| 2206 | 2219 | |
| 2207 | 2220 | // store view matrix without translation, which we'll use for precision-sensitive objects |
| 2208 | 2221 | glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat*)&_untranslatedViewMatrix); |
| 2209 | − _viewMatrixTranslation = translation; | |
| 2210 | − | |
| 2211 | − glTranslatef(translation.x, translation.y, translation.z); | |
| 2222 | + _viewMatrixTranslation = glm::vec3(); | |
| 2212 | 2223 | |
| 2213 | 2224 | _avatarManager.renderAvatars(Avatar::SHADOW_RENDER_MODE); |
| 2214 | 2225 | _particles.render(); |