From 073abf70478965df98d0af61554d0e132dc5ade8 Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Thu, 23 Apr 2009 02:27:11 +0000 Subject: BGE Dome update: * Enviroment Map implemented (replacing truncated mode 2). - Now it's possible to pre-bake animated (or static) EnvMaps to use with Cube Map textures. * Enabling 2DFilter in Dome mode - no GL_DEPTH_BUFFER supported though. * Tweaking GameSettings menu (centralizing buttons) --- source/blender/src/buttons_scene.c | 38 ++++--- source/gameengine/Ketsji/KX_Dome.cpp | 164 +++++++++++++++++++++++---- source/gameengine/Ketsji/KX_Dome.h | 3 +- source/gameengine/Ketsji/KX_KetsjiEngine.cpp | 4 +- 4 files changed, 166 insertions(+), 43 deletions(-) (limited to 'source') diff --git a/source/blender/src/buttons_scene.c b/source/blender/src/buttons_scene.c index f026e5f4034..577486135b4 100644 --- a/source/blender/src/buttons_scene.c +++ b/source/blender/src/buttons_scene.c @@ -1772,7 +1772,7 @@ static uiBlock *framing_render_menu(void *arg_unused) block= uiNewBlock(&curarea->uiblocks, "framing_options", UI_EMBOSS, UI_HELV, curarea->win); /* use this for a fake extra empy space around the buttons */ - uiDefBut(block, LABEL, 0, "", -5, -10, 295, 300, NULL, 0, 0, 0, 0, ""); + uiDefBut(block, LABEL, 0, "", -5, -10, 295, 305, NULL, 0, 0, 0, 0, ""); uiDefBut(block, LABEL, 0, "Framing:", xco, yco, 68,19, 0, 0, 0, 0, 0, ""); uiBlockBeginAlign(block); @@ -1787,16 +1787,17 @@ static uiBlock *framing_render_menu(void *arg_unused) uiDefButF(block, COL, 0, "", 0, yco - 58 + 18, 33, 58, &G.scene->framing.col[0], 0, 0, 0, randomcolorindex, ""); uiBlockBeginAlign(block); - uiDefButF(block, NUMSLI, 0, "R ", xco,yco,243,18, &G.scene->framing.col[0], 0.0, 1.0, randomcolorindex, 0, "Set the red component of the bars"); + uiDefButF(block, NUMSLI, 0, "R ", xco,yco,240,18, &G.scene->framing.col[0], 0.0, 1.0, randomcolorindex, 0, "Set the red component of the bars"); yco -= 20; - uiDefButF(block, NUMSLI, 0, "G ", xco,yco,243,18, &G.scene->framing.col[1], 0.0, 1.0, randomcolorindex, 0, "Set the green component of the bars"); + uiDefButF(block, NUMSLI, 0, "G ", xco,yco,240,18, &G.scene->framing.col[1], 0.0, 1.0, randomcolorindex, 0, "Set the green component of the bars"); yco -= 20; - uiDefButF(block, NUMSLI, 0, "B ", xco,yco,243,18, &G.scene->framing.col[2], 0.0, 1.0, randomcolorindex, 0, "Set the blue component of the bars"); + uiDefButF(block, NUMSLI, 0, "B ", xco,yco,240,18, &G.scene->framing.col[2], 0.0, 1.0, randomcolorindex, 0, "Set the blue component of the bars"); uiBlockEndAlign(block); xco = 0; uiDefBut(block, LABEL, 0, "Fullscreen:", xco, yco-=30, 100, 19, 0, 0.0, 0.0, 0, 0, ""); - uiDefButS(block, TOG, 0, "Fullscreen", xco+70, yco, 68, 19, &G.scene->r.fullscreen, 0.0, 0.0, 0, 0, "Starts player in a new fullscreen display"); + uiDefButS(block, TOG, 0, "Fullscreen", xco+74, yco, 68, 19, &G.scene->r.fullscreen, 0.0, 0.0, 0, 0, "Starts player in a new fullscreen display"); + xco = 3; uiBlockBeginAlign(block); uiDefButS(block, NUM, 0, "X:", xco+40, yco-=27, 100, 19, &G.scene->r.xplay, 10.0, 2000.0, 0, 0, "Displays current X screen/window resolution. Click to change."); uiDefButS(block, NUM, 0, "Y:", xco+140, yco, 100, 19, &G.scene->r.yplay, 10.0, 2000.0, 0, 0, "Displays current Y screen/window resolution. Click to change."); @@ -1816,26 +1817,29 @@ static uiBlock *framing_render_menu(void *arg_unused) * RAS_STEREO_VINTERLACE 7 * RAS_STEREO_DOME 8 */ + + xco = 8; uiBlockBeginAlign(block); uiDefButS(block, ROW, 0, "No Stereo", xco, yco-=30, 88, 19, &(G.scene->r.stereomode), 7.0, 1.0, 0, 0, "Disables stereo"); - uiDefButS(block, ROW, 0, "Pageflip", xco+=90, yco, 88, 19, &(G.scene->r.stereomode), 7.0, 2.0, 0, 0, "Enables hardware pageflip stereo method"); - uiDefButS(block, ROW, 0, "Syncdouble", xco+=90, yco, 88, 19, &(G.scene->r.stereomode), 7.0, 3.0, 0, 0, "Enables syncdoubling stereo method"); - uiDefButS(block, ROW, 0, "Anaglyph", xco-=180, yco-=21, 88, 19, &(G.scene->r.stereomode), 7.0, 5.0, 0, 0, "Enables anaglyph (Red-Blue) stereo method"); - uiDefButS(block, ROW, 0, "Side by Side", xco+=90, yco, 88, 19, &(G.scene->r.stereomode), 7.0, 6.0, 0, 0, "Enables side by side left and right images"); - uiDefButS(block, ROW, 0, "V Interlace", xco+=90, yco, 88, 19, &(G.scene->r.stereomode), 7.0, 7.0, 0, 0, "Enables interlaced vertical strips for autostereo display"); + uiDefButS(block, ROW, 0, "Pageflip", xco+90, yco, 88, 19, &(G.scene->r.stereomode), 7.0, 2.0, 0, 0, "Enables hardware pageflip stereo method"); + uiDefButS(block, ROW, 0, "Syncdouble", xco+180, yco, 88, 19, &(G.scene->r.stereomode), 7.0, 3.0, 0, 0, "Enables syncdoubling stereo method"); + uiDefButS(block, ROW, 0, "Anaglyph", xco, yco-=21, 88, 19, &(G.scene->r.stereomode), 7.0, 5.0, 0, 0, "Enables anaglyph (Red-Blue) stereo method"); + uiDefButS(block, ROW, 0, "Side by Side", xco+90, yco, 88, 19, &(G.scene->r.stereomode), 7.0, 6.0, 0, 0, "Enables side by side left and right images"); + uiDefButS(block, ROW, 0, "V Interlace", xco+180, yco, 88, 19, &(G.scene->r.stereomode), 7.0, 7.0, 0, 0, "Enables interlaced vertical strips for autostereo display"); uiBlockEndAlign(block); + xco = 8; uiBlockBeginAlign(block); - uiDefButS(block, ROW, 0, "Dome", xco-=180, yco-=30, 88, 19, &(G.scene->r.stereomode), 7.0, 8.0, 0, 0, "Enables dome camera"); - uiDefButS(block, NUM, 0, "Ang:", xco+=90, yco, 88, 19, &G.scene->r.domeangle, 90.0, 250.0, 0, 0, "Angle (Aperture) of the Dome - it only works in mode 1"); - uiDefButS(block, NUM, 0, "Mode:", xco+=90, yco, 88, 19, &G.scene->r.domemode, 1.0, 3.0, 0, 0, "Dome mode - 1 fisheye, 2 truncated, 3 spherical panoramic"); + uiDefButS(block, ROW, 0, "Dome", xco, yco-=30, 88, 19, &(G.scene->r.stereomode), 7.0, 8.0, 0, 0, "Enables dome camera"); + uiDefButS(block, NUM, 0, "Ang:", xco+90, yco, 88, 19, &G.scene->r.domeangle, 90.0, 250.0, 0, 0, "Angle (Aperture) of the Dome - it only works in mode 1"); + uiDefButS(block, NUM, 0, "Mode:", xco+180, yco, 88, 19, &G.scene->r.domemode, 1.0, 3.0, 0, 0, "1 fisheye, 2 environment map, 3 spherical panoramic"); - uiDefButF(block, NUM, 0, "Size:", xco-=180, yco-=21, 88, 19, &G.scene->r.domesize, 0.5, 3.5, 0, 0, "Size adjustments"); - uiDefButS(block, NUM, 0, "Tes:", xco+=90, yco, 88, 19, &G.scene->r.domeres, 1.0, 8.0, 0, 0, "Tesselation level - 1 to 8"); - uiDefButF(block, NUM, 0, "Res:", xco+=90, yco, 88, 19, &G.scene->r.domeresbuf, 0.1, 1.0, 0, 0, "Buffer Resolution - decrease it to increase speed"); + uiDefButF(block, NUM, 0, "Size:", xco, yco-=21, 88, 19, &G.scene->r.domesize, 0.5, 3.5, 0, 0, "Size adjustments"); + uiDefButS(block, NUM, 0, "Tes:", xco+90, yco, 88, 19, &G.scene->r.domeres, 1.0, 8.0, 0, 0, "Tesselation level - 1 to 8"); + uiDefButF(block, NUM, 0, "Res:", xco+180, yco, 88, 19, &G.scene->r.domeresbuf, 0.1, 1.0, 0, 0, "Buffer Resolution - decrease it to increase speed"); - uiDefIDPoinBut(block, test_scriptpoin_but, ID_SCRIPT, 1, "Warp Data: ", xco-180,yco-=21,268, 19, &G.scene->r.dometext, "Custom Warp Mesh data file"); + uiDefIDPoinBut(block, test_scriptpoin_but, ID_SCRIPT, 1, "Warp Data: ", xco,yco-=21,268, 19, &G.scene->r.dometext, "Custom Warp Mesh data file"); uiBlockEndAlign(block); uiBlockSetDirection(block, UI_TOP); diff --git a/source/gameengine/Ketsji/KX_Dome.cpp b/source/gameengine/Ketsji/KX_Dome.cpp index 321370f9f3f..bcff00af76c 100644 --- a/source/gameengine/Ketsji/KX_Dome.cpp +++ b/source/gameengine/Ketsji/KX_Dome.cpp @@ -107,15 +107,9 @@ KX_Dome::KX_Dome ( CreateMeshDome250(); m_numfaces = 5; } break; - case DOME_TRUNCATED: - cubetop.resize(1); - cubebottom.resize(1); - cubeleft.resize(2); - cuberight.resize(2); - - m_angle = 180; - CreateMeshDome180(); - m_numfaces = 4; + case DOME_ENVMAP: + m_angle = 360; + m_numfaces = 6; break; case DOME_PANORAM_SPH: cubeleft.resize(2); @@ -240,7 +234,7 @@ bool KX_Dome::CreateDL(){ dlistId = glGenLists((GLsizei) m_numimages); if (dlistId != 0) { - if(m_mode == DOME_FISHEYE || m_mode == DOME_TRUNCATED){ + if(m_mode == DOME_FISHEYE){ glNewList(dlistId, GL_COMPILE); GLDrawTriangles(cubetop, nfacestop); glEndList(); @@ -386,7 +380,7 @@ void KX_Dome::GLDrawWarpQuads(void) } glEnd(); } else{ - printf("Error: Warp Mode unsupported. Try 1 for Polar Mesh or 2 for Fisheye.\n"); + printf("Error: Warp Mode %d unsupported. Try 1 for Polar Mesh or 2 for Fisheye.\n", warp.mode); } } @@ -1415,7 +1409,7 @@ Uses 6 cameras for angles up to 360 MT_Scalar c = cos(deg45); MT_Scalar s = sin(deg45); - if ((m_mode == DOME_FISHEYE && m_angle <= 180)|| m_mode == DOME_TRUNCATED){ + if ((m_mode == DOME_FISHEYE && m_angle <= 180)){ m_locRot[0] = MT_Matrix3x3( // 90º - Top c, -s, 0.0, @@ -1437,7 +1431,7 @@ Uses 6 cameras for angles up to 360 0.0, 1.0, 0.0, s, 0.0, c); - } else if ((m_mode == DOME_FISHEYE && m_angle > 180)){ + } else if ((m_mode == DOME_FISHEYE && m_angle > 180) || m_mode == DOME_ENVMAP){ m_locRot[0] = MT_Matrix3x3( // 90º - Top 1.0, 0.0, 0.0, @@ -1464,7 +1458,7 @@ Uses 6 cameras for angles up to 360 0.0, 1.0, 0.0, 0.0, 0.0, 1.0); - m_locRot[5] = MT_Matrix3x3( // 180º - Back - NOT USING + m_locRot[5] = MT_Matrix3x3( // 180º - Back - USED for ENVMAP only -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0,-1.0); @@ -1531,8 +1525,8 @@ void KX_Dome::Draw(void) case DOME_FISHEYE: DrawDomeFisheye(); break; - case DOME_TRUNCATED: - DrawDomeFisheye(); + case DOME_ENVMAP: + DrawEnvMap(); break; case DOME_PANORAM_SPH: DrawPanorama(); @@ -1547,7 +1541,7 @@ void KX_Dome::Draw(void) } } -void KX_Dome::DrawDomeFisheye(void) +void KX_Dome::DrawEnvMap(void) { int i,j; @@ -1563,17 +1557,141 @@ void KX_Dome::DrawDomeFisheye(void) float ortho_width, ortho_height; if (warp.usemesh) - glOrtho((-1.0), 1.0, (-1.0), 1.0, -20.0, 10.0); //stretch the image to reduce resolution lost + glOrtho((-1.0), 1.0, (-0.66), 0.66, -20.0, 10.0); //stretch the image to reduce resolution lost - else if(m_mode == DOME_TRUNCATED){ - ortho_width = 1.0; - ortho_height = 2 * ((float)can_height/can_width) - 1.0 ; + else { + if (can_width/3 <= can_height/2){ + ortho_width = 1.0; + ortho_height = (float)can_height/can_width; + }else{ + ortho_height = 2.0f / 3; + ortho_width = (float)can_width/can_height * ortho_height; + } ortho_width /= m_size; ortho_height /= m_size; + + glOrtho((-ortho_width), ortho_width, (-ortho_height), ortho_height, -20.0, 10.0); + } + + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + gluLookAt(0.0,0.0,1.0, 0.0,0.0,0.0, 0.0,1.0,0.0); + + glPolygonMode(GL_FRONT, GL_FILL); + glShadeModel(GL_SMOOTH); + glDisable(GL_LIGHTING); + glDisable(GL_DEPTH_TEST); + + glEnable(GL_TEXTURE_2D); + glColor3f(1.0,1.0,1.0); + + float uv_ratio = (float)(m_buffersize-1) / m_imagesize; + double onebythree = 1.0f / 3; + + // domefacesId[0] => (top) + glBindTexture(GL_TEXTURE_2D, domefacesId[0]); + glBegin(GL_QUADS); + glTexCoord2f(uv_ratio,uv_ratio); + glVertex3f( onebythree, 0.0f, 3.0f); + glTexCoord2f(0.0,uv_ratio); + glVertex3f(-onebythree, 0.0f, 3.0f); + glTexCoord2f(0.0,0.0); + glVertex3f(-onebythree,-2 * onebythree, 3.0f); + glTexCoord2f(uv_ratio,0.0); + glVertex3f(onebythree,-2 * onebythree, 3.0f); + glEnd(); + + // domefacesId[1] => (bottom) + glBindTexture(GL_TEXTURE_2D, domefacesId[1]); + glBegin(GL_QUADS); + glTexCoord2f(uv_ratio,uv_ratio); + glVertex3f(-onebythree, 0.0f, 3.0f); + glTexCoord2f(0.0,uv_ratio); + glVertex3f(-1.0f, 0.0f, 3.0f); + glTexCoord2f(0.0,0.0); + glVertex3f(-1.0f,-2 * onebythree, 3.0f); + glTexCoord2f(uv_ratio,0.0); + glVertex3f(-onebythree,-2 * onebythree, 3.0f); + glEnd(); + + // domefacesId[2] => -90º (left) + glBindTexture(GL_TEXTURE_2D, domefacesId[2]); + glBegin(GL_QUADS); + glTexCoord2f(uv_ratio,uv_ratio); + glVertex3f(-onebythree, 2 * onebythree, 3.0f); + glTexCoord2f(0.0,uv_ratio); + glVertex3f(-1.0f, 2 * onebythree, 3.0f); + glTexCoord2f(0.0,0.0); + glVertex3f(-1.0f, 0.0f, 3.0f); + glTexCoord2f(uv_ratio,0.0); + glVertex3f(-onebythree, 0.0f, 3.0f); + glEnd(); + + // domefacesId[3] => 90º (right) + glBindTexture(GL_TEXTURE_2D, domefacesId[3]); + glBegin(GL_QUADS); + glTexCoord2f(uv_ratio,uv_ratio); + glVertex3f( 1.0f, 2 * onebythree, 3.0f); + glTexCoord2f(0.0,uv_ratio); + glVertex3f( onebythree, 2 * onebythree, 3.0f); + glTexCoord2f(0.0,0.0); + glVertex3f( onebythree, 0.0f, 3.0f); + glTexCoord2f(uv_ratio,0.0); + glVertex3f(1.0f, 0.0f, 3.0f); + glEnd(); + + // domefacesId[4] => 0º (front) + glBindTexture(GL_TEXTURE_2D, domefacesId[4]); + glBegin(GL_QUADS); + glTexCoord2f(uv_ratio,uv_ratio); + glVertex3f( 1.0f, 0.0f, 3.0f); + glTexCoord2f(0.0,uv_ratio); + glVertex3f( onebythree, 0.0f, 3.0f); + glTexCoord2f(0.0,0.0); + glVertex3f( onebythree,-2 * onebythree, 3.0f); + glTexCoord2f(uv_ratio,0.0); + glVertex3f(1.0f, -2 * onebythree, 3.0f); + glEnd(); + + // domefacesId[5] => 180º (back) + glBindTexture(GL_TEXTURE_2D, domefacesId[5]); + glBegin(GL_QUADS); + glTexCoord2f(uv_ratio,uv_ratio); + glVertex3f( onebythree, 2 * onebythree, 3.0f); + glTexCoord2f(0.0,uv_ratio); + glVertex3f(-onebythree, 2 * onebythree, 3.0f); + glTexCoord2f(0.0,0.0); + glVertex3f(-onebythree, 0.0f, 3.0f); + glTexCoord2f(uv_ratio,0.0); + glVertex3f(onebythree, 0.0f, 3.0f); + glEnd(); + + glDisable(GL_TEXTURE_2D); + glEnable(GL_DEPTH_TEST); +} + +void KX_Dome::DrawDomeFisheye(void) +{ + int i,j; + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + // Making the viewport always square + + int can_width = m_viewport.GetRight(); + int can_height = m_viewport.GetTop(); + + float ortho_width, ortho_height; - glOrtho((-ortho_width), ortho_width, (-ortho_height), ortho_width, -20.0, 10.0); - } else { + if (warp.usemesh) + glOrtho((-1.0), 1.0, (-1.0), 1.0, -20.0, 10.0); //stretch the image to reduce resolution lost + + else { if (can_width < can_height){ ortho_width = 1.0; ortho_height = (float)can_height/can_width; diff --git a/source/gameengine/Ketsji/KX_Dome.h b/source/gameengine/Ketsji/KX_Dome.h index de3360cd897..762b09e6429 100644 --- a/source/gameengine/Ketsji/KX_Dome.h +++ b/source/gameengine/Ketsji/KX_Dome.h @@ -42,7 +42,7 @@ Developed as part of a Research and Development project for SAT - La Soci //Dome modes: limit hardcoded in buttons_scene.c #define DOME_FISHEYE 1 -#define DOME_TRUNCATED 2 +#define DOME_ENVMAP 2 #define DOME_PANORAM_SPH 3 #define DOME_NUM_MODES 4 @@ -131,6 +131,7 @@ public: void GLDrawWarpQuads(void); void Draw(void); void DrawDomeFisheye(void); + void DrawEnvMap(void); void DrawPanorama(void); void DrawDomeWarped(void); diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index a9206c1bb8f..ef43d6b176c 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -353,7 +353,6 @@ void KX_KetsjiEngine::RenderDome() m_dome->BindImages(i); } -// m_dome->Dome_PostRender(scene, cam, stereomode); m_canvas->EndFrame();//XXX do we really need that? m_canvas->SetViewPort(0, 0, m_canvas->GetWidth(), m_canvas->GetHeight()); @@ -381,7 +380,8 @@ void KX_KetsjiEngine::RenderDome() m_dome->Draw(); - //run 2dfilters + // run the 2dfilters and motion blur once for all the scenes + PostRenderFrame(); EndFrame(); } -- cgit v1.2.3