Showing the changes to interface/src/Application.cpp (1 of 1 file). Show all
Unified · Split
| @@ -2990,128 +2990,6 @@ static QThread * activeRenderingThread = nullptr; · 2989 unmodified lines | |||
| 2990 | 2990 | ||
| 2991 | void Application::updateShadowMap(RenderArgs* renderArgs) { | 2991 | void Application::updateShadowMap(RenderArgs* renderArgs) { |
| 2992 | // TODO fix shadows and make them use the GPU library | 2992 | // TODO fix shadows and make them use the GPU library |
| 2993 | #if 0 | ||
| 2994 | activeRenderingThread = QThread::currentThread(); | ||
| 2995 | |||
| 2996 | PerformanceTimer perfTimer("shadowMap"); | ||
| 2997 | auto shadowFramebuffer = DependencyManager::get<TextureCache>()->getShadowFramebuffer(); | ||
| 2998 | |||
| 2999 | { | ||
| 3000 | gpu::Batch batch; | ||
| 3001 | auto primaryFbo = DependencyManager::get<TextureCache>()->getPrimaryFramebuffer(); | ||
| 3002 | batch.setFramebuffer(shadowFramebuffer); | ||
| 3003 | // clear the normal and specular buffers | ||
| 3004 | batch.clearFramebuffer( | ||
| 3005 | gpu::Framebuffer::BUFFER_DEPTH, | ||
| 3006 | vec4(vec3(0), 1), 1.0, 0.0); | ||
| 3007 | // Viewport is assigned to the size of the framebuffer | ||
| 3008 | QSize size = DependencyManager::get<TextureCache>()->getFrameBufferSize(); | ||
| 3009 | renderArgs->_context->render(batch); | ||
| 3010 | } | ||
| 3011 | |||
| 3012 | glm::vec3 lightDirection = getSunDirection(); | ||
| 3013 | glm::quat rotation = rotationBetween(IDENTITY_FRONT, lightDirection); | ||
| 3014 | glm::quat inverseRotation = glm::inverse(rotation); | ||
| 3015 | |||
| 3016 | const float SHADOW_MATRIX_DISTANCES[] = { 0.0f, 2.0f, 6.0f, 14.0f, 30.0f }; | ||
| 3017 | const glm::vec2 MAP_COORDS[] = { glm::vec2(0.0f, 0.0f), glm::vec2(0.5f, 0.0f), | ||
| 3018 | glm::vec2(0.0f, 0.5f), glm::vec2(0.5f, 0.5f) }; | ||
| 3019 | |||
| 3020 | float frustumScale = 1.0f / (_viewFrustum.getFarClip() - _viewFrustum.getNearClip()); | ||
| 3021 | loadViewFrustum(_myCamera, _viewFrustum); | ||
| 3022 | |||
| 3023 | int matrixCount = 1; | ||
| 3024 | //int targetSize = fbo->width(); | ||
| 3025 | int sourceSize = shadowFramebuffer->getWidth(); | ||
| 3026 | int targetSize = shadowFramebuffer->getWidth(); | ||
| 3027 | float targetScale = 1.0f; | ||
| 3028 | if (Menu::getInstance()->isOptionChecked(MenuOption::CascadedShadows)) { | ||
| 3029 | matrixCount = CASCADED_SHADOW_MATRIX_COUNT; | ||
| 3030 | targetSize = sourceSize / 2; | ||
| 3031 | targetScale = 0.5f; | ||
| 3032 | } | ||
| 3033 | for (int i = 0; i < matrixCount; i++) { | ||
| 3034 | const glm::vec2& coord = MAP_COORDS[i]; | ||
| 3035 | glViewport(coord.s * sourceSize, coord.t * sourceSize, targetSize, targetSize); | ||
| 3036 | |||
| 3037 | // if simple shadow then since the resolution is twice as much as with cascaded, cover 2 regions with the map, not just one | ||
| 3038 | int regionIncrement = (matrixCount == 1 ? 2 : 1); | ||
| 3039 | float nearScale = SHADOW_MATRIX_DISTANCES[i] * frustumScale; | ||
| 3040 | float farScale = SHADOW_MATRIX_DISTANCES[i + regionIncrement] * frustumScale; | ||
| 3041 | glm::vec3 points[] = { | ||
| 3042 | glm::mix(_viewFrustum.getNearTopLeft(), _viewFrustum.getFarTopLeft(), nearScale), | ||
| 3043 | glm::mix(_viewFrustum.getNearTopRight(), _viewFrustum.getFarTopRight(), nearScale), | ||
| 3044 | glm::mix(_viewFrustum.getNearBottomLeft(), _viewFrustum.getFarBottomLeft(), nearScale), | ||
| 3045 | glm::mix(_viewFrustum.getNearBottomRight(), _viewFrustum.getFarBottomRight(), nearScale), | ||
| 3046 | glm::mix(_viewFrustum.getNearTopLeft(), _viewFrustum.getFarTopLeft(), farScale), | ||
| 3047 | glm::mix(_viewFrustum.getNearTopRight(), _viewFrustum.getFarTopRight(), farScale), | ||
| 3048 | glm::mix(_viewFrustum.getNearBottomLeft(), _viewFrustum.getFarBottomLeft(), farScale), | ||
| 3049 | glm::mix(_viewFrustum.getNearBottomRight(), _viewFrustum.getFarBottomRight(), farScale) }; | ||
| 3050 | glm::vec3 center; | ||
| 3051 | for (size_t j = 0; j < sizeof(points) / sizeof(points[0]); j++) { | ||
| 3052 | center += points[j]; | ||
| 3053 | } | ||
| 3054 | center /= (float)(sizeof(points) / sizeof(points[0])); | ||
| 3055 | float radius = 0.0f; | ||
| 3056 | for (size_t j = 0; j < sizeof(points) / sizeof(points[0]); j++) { | ||
| 3057 | radius = qMax(radius, glm::distance(points[j], center)); | ||
| 3058 | } | ||
| 3059 | if (i < 3) { | ||
| 3060 | const float RADIUS_SCALE = 0.5f; | ||
| 3061 | _shadowDistances[i] = -glm::distance(_viewFrustum.getPosition(), center) - radius * RADIUS_SCALE; | ||
| 3062 | } | ||
| 3063 | center = inverseRotation * center; | ||
| 3064 | |||
| 3065 | // to reduce texture "shimmer," move in texel increments | ||
| 3066 | float texelSize = (2.0f * radius) / targetSize; | ||
| 3067 | center = glm::vec3(roundf(center.x / texelSize) * texelSize, roundf(center.y / texelSize) * texelSize, | ||
| 3068 | roundf(center.z / texelSize) * texelSize); | ||
| 3069 | |||
| 3070 | glm::vec3 minima(center.x - radius, center.y - radius, center.z - radius); | ||
| 3071 | glm::vec3 maxima(center.x + radius, center.y + radius, center.z + radius); | ||
| 3072 | |||
| 3073 | // stretch out our extents in z so that we get all of the avatars | ||
| 3074 | minima.z -= _viewFrustum.getFarClip() * 0.5f; | ||
| 3075 | maxima.z += _viewFrustum.getFarClip() * 0.5f; | ||
| 3076 | |||
| 3077 | // save the combined matrix for rendering | ||
| 3078 | _shadowMatrices[i] = glm::transpose(glm::translate(glm::vec3(coord, 0.0f)) * | ||
| 3079 | glm::scale(glm::vec3(targetScale, targetScale, 1.0f)) * | ||
| 3080 | glm::translate(glm::vec3(0.5f, 0.5f, 0.5f)) * glm::scale(glm::vec3(0.5f, 0.5f, 0.5f)) * | ||
| 3081 | glm::ortho(minima.x, maxima.x, minima.y, maxima.y, -maxima.z, -minima.z) * glm::mat4_cast(inverseRotation)); | ||
| 3082 | |||
| 3083 | // update the shadow view frustum | ||
| 3084 | // glm::vec3 shadowFrustumCenter = glm::vec3((minima.x + maxima.x) * 0.5f, (minima.y + maxima.y) * 0.5f, (minima.z + maxima.z) * 0.5f); | ||
| 3085 | glm::vec3 shadowFrustumCenter = rotation * ((minima + maxima) * 0.5f); | ||
| 3086 | _shadowViewFrustum.setPosition(shadowFrustumCenter); | ||
| 3087 | _shadowViewFrustum.setOrientation(rotation); | ||
| 3088 | _shadowViewFrustum.setProjection(glm::ortho(minima.x, maxima.x, minima.y, maxima.y, minima.z, maxima.z)); | ||
| 3089 | _shadowViewFrustum.calculate(); | ||
| 3090 | |||
| 3091 | // store view matrix without translation, which we'll use for precision-sensitive objects | ||
| 3092 | updateUntranslatedViewMatrix(); | ||
| 3093 | // Equivalent to what is happening with _untranslatedViewMatrix and the _viewMatrixTranslation | ||
| 3094 | // the viewTransofmr object is updatded with the correct values and saved, | ||
| 3095 | // this is what is used for rendering the Entities and avatars | ||
| 3096 | Transform viewTransform; | ||
| 3097 | viewTransform.setRotation(rotation); | ||
| 3098 | setViewTransform(viewTransform); | ||
| 3099 | |||
| 3100 | |||
| 3101 | glEnable(GL_POLYGON_OFFSET_FILL); | ||
| 3102 | glPolygonOffset(1.1f, 4.0f); // magic numbers courtesy http://www.eecs.berkeley.edu/~ravir/6160/papers/shadowmaps.ppt | ||
| 3103 | |||
| 3104 | { | ||
| 3105 | PerformanceTimer perfTimer("entities"); | ||
| 3106 | _entities.render(renderArgs); | ||
| 3107 | } | ||
| 3108 | |||
| 3109 | glDisable(GL_POLYGON_OFFSET_FILL); | ||
| 3110 | } | ||
| 3111 | |||
| 3112 | glViewport(0, 0, _glWidget->getDeviceWidth(), _glWidget->getDeviceHeight()); | ||
| 3113 | activeRenderingThread = nullptr; | ||
| 3114 | #endif | ||
| 3115 | } | 2993 | } |
| 3116 | 2994 | ||
| 3117 | void Application::setupWorldLight(RenderArgs* renderArgs) { | 2995 | void Application::setupWorldLight(RenderArgs* renderArgs) { |
| @@ -3386,21 +3264,7 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 268 unmodified lines | |||
| 3386 | } | 3264 | } |
| 3387 | 3265 | ||
| 3388 | // TODO fix shadows and make them use the GPU library | 3266 | // TODO fix shadows and make them use the GPU library |
| 3389 | #if 0 | 3267 | |
| 3390 | // setup shadow matrices (again, after the camera transform) | ||
| 3391 | int shadowMatrixCount = 0; | ||
| 3392 | if (Menu::getInstance()->isOptionChecked(MenuOption::SimpleShadows)) { | ||
| 3393 | shadowMatrixCount = 1; | ||
| 3394 | } else if (Menu::getInstance()->isOptionChecked(MenuOption::CascadedShadows)) { | ||
| 3395 | shadowMatrixCount = CASCADED_SHADOW_MATRIX_COUNT; | ||
| 3396 | } | ||
| 3397 | for (int i = shadowMatrixCount - 1; i >= 0; i--) { | ||
| 3398 | glActiveTexture(GL_TEXTURE0 + i); | ||
| 3399 | glTexGenfv(GL_S, GL_EYE_PLANE, (const GLfloat*)&_shadowMatrices[i][0]); | ||
| 3400 | glTexGenfv(GL_T, GL_EYE_PLANE, (const GLfloat*)&_shadowMatrices[i][1]); | ||
| 3401 | glTexGenfv(GL_R, GL_EYE_PLANE, (const GLfloat*)&_shadowMatrices[i][2]); | ||
| 3402 | } | ||
| 3403 | #endif | ||
| 3404 | // The pending changes collecting the changes here | 3268 | // The pending changes collecting the changes here |
| 3405 | render::PendingChanges pendingChanges; | 3269 | render::PendingChanges pendingChanges; |
| 3406 | 3270 | ||