Showing the changes to interface/src/Application.cpp (1 of 9 files). Show all
Unified · Split
| @@ -424,12 +424,15 @@ void Application::paintGL() { · 423 unmodified lines | ||
| 424 | 424 | whichCamera = _viewFrustumOffsetCamera; |
| 425 | 425 | } |
| 426 | 426 | |
| 427 | + if (Menu::getInstance()->isOptionChecked(MenuOption::Shadows)) { | |
| 428 | + updateShadowMap(); | |
| 429 | + } | |
| 430 | + | |
| 427 | 431 | if (OculusManager::isConnected()) { |
| 428 | 432 | displayOculus(whichCamera); |
| 429 | 433 | |
| 430 | 434 | } else { |
| 431 | 435 | _glowEffect.prepare(); |
| 432 | − | |
| 433 | 436 | |
| 434 | 437 | glMatrixMode(GL_MODELVIEW); |
| 435 | 438 | glPushMatrix(); |
| @@ -2754,6 +2757,76 @@ void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) { · 2318 unmodified lines | ||
| 2754 | 2757 | viewFrustum.calculate(); |
| 2755 | 2758 | } |
| 2756 | 2759 | |
| 2760 | +glm::vec3 Application::getSunDirection() { | |
| 2761 | + return glm::normalize(_environment.getClosestData(_myCamera.getPosition()).getSunLocation() - _myCamera.getPosition()); | |
| 2762 | +} | |
| 2763 | + | |
| 2764 | +void Application::updateShadowMap() { | |
| 2765 | + QOpenGLFramebufferObject* fbo = _textureCache.getShadowFramebufferObject(); | |
| 2766 | + fbo->bind(); | |
| 2767 | + glEnable(GL_DEPTH_TEST); | |
| 2768 | + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |
| 2769 | + | |
| 2770 | + glViewport(0, 0, fbo->width(), fbo->height()); | |
| 2771 | + | |
| 2772 | + glm::vec3 lightDirection = -getSunDirection(); | |
| 2773 | + glm::quat rotation = glm::inverse(rotationBetween(IDENTITY_FRONT, lightDirection)); | |
| 2774 | + glm::vec3 translation = glm::vec3(); | |
| 2775 | + float nearScale = 0.0f; | |
| 2776 | + float farScale = 0.000001f; | |
| 2777 | + /* glm::vec3 points[] = { | |
| 2778 | + rotation * (glm::mix(_viewFrustum.getNearTopLeft(), _viewFrustum.getFarTopLeft(), nearScale) + translation), | |
| 2779 | + rotation * (glm::mix(_viewFrustum.getNearTopRight(), _viewFrustum.getFarTopRight(), nearScale) + translation), | |
| 2780 | + rotation * (glm::mix(_viewFrustum.getNearBottomLeft(), _viewFrustum.getFarBottomLeft(), nearScale) + translation), | |
| 2781 | + rotation * (glm::mix(_viewFrustum.getNearBottomRight(), _viewFrustum.getFarBottomRight(), nearScale) + translation), | |
| 2782 | + rotation * (glm::mix(_viewFrustum.getNearTopLeft(), _viewFrustum.getFarTopLeft(), farScale) + translation), | |
| 2783 | + rotation * (glm::mix(_viewFrustum.getNearTopRight(), _viewFrustum.getFarTopRight(), farScale) + translation), | |
| 2784 | + rotation * (glm::mix(_viewFrustum.getNearBottomLeft(), _viewFrustum.getFarBottomLeft(), farScale) + translation), | |
| 2785 | + rotation * (glm::mix(_viewFrustum.getNearBottomRight(), _viewFrustum.getFarBottomRight(), farScale) + translation) }; */ | |
| 2786 | + glm::vec3 points[] = { | |
| 2787 | + rotation * (_myAvatar.getPosition() + glm::vec3(-1, 0, 0) + translation), | |
| 2788 | + rotation * (_myAvatar.getPosition() + glm::vec3(1, 0, 0) + translation), | |
| 2789 | + rotation * (_myAvatar.getPosition() + glm::vec3(0, -1, 0) + translation), | |
| 2790 | + rotation * (_myAvatar.getPosition() + glm::vec3(0, 1, 0) + translation), | |
| 2791 | + rotation * (_myAvatar.getPosition() + glm::vec3(0, 0, -1) + translation), | |
| 2792 | + rotation * (_myAvatar.getPosition() + glm::vec3(0, 0, 1) + translation) }; | |
| 2793 | + glm::vec3 minima(FLT_MAX, FLT_MAX, FLT_MAX), maxima(-FLT_MAX, -FLT_MAX, -FLT_MAX); | |
| 2794 | + for (int i = 0; i < sizeof(points) / sizeof(points[0]); i++) { | |
| 2795 | + minima = glm::min(minima, points[i]); | |
| 2796 | + maxima = glm::max(maxima, points[i]); | |
| 2797 | + } | |
| 2798 | + | |
| 2799 | + glMatrixMode(GL_PROJECTION); | |
| 2800 | + glPushMatrix(); | |
| 2801 | + glLoadIdentity(); | |
| 2802 | + glOrtho(minima.x, maxima.x, minima.y, maxima.y, -maxima.z, -minima.z); | |
| 2803 | + | |
| 2804 | + glMatrixMode(GL_MODELVIEW); | |
| 2805 | + glPushMatrix(); | |
| 2806 | + glLoadIdentity(); | |
| 2807 | + glm::vec3 axis = glm::axis(rotation); | |
| 2808 | + glRotatef(glm::angle(rotation), axis.x, axis.y, axis.z); | |
| 2809 | + | |
| 2810 | + // store view matrix without translation, which we'll use for precision-sensitive objects | |
| 2811 | + glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat*)&_untranslatedViewMatrix); | |
| 2812 | + _viewMatrixTranslation = translation; | |
| 2813 | + | |
| 2814 | + glTranslatef(translation.x, translation.y, translation.z); | |
| 2815 | + | |
| 2816 | + renderAvatars(_myCamera); | |
| 2817 | + | |
| 2818 | + glPopMatrix(); | |
| 2819 | + | |
| 2820 | + glMatrixMode(GL_PROJECTION); | |
| 2821 | + glPopMatrix(); | |
| 2822 | + | |
| 2823 | + glMatrixMode(GL_MODELVIEW); | |
| 2824 | + | |
| 2825 | + fbo->release(); | |
| 2826 | + | |
| 2827 | + glViewport(0, 0, _glWidget->width(), _glWidget->height()); | |
| 2828 | +} | |
| 2829 | + | |
| 2757 | 2830 | // this shader is an adaptation (HLSL -> GLSL, removed conditional) of the one in the Oculus sample |
| 2758 | 2831 | // code (Samples/OculusRoomTiny/RenderTiny_D3D1X_Device.cpp), which is under the Apache license |
| 2759 | 2832 | // (http://www.apache.org/licenses/LICENSE-2.0) |
| @@ -2896,15 +2969,14 @@ void Application::displayOculus(Camera& whichCamera) { · 136 unmodified lines | ||
| 2896 | 2969 | const GLfloat WHITE_SPECULAR_COLOR[] = { 1.0f, 1.0f, 1.0f, 1.0f }; |
| 2897 | 2970 | const GLfloat NO_SPECULAR_COLOR[] = { 0.0f, 0.0f, 0.0f, 1.0f }; |
| 2898 | 2971 | |
| 2899 | −void Application::setupWorldLight(Camera& whichCamera) { | |
| 2972 | +void Application::setupWorldLight() { | |
| 2900 | 2973 | |
| 2901 | 2974 | // Setup 3D lights (after the camera transform, so that they are positioned in world space) |
| 2902 | 2975 | glEnable(GL_COLOR_MATERIAL); |
| 2903 | 2976 | glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); |
| 2904 | 2977 | |
| 2905 | − glm::vec3 relativeSunLoc = glm::normalize(_environment.getClosestData(whichCamera.getPosition()).getSunLocation() - | |
| 2906 | − whichCamera.getPosition()); | |
| 2907 | − GLfloat light_position0[] = { relativeSunLoc.x, relativeSunLoc.y, relativeSunLoc.z, 0.0 }; | |
| 2978 | + glm::vec3 sunDirection = getSunDirection(); | |
| 2979 | + GLfloat light_position0[] = { sunDirection.x, sunDirection.y, sunDirection.z, 0.0 }; | |
| 2908 | 2980 | glLightfv(GL_LIGHT0, GL_POSITION, light_position0); |
| 2909 | 2981 | GLfloat ambient_color[] = { 0.7, 0.7, 0.8 }; |
| 2910 | 2982 | glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_color); |
| @@ -2962,7 +3034,7 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) { · 51 unmodified lines | ||
| 2962 | 3034 | glTranslatef(_viewMatrixTranslation.x, _viewMatrixTranslation.y, _viewMatrixTranslation.z); |
| 2963 | 3035 | |
| 2964 | 3036 | // Setup 3D lights (after the camera transform, so that they are positioned in world space) |
| 2965 | − setupWorldLight(whichCamera); | |
| 3037 | + setupWorldLight(); | |
| 2966 | 3038 | |
| 2967 | 3039 | if (!selfAvatarOnly && Menu::getInstance()->isOptionChecked(MenuOption::Stars)) { |
| 2968 | 3040 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), |
| @@ -3099,44 +3171,11 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) { · 130 unmodified lines | ||
| 3099 | 3171 | } |
| 3100 | 3172 | } |
| 3101 | 3173 | |
| 3102 | − _myAvatar.renderScreenTint(SCREEN_TINT_BEFORE_AVATARS, whichCamera); | |
| 3174 | + _myAvatar.renderScreenTint(SCREEN_TINT_BEFORE_AVATARS); | |
| 3103 | 3175 | |
| 3104 | − if (Menu::getInstance()->isOptionChecked(MenuOption::Avatars)) { | |
| 3105 | − PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), | |
| 3106 | − "Application::displaySide() ... Avatars..."); | |
| 3107 | − | |
| 3108 | − | |
| 3109 | − if (!selfAvatarOnly) { | |
| 3110 | − // Render avatars of other nodes | |
| 3111 | − NodeList* nodeList = NodeList::getInstance(); | |
| 3112 | − | |
| 3113 | − for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { | |
| 3114 | − node->lock(); | |
| 3115 | − | |
| 3116 | − if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) { | |
| 3117 | − Avatar *avatar = (Avatar *)node->getLinkedData(); | |
| 3118 | − if (!avatar->isInitialized()) { | |
| 3119 | − avatar->init(); | |
| 3120 | − } | |
| 3121 | − avatar->render(false, Menu::getInstance()->isOptionChecked(MenuOption::AvatarAsBalls)); | |
| 3122 | − avatar->setDisplayingLookatVectors(Menu::getInstance()->isOptionChecked(MenuOption::LookAtVectors)); | |
| 3123 | − } | |
| 3124 | − | |
| 3125 | − node->unlock(); | |
| 3126 | − } | |
| 3127 | − } | |
| 3128 | − | |
| 3129 | − // Render my own Avatar | |
| 3130 | − _myAvatar.render(whichCamera.getMode() == CAMERA_MODE_MIRROR, | |
| 3131 | − Menu::getInstance()->isOptionChecked(MenuOption::AvatarAsBalls)); | |
| 3132 | − _myAvatar.setDisplayingLookatVectors(Menu::getInstance()->isOptionChecked(MenuOption::LookAtVectors)); | |
| 3176 | + renderAvatars(whichCamera, selfAvatarOnly); | |
| 3133 | 3177 | |
| 3134 | − if (Menu::getInstance()->isOptionChecked(MenuOption::LookAtIndicator) && _lookatTargetAvatar) { | |
| 3135 | − renderLookatIndicator(_lookatOtherPosition, whichCamera); | |
| 3136 | − } | |
| 3137 | − } | |
| 3138 | − | |
| 3139 | − _myAvatar.renderScreenTint(SCREEN_TINT_AFTER_AVATARS, whichCamera); | |
| 3178 | + _myAvatar.renderScreenTint(SCREEN_TINT_AFTER_AVATARS); | |
| 3140 | 3179 | |
| 3141 | 3180 | if (!selfAvatarOnly) { |
| 3142 | 3181 | // Render the world box |
| @@ -3336,6 +3375,29 @@ void Application::displayOverlay() { · 193 unmodified lines | ||
| 3336 | 3375 | // render the webcam input frame |
| 3337 | 3376 | _webcam.renderPreview(_glWidget->width(), _glWidget->height()); |
| 3338 | 3377 | |
| 3378 | + if (Menu::getInstance()->isOptionChecked(MenuOption::Shadows)) { | |
| 3379 | + glBindTexture(GL_TEXTURE_2D, _textureCache.getShadowDepthTextureID()); | |
| 3380 | + glEnable(GL_TEXTURE_2D); | |
| 3381 | + glColor3f(1.0f, 1.0f, 1.0f); | |
| 3382 | + | |
| 3383 | + glBegin(GL_QUADS); | |
| 3384 | + glTexCoord2f(0.0f, 0.0f); | |
| 3385 | + glVertex2f(500, 500); | |
| 3386 | + | |
| 3387 | + glTexCoord2f(1.0f, 0.0f); | |
| 3388 | + glVertex2f(1000, 500); | |
| 3389 | + | |
| 3390 | + glTexCoord2f(1.0f, 1.0f); | |
| 3391 | + glVertex2f(1000, 0); | |
| 3392 | + | |
| 3393 | + glTexCoord2f(0.0f, 1.0f); | |
| 3394 | + glVertex2f(500, 0); | |
| 3395 | + glEnd(); | |
| 3396 | + | |
| 3397 | + glDisable(GL_TEXTURE_2D); | |
| 3398 | + glBindTexture(GL_TEXTURE_2D, 0); | |
| 3399 | + } | |
| 3400 | + | |
| 3339 | 3401 | _palette.render(_glWidget->width(), _glWidget->height()); |
| 3340 | 3402 | |
| 3341 | 3403 | QAction* paintColorAction = NULL; |
| @@ -3758,7 +3820,42 @@ void Application::renderCoverageMapsRecursively(CoverageMap* map) { · 416 unmodified lines | ||
| 3758 | 3820 | } |
| 3759 | 3821 | } |
| 3760 | 3822 | |
| 3823 | +void Application::renderAvatars(Camera& whichCamera, bool selfAvatarOnly) { | |
| 3824 | + if (!Menu::getInstance()->isOptionChecked(MenuOption::Avatars)) { | |
| 3825 | + return; | |
| 3826 | + } | |
| 3827 | + PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), | |
| 3828 | + "Application::displaySide() ... Avatars..."); | |
| 3761 | 3829 | |
| 3830 | + if (!selfAvatarOnly) { | |
| 3831 | + // Render avatars of other nodes | |
| 3832 | + NodeList* nodeList = NodeList::getInstance(); | |
| 3833 | + | |
| 3834 | + for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { | |
| 3835 | + node->lock(); | |
| 3836 | + | |
| 3837 | + if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) { | |
| 3838 | + Avatar *avatar = (Avatar *)node->getLinkedData(); | |
| 3839 | + if (!avatar->isInitialized()) { | |
| 3840 | + avatar->init(); | |
| 3841 | + } | |
| 3842 | + avatar->render(false, Menu::getInstance()->isOptionChecked(MenuOption::AvatarAsBalls)); | |
| 3843 | + avatar->setDisplayingLookatVectors(Menu::getInstance()->isOptionChecked(MenuOption::LookAtVectors)); | |
| 3844 | + } | |
| 3845 | + | |
| 3846 | + node->unlock(); | |
| 3847 | + } | |
| 3848 | + } | |
| 3849 | + | |
| 3850 | + // Render my own Avatar | |
| 3851 | + _myAvatar.render(whichCamera.getMode() == CAMERA_MODE_MIRROR, | |
| 3852 | + Menu::getInstance()->isOptionChecked(MenuOption::AvatarAsBalls)); | |
| 3853 | + _myAvatar.setDisplayingLookatVectors(Menu::getInstance()->isOptionChecked(MenuOption::LookAtVectors)); | |
| 3854 | + | |
| 3855 | + if (Menu::getInstance()->isOptionChecked(MenuOption::LookAtIndicator) && _lookatTargetAvatar) { | |
| 3856 | + renderLookatIndicator(_lookatOtherPosition, whichCamera); | |
| 3857 | + } | |
| 3858 | +} | |
| 3762 | 3859 | |
| 3763 | 3860 | // renderViewFrustum() |
| 3764 | 3861 | // |