History

Progress towards shadow maps.

Andrzej Kapolka committed 12 years ago

Commit 5cc5d9b1 parent 893eadc9 files · +188 −48Browse files

Showing the changes to interface/src/Application.cpp (1 of 9 files). Show all

Unified · Split

interface/src/Application.cpp+139−42
@@ -424,12 +424,15 @@ void Application::paintGL() { · 423 unmodified lines
424 whichCamera = _viewFrustumOffsetCamera;424 whichCamera = _viewFrustumOffsetCamera;
425 } 425 }
426 426
427 if (Menu::getInstance()->isOptionChecked(MenuOption::Shadows)) {
428 updateShadowMap();
429 }
430
427 if (OculusManager::isConnected()) {431 if (OculusManager::isConnected()) {
428 displayOculus(whichCamera);432 displayOculus(whichCamera);
429 433
430 } else {434 } else {
431 _glowEffect.prepare(); 435 _glowEffect.prepare();
432
433 436
434 glMatrixMode(GL_MODELVIEW);437 glMatrixMode(GL_MODELVIEW);
435 glPushMatrix();438 glPushMatrix();
@@ -2754,6 +2757,76 @@ void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) { · 2318 unmodified lines
2754 viewFrustum.calculate();2757 viewFrustum.calculate();
2755}2758}
2756 2759
2760glm::vec3 Application::getSunDirection() {
2761 return glm::normalize(_environment.getClosestData(_myCamera.getPosition()).getSunLocation() - _myCamera.getPosition());
2762}
2763
2764void 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// this shader is an adaptation (HLSL -> GLSL, removed conditional) of the one in the Oculus sample2830// this shader is an adaptation (HLSL -> GLSL, removed conditional) of the one in the Oculus sample
2758// code (Samples/OculusRoomTiny/RenderTiny_D3D1X_Device.cpp), which is under the Apache license2831// code (Samples/OculusRoomTiny/RenderTiny_D3D1X_Device.cpp), which is under the Apache license
2759// (http://www.apache.org/licenses/LICENSE-2.0)2832// (http://www.apache.org/licenses/LICENSE-2.0)
@@ -2896,15 +2969,14 @@ void Application::displayOculus(Camera& whichCamera) { · 136 unmodified lines
2896const GLfloat WHITE_SPECULAR_COLOR[] = { 1.0f, 1.0f, 1.0f, 1.0f };2969const GLfloat WHITE_SPECULAR_COLOR[] = { 1.0f, 1.0f, 1.0f, 1.0f };
2897const GLfloat NO_SPECULAR_COLOR[] = { 0.0f, 0.0f, 0.0f, 1.0f };2970const GLfloat NO_SPECULAR_COLOR[] = { 0.0f, 0.0f, 0.0f, 1.0f };
2898 2971
2899void Application::setupWorldLight(Camera& whichCamera) {2972void Application::setupWorldLight() {
2900 2973
2901 // Setup 3D lights (after the camera transform, so that they are positioned in world space)2974 // Setup 3D lights (after the camera transform, so that they are positioned in world space)
2902 glEnable(GL_COLOR_MATERIAL);2975 glEnable(GL_COLOR_MATERIAL);
2903 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);2976 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
2904 2977
2905 glm::vec3 relativeSunLoc = glm::normalize(_environment.getClosestData(whichCamera.getPosition()).getSunLocation() -2978 glm::vec3 sunDirection = getSunDirection();
2906 whichCamera.getPosition());2979 GLfloat light_position0[] = { sunDirection.x, sunDirection.y, sunDirection.z, 0.0 };
2907 GLfloat light_position0[] = { relativeSunLoc.x, relativeSunLoc.y, relativeSunLoc.z, 0.0 };
2908 glLightfv(GL_LIGHT0, GL_POSITION, light_position0);2980 glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
2909 GLfloat ambient_color[] = { 0.7, 0.7, 0.8 };2981 GLfloat ambient_color[] = { 0.7, 0.7, 0.8 };
2910 glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_color);2982 glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_color);
@@ -2962,7 +3034,7 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) { · 51 unmodified lines
2962 glTranslatef(_viewMatrixTranslation.x, _viewMatrixTranslation.y, _viewMatrixTranslation.z);3034 glTranslatef(_viewMatrixTranslation.x, _viewMatrixTranslation.y, _viewMatrixTranslation.z);
2963 3035
2964 // Setup 3D lights (after the camera transform, so that they are positioned in world space)3036 // Setup 3D lights (after the camera transform, so that they are positioned in world space)
2965 setupWorldLight(whichCamera);3037 setupWorldLight();
2966 3038
2967 if (!selfAvatarOnly && Menu::getInstance()->isOptionChecked(MenuOption::Stars)) {3039 if (!selfAvatarOnly && Menu::getInstance()->isOptionChecked(MenuOption::Stars)) {
2968 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), 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)) {3176 renderAvatars(whichCamera, selfAvatarOnly);
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));
3133 3177
3134 if (Menu::getInstance()->isOptionChecked(MenuOption::LookAtIndicator) && _lookatTargetAvatar) {3178 _myAvatar.renderScreenTint(SCREEN_TINT_AFTER_AVATARS);
3135 renderLookatIndicator(_lookatOtherPosition, whichCamera);
3136 }
3137 }
3138
3139 _myAvatar.renderScreenTint(SCREEN_TINT_AFTER_AVATARS, whichCamera);
3140 3179
3141 if (!selfAvatarOnly) {3180 if (!selfAvatarOnly) {
3142 // Render the world box3181 // Render the world box
@@ -3336,6 +3375,29 @@ void Application::displayOverlay() { · 193 unmodified lines
3336 // render the webcam input frame3375 // render the webcam input frame
3337 _webcam.renderPreview(_glWidget->width(), _glWidget->height());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 _palette.render(_glWidget->width(), _glWidget->height());3401 _palette.render(_glWidget->width(), _glWidget->height());
3340 3402
3341 QAction* paintColorAction = NULL;3403 QAction* paintColorAction = NULL;
@@ -3758,7 +3820,42 @@ void Application::renderCoverageMapsRecursively(CoverageMap* map) { · 416 unmodified lines
3758 }3820 }
3759}3821}
3760 3822
3823void 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// renderViewFrustum()3860// renderViewFrustum()
3764//3861//

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t