From 71b26cf12896b7cb09902a4c5d4a973268be8135 Mon Sep 17 00:00:00 2001 From: BielBdeLuna <7318.tk@gmail.com> Date: Sat, 16 Aug 2014 23:20:46 +0200 Subject: [PATCH 1/7] envshot working but not correctly --- neo/renderer/RenderSystem_init.cpp | 85 ++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/neo/renderer/RenderSystem_init.cpp b/neo/renderer/RenderSystem_init.cpp index 36a9f57f..8093daa5 100644 --- a/neo/renderer/RenderSystem_init.cpp +++ b/neo/renderer/RenderSystem_init.cpp @@ -1444,6 +1444,90 @@ void R_StencilShot() fileSystem->WriteFile( "screenshots/stencilShot.tga", buffer.Ptr(), c, "fs_savepath" ); } +/* +================== +R_EnvShot_f + +envshot + +Saves out env/_ft.tga, etc +================== +*/ +void R_EnvShot_f( const idCmdArgs &args ) { + idStr fullname; + const char *baseName; + int i; + idMat3 axis[6]; + renderView_t ref; + viewDef_t primary; + int blends; + const char *extensions[6] = { "_px.tga", "_nx.tga", "_py.tga", "_ny.tga", + "_pz.tga", "_nz.tga" }; + int size; + + if ( args.Argc() != 2 && args.Argc() != 3 && args.Argc() != 4 ) { + common->Printf( "USAGE: envshot [size] [blends]\n" ); + return; + } + baseName = args.Argv( 1 ); + + blends = 1; + if ( args.Argc() == 4 ) { + size = atoi( args.Argv( 2 ) ); + blends = atoi( args.Argv( 3 ) ); + } else if ( args.Argc() == 3 ) { + size = atoi( args.Argv( 2 ) ); + blends = 1; + } else { + size = 256; + blends = 1; + } + + if ( !tr.primaryView ) { + common->Printf( "No primary view.\n" ); + return; + } + + primary = *tr.primaryView; + + memset( &axis, 0, sizeof( axis ) ); + axis[0][0][0] = 1; + axis[0][1][2] = 1; + axis[0][2][1] = 1; + + axis[1][0][0] = -1; + axis[1][1][2] = -1; + axis[1][2][1] = 1; + + axis[2][0][1] = 1; + axis[2][1][0] = -1; + axis[2][2][2] = -1; + + axis[3][0][1] = -1; + axis[3][1][0] = -1; + axis[3][2][2] = 1; + + axis[4][0][2] = 1; + axis[4][1][0] = -1; + axis[4][2][1] = 1; + + axis[5][0][2] = -1; + axis[5][1][0] = 1; + axis[5][2][1] = 1; + + for ( i = 0 ; i < 6 ; i++ ) { + ref = primary.renderView; + //ref.x = ref.y = 0; + ref.fov_x = ref.fov_y = 90; + //ref.width = glConfig.vidWidth; + //ref.height = glConfig.vidHeight; + ref.viewaxis = axis[i]; + sprintf( fullname, "env/%s%s", baseName, extensions[i] ); + tr.TakeScreenshot( size, size, fullname, blends, &ref ); + } + + common->Printf( "Wrote %s, etc\n", fullname.c_str() ); +} //============================================================================ @@ -2039,6 +2123,7 @@ void R_InitCommands() cmdSystem->AddCommand( "listGuis", R_ListGuis_f, CMD_FL_RENDERER, "lists guis" ); cmdSystem->AddCommand( "touchGui", R_TouchGui_f, CMD_FL_RENDERER, "touches a gui" ); cmdSystem->AddCommand( "screenshot", R_ScreenShot_f, CMD_FL_RENDERER, "takes a screenshot" ); + cmdSystem->AddCommand( "envshot", R_EnvShot_f, CMD_FL_RENDERER, "takes an environment shot" ); cmdSystem->AddCommand( "makeAmbientMap", R_MakeAmbientMap_f, CMD_FL_RENDERER | CMD_FL_CHEAT, "makes an ambient map" ); cmdSystem->AddCommand( "gfxInfo", GfxInfo_f, CMD_FL_RENDERER, "show graphics info" ); cmdSystem->AddCommand( "modulateLights", R_ModulateLights_f, CMD_FL_RENDERER | CMD_FL_CHEAT, "modifies shader parms on all lights" ); From 706d98f24c75a3bccaebd8b5a2ad518a81d04147 Mon Sep 17 00:00:00 2001 From: BielBdeLuna <7318.tk@gmail.com> Date: Mon, 18 Aug 2014 03:38:55 +0200 Subject: [PATCH 2/7] now envshot does the target renderers at a proportionatesize and unskewed, but still the first of them fails. --- neo/renderer/RenderSystem_init.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/neo/renderer/RenderSystem_init.cpp b/neo/renderer/RenderSystem_init.cpp index 8093daa5..015db1bc 100644 --- a/neo/renderer/RenderSystem_init.cpp +++ b/neo/renderer/RenderSystem_init.cpp @@ -1461,9 +1461,13 @@ void R_EnvShot_f( const idCmdArgs &args ) { renderView_t ref; viewDef_t primary; int blends; - const char *extensions[6] = { "_px.tga", "_nx.tga", "_py.tga", "_ny.tga", - "_pz.tga", "_nz.tga" }; + const char *extensions[6] = { "_px.png", "_nx.png", "_py.png", "_ny.png", + "_pz.png", "_nz.png" }; int size; + int res_w, res_h; + + res_w = renderSystem->GetWidth(); + res_h = renderSystem->GetHeight(); if ( args.Argc() != 2 && args.Argc() != 3 && args.Argc() != 4 ) { common->Printf( "USAGE: envshot [size] [blends]\n" ); @@ -1515,6 +1519,14 @@ void R_EnvShot_f( const idCmdArgs &args ) { axis[5][1][0] = 1; axis[5][2][1] = 1; + // let's gain the "size" resolution + // FIXME that's a hack!! + if ( ( res_w != size ) || ( res_h != size ) ) { + cvarSystem->SetCVarInteger( "r_windowWidth", size ); + cvarSystem->SetCVarInteger( "r_windowHeight", size ); + R_SetNewMode( false ); // the same as "vid_restart" + } + for ( i = 0 ; i < 6 ; i++ ) { ref = primary.renderView; //ref.x = ref.y = 0; @@ -1526,7 +1538,12 @@ void R_EnvShot_f( const idCmdArgs &args ) { tr.TakeScreenshot( size, size, fullname, blends, &ref ); } - common->Printf( "Wrote %s, etc\n", fullname.c_str() ); + // restore the original resolution + cvarSystem->SetCVarInteger( "r_windowWidth", res_w ); + cvarSystem->SetCVarInteger( "r_windowHeight", res_h ); + R_SetNewMode( false ); // the same as "vid_restart" + + common->Printf( "Wrote %s, etc\n", fullname.c_str() ); } //============================================================================ From 095cf836c62c23a4347690f048d84020e5e22824 Mon Sep 17 00:00:00 2001 From: BielBdeLuna <7318.tk@gmail.com> Date: Tue, 19 Aug 2014 11:35:50 +0200 Subject: [PATCH 3/7] screen shots are PNG and envshots are TGA, but still envshots come out somewhat wrong --- neo/framework/common_frame.cpp | 6 +- neo/renderer/Image.h | 7 +++ neo/renderer/RenderSystem.h | 2 +- neo/renderer/RenderSystem_init.cpp | 90 ++++++++++++++++++++++-------- neo/renderer/tr_local.h | 2 +- 5 files changed, 79 insertions(+), 28 deletions(-) diff --git a/neo/framework/common_frame.cpp b/neo/framework/common_frame.cpp index a23e83d9..6971bb6c 100644 --- a/neo/framework/common_frame.cpp +++ b/neo/framework/common_frame.cpp @@ -530,14 +530,14 @@ void idCommonLocal::Frame() // save the screenshot and audio from the last draw if needed if( aviCaptureMode ) { - idStr name = va( "demos/%s/%s_%05i.tga", aviDemoShortName.c_str(), aviDemoShortName.c_str(), aviDemoFrameCount++ ); - renderSystem->TakeScreenshot( com_aviDemoWidth.GetInteger(), com_aviDemoHeight.GetInteger(), name, com_aviDemoSamples.GetInteger(), NULL ); + idStr name = va( "demos/%s/%s_%05i", aviDemoShortName.c_str(), aviDemoShortName.c_str(), aviDemoFrameCount++ ); + renderSystem->TakeScreenshot( com_aviDemoWidth.GetInteger(), com_aviDemoHeight.GetInteger(), name, com_aviDemoSamples.GetInteger(), NULL, TGA ); // remove any printed lines at the top before taking the screenshot console->ClearNotifyLines(); // this will call Draw, possibly multiple times if com_aviDemoSamples is > 1 - renderSystem->TakeScreenshot( com_aviDemoWidth.GetInteger(), com_aviDemoHeight.GetInteger(), name, com_aviDemoSamples.GetInteger(), NULL ); + renderSystem->TakeScreenshot( com_aviDemoWidth.GetInteger(), com_aviDemoHeight.GetInteger(), name, com_aviDemoSamples.GetInteger(), NULL, TGA ); } //-------------------------------------------- diff --git a/neo/renderer/Image.h b/neo/renderer/Image.h index 6a90561f..e4e8aae8 100644 --- a/neo/renderer/Image.h +++ b/neo/renderer/Image.h @@ -69,6 +69,13 @@ typedef enum CF_2D_ARRAY // not a cube map but not a single 2d texture either } cubeFiles_t; +enum fileType_t +{ + TGA, + PNG, + JPG +}; + #include "ImageOpts.h" #include "BinaryImage.h" diff --git a/neo/renderer/RenderSystem.h b/neo/renderer/RenderSystem.h index a9e757d7..c21088fd 100644 --- a/neo/renderer/RenderSystem.h +++ b/neo/renderer/RenderSystem.h @@ -332,7 +332,7 @@ public: // This will perform swapbuffers, so it is NOT an approppriate way to // generate image files that happen during gameplay, as for savegame // markers. Use WriteRender() instead. - virtual void TakeScreenshot( int width, int height, const char* fileName, int samples, struct renderView_s* ref ) = 0; + virtual void TakeScreenshot( int width, int height, const char* fileName, int samples, struct renderView_s* ref, int exten ) = 0; // the render output can be cropped down to a subset of the real screen, as // for save-game reviews and split-screen multiplayer. Users of the renderer diff --git a/neo/renderer/RenderSystem_init.cpp b/neo/renderer/RenderSystem_init.cpp index 015db1bc..7a8077b1 100644 --- a/neo/renderer/RenderSystem_init.cpp +++ b/neo/renderer/RenderSystem_init.cpp @@ -1223,20 +1223,34 @@ If ref == NULL, common->UpdateScreen will be used ================== */ // RB: changed .tga to .png -void idRenderSystemLocal::TakeScreenshot( int width, int height, const char* fileName, int blends, renderView_t* ref ) +void idRenderSystemLocal::TakeScreenshot( int width, int height, const char* fileName, int blends, renderView_t* ref, int exten ) { byte* buffer; - int i, j; - + int i, j, c, temp; + const char *formatName[3] = { ".tga", ".png", ".jpg" }; + idStr finalFileName; + + sprintf( finalFileName, "%s%s", fileName, formatName[exten] ); + takingScreenshot = true; - - int pix = width * height; - - buffer = ( byte* )R_StaticAlloc( pix * 3 ); + + int pix = width * height; + const int bufferSize = pix * 3 + 18; + + if ( exten == PNG ) { + buffer = ( byte* )R_StaticAlloc( pix * 3 ); + } else if ( exten == TGA ) { + buffer = (byte *)R_StaticAlloc( bufferSize ); + memset( buffer, 0, bufferSize ); + } if( blends <= 1 ) { - R_ReadTiledPixels( width, height, buffer, ref ); + if ( exten == PNG ) { + R_ReadTiledPixels( width, height, buffer, ref ); + } else if ( exten == TGA ) { + R_ReadTiledPixels( width, height, buffer + 18, ref ); + } } else { @@ -1248,25 +1262,57 @@ void idRenderSystemLocal::TakeScreenshot( int width, int height, const char* fil for( i = 0 ; i < blends ; i++ ) { - R_ReadTiledPixels( width, height, buffer, ref ); + if ( exten == PNG ) { + R_ReadTiledPixels( width, height, buffer, ref ); + } else if ( exten == TGA ) { + R_ReadTiledPixels( width, height, buffer + 18, ref ); + } for( j = 0 ; j < pix * 3 ; j++ ) { - shortBuffer[j] += buffer[j]; + if ( exten == PNG ) { + shortBuffer[j] += buffer[j]; + } else if ( exten == TGA ) { + shortBuffer[j] += buffer[18 + j]; + } } } // divide back to bytes for( i = 0 ; i < pix * 3 ; i++ ) { - buffer[i] = shortBuffer[i] / blends; + if ( exten == PNG ) { + buffer[i] = shortBuffer[i] / blends; + } else if ( exten == TGA ) { + buffer[18 + i] = shortBuffer[i] / blends; + } } R_StaticFree( shortBuffer ); r_jitter.SetBool( false ); } - - R_WritePNG( fileName, buffer, 3, width, height, false ); + if ( exten == PNG ) { + R_WritePNG( finalFileName, buffer, 3, width, height, false ); + } else { + // fill in the header (this is vertically flipped, which qglReadPixels emits) + buffer[2] = 2; // uncompressed type + buffer[12] = width & 255; + buffer[13] = width >> 8; + buffer[14] = height & 255; + buffer[15] = height >> 8; + buffer[16] = 24; // pixel size + + // swap rgb to bgr + c = 18 + width * height * 3; + + for (i=18 ; iWriteFile( finalFileName, buffer, c ); + } R_StaticFree( buffer ); @@ -1317,7 +1363,7 @@ void R_ScreenshotFilename( int& lastNumber, const char* base, idStr& fileName ) time( &aclock ); struct tm* t = localtime( &aclock ); - sprintf( fileName, "%s%s-%04d%02d%02d-%02d%02d%02d-%03d.png", base, "rbdoom-3-bfg", + sprintf( fileName, "%s%s-%04d%02d%02d-%02d%02d%02d-%03d", base, "rbdoom-3-bfg", 1900 + t->tm_year, 1 + t->tm_mon, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, lastNumber ); #endif // RB end @@ -1397,7 +1443,7 @@ void R_ScreenShot_f( const idCmdArgs& args ) // put the console away console->Close(); - tr.TakeScreenshot( width, height, checkname, blends, NULL ); + tr.TakeScreenshot( width, height, checkname, blends, NULL, PNG ); common->Printf( "Wrote %s\n", checkname.c_str() ); } @@ -1461,8 +1507,7 @@ void R_EnvShot_f( const idCmdArgs &args ) { renderView_t ref; viewDef_t primary; int blends; - const char *extensions[6] = { "_px.png", "_nx.png", "_py.png", "_ny.png", - "_pz.png", "_nz.png" }; + const char *extensions[6] = { "_px", "_nx", "_py", "_ny", "_pz", "_nz" }; int size; int res_w, res_h; @@ -1519,23 +1564,22 @@ void R_EnvShot_f( const idCmdArgs &args ) { axis[5][1][0] = 1; axis[5][2][1] = 1; - // let's gain the "size" resolution - // FIXME that's a hack!! + // let's get the game window to a "size" resolution if ( ( res_w != size ) || ( res_h != size ) ) { cvarSystem->SetCVarInteger( "r_windowWidth", size ); cvarSystem->SetCVarInteger( "r_windowHeight", size ); R_SetNewMode( false ); // the same as "vid_restart" - } + } // FIXME that's a hack!! for ( i = 0 ; i < 6 ; i++ ) { ref = primary.renderView; - //ref.x = ref.y = 0; + //ref.x = ref.y = 0; // this no longer serves any purpose ref.fov_x = ref.fov_y = 90; - //ref.width = glConfig.vidWidth; + //ref.width = glConfig.vidWidth; // this no longer serves any purpose //ref.height = glConfig.vidHeight; ref.viewaxis = axis[i]; sprintf( fullname, "env/%s%s", baseName, extensions[i] ); - tr.TakeScreenshot( size, size, fullname, blends, &ref ); + tr.TakeScreenshot( size, size, fullname, blends, &ref, TGA ); } // restore the original resolution diff --git a/neo/renderer/tr_local.h b/neo/renderer/tr_local.h index 8944973c..26c0d89d 100644 --- a/neo/renderer/tr_local.h +++ b/neo/renderer/tr_local.h @@ -814,7 +814,7 @@ public: virtual const emptyCommand_t* SwapCommandBuffers_FinishCommandBuffers(); virtual void RenderCommandBuffers( const emptyCommand_t* commandBuffers ); - virtual void TakeScreenshot( int width, int height, const char* fileName, int downSample, renderView_t* ref ); + virtual void TakeScreenshot( int width, int height, const char* fileName, int downSample, renderView_t* ref, int exten ); virtual void CropRenderSize( int width, int height ); virtual void CaptureRenderToImage( const char* imageName, bool clearColorAfterCopy = false ); virtual void CaptureRenderToFile( const char* fileName, bool fixAlpha ); From d7345d61680d07853fcc305f199258cd0534abe6 Mon Sep 17 00:00:00 2001 From: BielBdeLuna <7318.tk@gmail.com> Date: Wed, 20 Aug 2014 12:12:01 +0200 Subject: [PATCH 4/7] envToSky not working yet --- neo/renderer/RenderSystem_init.cpp | 186 +++++++++++++++++++++++++++-- 1 file changed, 174 insertions(+), 12 deletions(-) diff --git a/neo/renderer/RenderSystem_init.cpp b/neo/renderer/RenderSystem_init.cpp index 7a8077b1..c001125c 100644 --- a/neo/renderer/RenderSystem_init.cpp +++ b/neo/renderer/RenderSystem_init.cpp @@ -1503,13 +1503,13 @@ void R_EnvShot_f( const idCmdArgs &args ) { idStr fullname; const char *baseName; int i; - idMat3 axis[6]; + idMat3 axis[7], oldAxis; renderView_t ref; viewDef_t primary; int blends; - const char *extensions[6] = { "_px", "_nx", "_py", "_ny", "_pz", "_nz" }; + const char *extensions[7] = { "_wrong", "_nx", "_py", "_ny", "_pz", "_nz", "_px" }; int size; - int res_w, res_h; + int res_w, res_h, old_fov_x, old_fov_y; res_w = renderSystem->GetWidth(); res_h = renderSystem->GetHeight(); @@ -1540,8 +1540,8 @@ void R_EnvShot_f( const idCmdArgs &args ) { primary = *tr.primaryView; memset( &axis, 0, sizeof( axis ) ); - axis[0][0][0] = 1; - axis[0][1][2] = 1; + axis[0][0][0] = 1; // this one gets ignored as it always come out wrong. + axis[0][1][2] = 1; // and so we repeat this axis as the last one. axis[0][2][1] = 1; axis[1][0][0] = -1; @@ -1564,6 +1564,10 @@ void R_EnvShot_f( const idCmdArgs &args ) { axis[5][1][0] = 1; axis[5][2][1] = 1; + axis[6][0][0] = 1; // this is the repetition of the first axis + axis[6][1][2] = 1; + axis[6][2][1] = 1; + // let's get the game window to a "size" resolution if ( ( res_w != size ) || ( res_h != size ) ) { cvarSystem->SetCVarInteger( "r_windowWidth", size ); @@ -1571,23 +1575,33 @@ void R_EnvShot_f( const idCmdArgs &args ) { R_SetNewMode( false ); // the same as "vid_restart" } // FIXME that's a hack!! - for ( i = 0 ; i < 6 ; i++ ) { - ref = primary.renderView; - //ref.x = ref.y = 0; // this no longer serves any purpose + for ( i = 0 ; i < 7 ; i++ ) { + + ref = primary.renderView; + + if ( i == 0 ) { + // so we return to that axis and fov after the fact. + oldAxis = ref.viewaxis; + old_fov_x = ref.fov_x; + old_fov_y = ref.fov_y; + } + ref.fov_x = ref.fov_y = 90; - //ref.width = glConfig.vidWidth; // this no longer serves any purpose - //ref.height = glConfig.vidHeight; ref.viewaxis = axis[i]; sprintf( fullname, "env/%s%s", baseName, extensions[i] ); + tr.TakeScreenshot( size, size, fullname, blends, &ref, TGA ); } - // restore the original resolution + // restore the original resolution, axis and fov + ref.viewaxis = oldAxis; + ref.fov_x = old_fov_x; + ref.fov_y = old_fov_y; cvarSystem->SetCVarInteger( "r_windowWidth", res_w ); cvarSystem->SetCVarInteger( "r_windowHeight", res_h ); R_SetNewMode( false ); // the same as "vid_restart" - common->Printf( "Wrote %s, etc\n", fullname.c_str() ); + common->Printf( "Wrote a env set with the name %s\n", baseName ); } //============================================================================ @@ -1830,6 +1844,153 @@ void R_MakeAmbientMap_f( const idCmdArgs& args ) } } +/* +================== +R_MakeSkyboxMap_f + +R_MakeSkyboxMap_f [size] + +Saves out env/_amb_ft.tga, etc +================== +*/ +void R_MakeSkyboxMap_f( const idCmdArgs& args ) +{ + idStr fullname; + const char* baseName; + int i; + renderView_t ref; + viewDef_t primary; + const char* envDirections[6] = { "_nx", "_py", "_ny", "_pz", "_nz", "_px" }; + const char* skyDirections[6] = { "_forward", "_back", "_left", "_right", "_up", "_down" }; + const char* ext = ".tga"; + int outSize; + byte* buffers[6]; + int width = 0, height = 0; + + if( args.Argc() != 2 && args.Argc() != 3 ) + { + common->Printf( "USAGE: envToSky [size]\n" ); + return; + } + + baseName = args.Argv( 1 ); + + if( args.Argc() == 3 ) + { + outSize = atoi( args.Argv( 2 ) ); + } + else + { + outSize = 32; + } + + memset( &cubeAxis, 0, sizeof( cubeAxis ) ); + cubeAxis[0][0][0] = 1; + cubeAxis[0][1][2] = 1; + cubeAxis[0][2][1] = 1; + + cubeAxis[1][0][0] = -1; + cubeAxis[1][1][2] = -1; + cubeAxis[1][2][1] = 1; + + cubeAxis[2][0][1] = 1; + cubeAxis[2][1][0] = -1; + cubeAxis[2][2][2] = -1; + + cubeAxis[3][0][1] = -1; + cubeAxis[3][1][0] = -1; + cubeAxis[3][2][2] = 1; + + cubeAxis[4][0][2] = 1; + cubeAxis[4][1][0] = -1; + cubeAxis[4][2][1] = 1; + + cubeAxis[5][0][2] = -1; + cubeAxis[5][1][0] = 1; + cubeAxis[5][2][1] = 1; + + // read all of the images + for( i = 0 ; i < 6 ; i++ ) + { + sprintf( fullname, "env/%s%s%s", baseName, envDirections[i], ext ); + common->Printf( "loading %s\n", fullname.c_str() ); + const bool captureToImage = false; + common->UpdateScreen( captureToImage ); + R_LoadImage( fullname, &buffers[i], &width, &height, NULL, true ); + if( !buffers[i] ) + { + common->Printf( "failed.\n" ); + for( i-- ; i >= 0 ; i-- ) + { + Mem_Free( buffers[i] ); + } + return; + } + } + + byte* outBuffer = ( byte* )_alloca( outSize * outSize * 4 ); + + for( i = 0 ; i < 6 ; i++ ){ + for( int x = 0 ; x < outSize ; x++ ){ + for( int y = 0 ; y < outSize ; y++ ){ + idVec3 dir; + float total[3]; + + dir = cubeAxis[i][0] + -( -1 + 2.0 * x / ( outSize - 1 ) ) * cubeAxis[i][1] + -( -1 + 2.0 * y / ( outSize - 1 ) ) * cubeAxis[i][2]; + dir.Normalize(); + + total[0] = total[1] = total[2] = 0; + + //float limit = map ? 0.95 : 0.25; // small for specular, almost hemisphere for ambient + + for( int s = 0 ; s < samples ; s++ ){ + // pick a random direction vector that is inside the unit sphere but not behind dir, + // which is a robust way to evenly sample a hemisphere + idVec3 test; + while( 1 ){ + for( int j = 0 ; j < 3 ; j++ ){ + test[j] = -1 + 2 * ( rand() & 0x7fff ) / ( float )0x7fff; + } + if( test.Length() > 1.0 ){ continue; } + test.Normalize(); + if( test * dir > limit ){ break; } // don't do a complete hemisphere + } + byte result[4]; + + R_SampleCubeMap( test, width, buffers, result ); + total[0] += result[0]; + total[1] += result[1]; + total[2] += result[2]; + } + outBuffer[( y * outSize + x ) * 4 + 0] = total[0] / samples; + outBuffer[( y * outSize + x ) * 4 + 1] = total[1] / samples; + outBuffer[( y * outSize + x ) * 4 + 2] = total[2] / samples; + outBuffer[( y * outSize + x ) * 4 + 3] = 255; + /* + outBuffer[( y * outSize + x ) * 4 + 0] = dir[0]; + outBuffer[( y * outSize + x ) * 4 + 1] = dir[1]; + outBuffer[( y * outSize + x ) * 4 + 2] = dir[2]; + outBuffer[( y * outSize + x ) * 4 + 3] = 255; + */ + } + } + sprintf( fullname, "env/skybox/%s/%s%s%s", baseName, baseName, skyDirections[i], ext ); + common->Printf( "writing %s\n", fullname.c_str() ); + const bool captureToImage2 = false; + common->UpdateScreen( captureToImage2 ); + R_WriteTGA( fullname, outBuffer, outSize, outSize ); + //R_WriteTGA( fullname, buffers[i], outSize, outSize ); + } + + for( i = 0 ; i < 6 ; i++ ) + { + if( buffers[i] ) + { + Mem_Free( buffers[i] ); + } + } +} + //============================================================================ @@ -2186,6 +2347,7 @@ void R_InitCommands() cmdSystem->AddCommand( "screenshot", R_ScreenShot_f, CMD_FL_RENDERER, "takes a screenshot" ); cmdSystem->AddCommand( "envshot", R_EnvShot_f, CMD_FL_RENDERER, "takes an environment shot" ); cmdSystem->AddCommand( "makeAmbientMap", R_MakeAmbientMap_f, CMD_FL_RENDERER | CMD_FL_CHEAT, "makes an ambient map" ); + cmdSystem->AddCommand( "envToSky", R_MakeSkyboxMap_f, CMD_FL_RENDERER | CMD_FL_CHEAT, "makes sky box textures from environment textures" ); cmdSystem->AddCommand( "gfxInfo", GfxInfo_f, CMD_FL_RENDERER, "show graphics info" ); cmdSystem->AddCommand( "modulateLights", R_ModulateLights_f, CMD_FL_RENDERER | CMD_FL_CHEAT, "modifies shader parms on all lights" ); cmdSystem->AddCommand( "testImage", R_TestImage_f, CMD_FL_RENDERER | CMD_FL_CHEAT, "displays the given image centered on screen", idCmdSystem::ArgCompletion_ImageName ); From fedaf6b69106ae2291c4d237937a0a8dba22186f Mon Sep 17 00:00:00 2001 From: BielBdeLuna <7318.tk@gmail.com> Date: Sun, 24 Aug 2014 00:10:50 +0200 Subject: [PATCH 5/7] envshot and others working --- neo/renderer/Image.h | 3 +- neo/renderer/Image_process.cpp | 17 +++ neo/renderer/RenderSystem_init.cpp | 202 ++++++++++++----------------- 3 files changed, 99 insertions(+), 123 deletions(-) diff --git a/neo/renderer/Image.h b/neo/renderer/Image.h index e4e8aae8..4add5cf3 100644 --- a/neo/renderer/Image.h +++ b/neo/renderer/Image.h @@ -201,7 +201,7 @@ public: } static void GetGeneratedName( idStr& _name, const textureUsage_t& _usage, const cubeFiles_t& _cube ); - + private: friend class idImageManager; @@ -397,6 +397,7 @@ void R_BlendOverTexture( byte* data, int pixelCount, const byte blend[4] ); void R_HorizontalFlip( byte* data, int width, int height ); void R_VerticalFlip( byte* data, int width, int height ); void R_RotatePic( byte* data, int width ); +void R_ApplyCubeMapTransforms( int i, byte* data, int size ); /* ==================================================================== diff --git a/neo/renderer/Image_process.cpp b/neo/renderer/Image_process.cpp index cee19af1..a3c13264 100644 --- a/neo/renderer/Image_process.cpp +++ b/neo/renderer/Image_process.cpp @@ -538,6 +538,7 @@ void R_RotatePic( byte* data, int width ) { for( j = 0 ; j < width ; j++ ) { + // apparently rotates the picture and then it flips the picture horitzontally *( temp + i * width + j ) = *( ( int* )data + j * width + i ); } } @@ -547,3 +548,19 @@ void R_RotatePic( byte* data, int width ) R_StaticFree( temp ); } +// transforms in both ways, the images from a cube map, +// in both the Env map and the Skybox map systems. +void R_ApplyCubeMapTransforms ( int iter, byte* data, int size ) { + if ( ( iter == 1 ) || ( iter == 2 ) ) { + R_VerticalFlip( data, size, size ); + } + if ( ( iter == 0 ) || ( iter == 1 ) || ( iter == 4 ) || ( iter == 5 ) ) { + R_RotatePic( data, size ); // apparently not only rotates but also flips horitzontally + } + if ( iter == 1 ) { + R_VerticalFlip( data, size, size ); + } else if ( iter == 3 ) { // that's so just for having less lines + R_HorizontalFlip( data, size, size ); + } +} + diff --git a/neo/renderer/RenderSystem_init.cpp b/neo/renderer/RenderSystem_init.cpp index c001125c..8c7360d4 100644 --- a/neo/renderer/RenderSystem_init.cpp +++ b/neo/renderer/RenderSystem_init.cpp @@ -237,6 +237,10 @@ idCVar r_shadowMapPolygonOffset( "r_shadowMapPolygonOffset", "3000", CVAR_RENDER idCVar r_shadowMapOccluderFacing( "r_shadowMapOccluderFacing", "2", CVAR_RENDERER | CVAR_INTEGER, "0 = front faces, 1 = back faces, 2 = twosided" ); // RB end +const char* fileExten [3] = { "tga", "png", "jpg" }; +const char* envDirection[6] = { "_nx", "_py", "_ny", "_pz", "_nz", "_px" }; +const char* skyDirection[6] = { "_forward", "_back", "_left", "_right", "_up", "_down" }; + /* ======================== @@ -1844,142 +1848,54 @@ void R_MakeAmbientMap_f( const idCmdArgs& args ) } } -/* -================== -R_MakeSkyboxMap_f - -R_MakeSkyboxMap_f [size] - -Saves out env/_amb_ft.tga, etc -================== -*/ -void R_MakeSkyboxMap_f( const idCmdArgs& args ) +void R_TransformCubemap( const char* orgDirection[6], const char* orgDir, const char* destDirection[6], const char* destDir, const char* baseName ) { - idStr fullname; - const char* baseName; + idStr fullname; int i; - renderView_t ref; - viewDef_t primary; - const char* envDirections[6] = { "_nx", "_py", "_ny", "_pz", "_nz", "_px" }; - const char* skyDirections[6] = { "_forward", "_back", "_left", "_right", "_up", "_down" }; - const char* ext = ".tga"; + const char* ext = ".tga"; + bool errorInOriginalImages = false; int outSize; byte* buffers[6]; - int width = 0, height = 0; + int width = 0, height = 0; - if( args.Argc() != 2 && args.Argc() != 3 ) - { - common->Printf( "USAGE: envToSky [size]\n" ); - return; - } - - baseName = args.Argv( 1 ); - - if( args.Argc() == 3 ) - { - outSize = atoi( args.Argv( 2 ) ); - } - else - { - outSize = 32; - } - - memset( &cubeAxis, 0, sizeof( cubeAxis ) ); - cubeAxis[0][0][0] = 1; - cubeAxis[0][1][2] = 1; - cubeAxis[0][2][1] = 1; - - cubeAxis[1][0][0] = -1; - cubeAxis[1][1][2] = -1; - cubeAxis[1][2][1] = 1; - - cubeAxis[2][0][1] = 1; - cubeAxis[2][1][0] = -1; - cubeAxis[2][2][2] = -1; - - cubeAxis[3][0][1] = -1; - cubeAxis[3][1][0] = -1; - cubeAxis[3][2][2] = 1; - - cubeAxis[4][0][2] = 1; - cubeAxis[4][1][0] = -1; - cubeAxis[4][2][1] = 1; - - cubeAxis[5][0][2] = -1; - cubeAxis[5][1][0] = 1; - cubeAxis[5][2][1] = 1; - - // read all of the images for( i = 0 ; i < 6 ; i++ ) { - sprintf( fullname, "env/%s%s%s", baseName, envDirections[i], ext ); + // read every image images + sprintf( fullname, "%s/%s%s.%s", orgDir, baseName, orgDirection[i], fileExten [TGA] ); common->Printf( "loading %s\n", fullname.c_str() ); const bool captureToImage = false; common->UpdateScreen( captureToImage ); R_LoadImage( fullname, &buffers[i], &width, &height, NULL, true ); - if( !buffers[i] ) + + //check if the buffer is troublesome + if ( !buffers[i] ) { common->Printf( "failed.\n" ); - for( i-- ; i >= 0 ; i-- ) - { - Mem_Free( buffers[i] ); - } - return; - } - } - - byte* outBuffer = ( byte* )_alloca( outSize * outSize * 4 ); - - for( i = 0 ; i < 6 ; i++ ){ - for( int x = 0 ; x < outSize ; x++ ){ - for( int y = 0 ; y < outSize ; y++ ){ - idVec3 dir; - float total[3]; - - dir = cubeAxis[i][0] + -( -1 + 2.0 * x / ( outSize - 1 ) ) * cubeAxis[i][1] + -( -1 + 2.0 * y / ( outSize - 1 ) ) * cubeAxis[i][2]; - dir.Normalize(); - - total[0] = total[1] = total[2] = 0; - - //float limit = map ? 0.95 : 0.25; // small for specular, almost hemisphere for ambient - - for( int s = 0 ; s < samples ; s++ ){ - // pick a random direction vector that is inside the unit sphere but not behind dir, - // which is a robust way to evenly sample a hemisphere - idVec3 test; - while( 1 ){ - for( int j = 0 ; j < 3 ; j++ ){ - test[j] = -1 + 2 * ( rand() & 0x7fff ) / ( float )0x7fff; - } - if( test.Length() > 1.0 ){ continue; } - test.Normalize(); - if( test * dir > limit ){ break; } // don't do a complete hemisphere - } - byte result[4]; - - R_SampleCubeMap( test, width, buffers, result ); - total[0] += result[0]; - total[1] += result[1]; - total[2] += result[2]; - } - outBuffer[( y * outSize + x ) * 4 + 0] = total[0] / samples; - outBuffer[( y * outSize + x ) * 4 + 1] = total[1] / samples; - outBuffer[( y * outSize + x ) * 4 + 2] = total[2] / samples; - outBuffer[( y * outSize + x ) * 4 + 3] = 255; - /* - outBuffer[( y * outSize + x ) * 4 + 0] = dir[0]; - outBuffer[( y * outSize + x ) * 4 + 1] = dir[1]; - outBuffer[( y * outSize + x ) * 4 + 2] = dir[2]; - outBuffer[( y * outSize + x ) * 4 + 3] = 255; - */ - } + errorInOriginalImages = true; + } else if ( width != height ) { + common->Printf( "wrong size pal!\n\n\nget your shit together and set the size according to your images!\n\n\ninept programmers are inept!\n" ); + errorInOriginalImages = true; // yeah, but don't just choke on a joke! + } else { + errorInOriginalImages = false; } - sprintf( fullname, "env/skybox/%s/%s%s%s", baseName, baseName, skyDirections[i], ext ); + + if ( errorInOriginalImages ) { + errorInOriginalImages = false; + for( i-- ; i >= 0 ; i-- ) { + Mem_Free( buffers[i] ); // clean up every buffer from this stage down + } + + return; + } + + // apply rotations and flips + R_ApplyCubeMapTransforms( i, buffers[i], width ); + + //save the images with the appropiate skybox naming convention + sprintf( fullname, "%s/%s/%s%s.%s", destDir, baseName, baseName, destDirection[i], fileExten [TGA] ); common->Printf( "writing %s\n", fullname.c_str() ); - const bool captureToImage2 = false; - common->UpdateScreen( captureToImage2 ); - R_WriteTGA( fullname, outBuffer, outSize, outSize ); - //R_WriteTGA( fullname, buffers[i], outSize, outSize ); + common->UpdateScreen( false ); + R_WriteTGA( fullname, buffers[i], width, width ); } for( i = 0 ; i < 6 ; i++ ) @@ -1991,6 +1907,47 @@ void R_MakeSkyboxMap_f( const idCmdArgs& args ) } } +/* +================== +R_TransformEnvToSkybox_f + +R_TransformEnvToSkybox_f + +transforms env textures (of the type px, py, pz, nx, ny, nz) +to skybox textures ( forward, back, left, right, up, down) +================== +*/ +void R_TransformEnvToSkybox_f( const idCmdArgs& args ){ + + if( args.Argc() != 2 ) { + common->Printf( "USAGE: envToSky \n" ); + return; + } + + R_TransformCubemap( envDirection, "env", skyDirection, "skybox", args.Argv( 1 ) ); +} + +/* +================== +R_TransformSkyboxToEnv_f + +R_TransformSkyboxToEnv_f + +transforms skybox textures ( forward, back, left, right, up, down) +to env textures (of the type px, py, pz, nx, ny, nz) +================== +*/ + +void R_TransformSkyboxToEnv_f ( const idCmdArgs& args ){ + + if( args.Argc() != 2 ) { + common->Printf( "USAGE: skyToEnv \n" ); + return; + } + + R_TransformCubemap( skyDirection, "skybox", envDirection, "env", args.Argv( 1 ) ); +} + //============================================================================ @@ -2347,7 +2304,8 @@ void R_InitCommands() cmdSystem->AddCommand( "screenshot", R_ScreenShot_f, CMD_FL_RENDERER, "takes a screenshot" ); cmdSystem->AddCommand( "envshot", R_EnvShot_f, CMD_FL_RENDERER, "takes an environment shot" ); cmdSystem->AddCommand( "makeAmbientMap", R_MakeAmbientMap_f, CMD_FL_RENDERER | CMD_FL_CHEAT, "makes an ambient map" ); - cmdSystem->AddCommand( "envToSky", R_MakeSkyboxMap_f, CMD_FL_RENDERER | CMD_FL_CHEAT, "makes sky box textures from environment textures" ); + cmdSystem->AddCommand( "envToSky", R_TransformEnvToSkybox_f, CMD_FL_RENDERER | CMD_FL_CHEAT, "transforms environment textures to sky box textures" ); + cmdSystem->AddCommand( "skyToEnv", R_TransformSkyboxToEnv_f, CMD_FL_RENDERER | CMD_FL_CHEAT, "transforms sky box textures to environment textures" ); cmdSystem->AddCommand( "gfxInfo", GfxInfo_f, CMD_FL_RENDERER, "show graphics info" ); cmdSystem->AddCommand( "modulateLights", R_ModulateLights_f, CMD_FL_RENDERER | CMD_FL_CHEAT, "modifies shader parms on all lights" ); cmdSystem->AddCommand( "testImage", R_TestImage_f, CMD_FL_RENDERER | CMD_FL_CHEAT, "displays the given image centered on screen", idCmdSystem::ArgCompletion_ImageName ); From fc7ed840bcf56dfd547f78c899024c7e36e4ab97 Mon Sep 17 00:00:00 2001 From: BielBdeLuna <7318.tk@gmail.com> Date: Mon, 25 Aug 2014 15:25:54 +0200 Subject: [PATCH 6/7] astyle and other wonderbar stuff! --- neo/framework/common_frame.cpp | 3 +- neo/renderer/Image.h | 10 +- neo/renderer/Image_process.cpp | 34 +-- neo/renderer/RenderSystem_init.cpp | 370 ++++++++++++++++------------- 4 files changed, 233 insertions(+), 184 deletions(-) diff --git a/neo/framework/common_frame.cpp b/neo/framework/common_frame.cpp index 6971bb6c..ec11fbc2 100644 --- a/neo/framework/common_frame.cpp +++ b/neo/framework/common_frame.cpp @@ -530,7 +530,8 @@ void idCommonLocal::Frame() // save the screenshot and audio from the last draw if needed if( aviCaptureMode ) { - idStr name = va( "demos/%s/%s_%05i", aviDemoShortName.c_str(), aviDemoShortName.c_str(), aviDemoFrameCount++ ); + idStr name; + name.Format( "demos/%s/%s_%05i", aviDemoShortName.c_str(), aviDemoShortName.c_str(), aviDemoFrameCount++ ); renderSystem->TakeScreenshot( com_aviDemoWidth.GetInteger(), com_aviDemoHeight.GetInteger(), name, com_aviDemoSamples.GetInteger(), NULL, TGA ); // remove any printed lines at the top before taking the screenshot diff --git a/neo/renderer/Image.h b/neo/renderer/Image.h index 4add5cf3..368c678f 100644 --- a/neo/renderer/Image.h +++ b/neo/renderer/Image.h @@ -69,11 +69,11 @@ typedef enum CF_2D_ARRAY // not a cube map but not a single 2d texture either } cubeFiles_t; -enum fileType_t +enum imageFileType_t { - TGA, - PNG, - JPG + TGA, + PNG, + JPG }; #include "ImageOpts.h" @@ -201,7 +201,7 @@ public: } static void GetGeneratedName( idStr& _name, const textureUsage_t& _usage, const cubeFiles_t& _cube ); - + private: friend class idImageManager; diff --git a/neo/renderer/Image_process.cpp b/neo/renderer/Image_process.cpp index a3c13264..a10d760b 100644 --- a/neo/renderer/Image_process.cpp +++ b/neo/renderer/Image_process.cpp @@ -538,7 +538,7 @@ void R_RotatePic( byte* data, int width ) { for( j = 0 ; j < width ; j++ ) { - // apparently rotates the picture and then it flips the picture horitzontally + // apparently rotates the picture and then it flips the picture horitzontally *( temp + i * width + j ) = *( ( int* )data + j * width + i ); } } @@ -548,19 +548,25 @@ void R_RotatePic( byte* data, int width ) R_StaticFree( temp ); } -// transforms in both ways, the images from a cube map, +// transforms in both ways, the images from a cube map, // in both the Env map and the Skybox map systems. -void R_ApplyCubeMapTransforms ( int iter, byte* data, int size ) { - if ( ( iter == 1 ) || ( iter == 2 ) ) { - R_VerticalFlip( data, size, size ); - } - if ( ( iter == 0 ) || ( iter == 1 ) || ( iter == 4 ) || ( iter == 5 ) ) { - R_RotatePic( data, size ); // apparently not only rotates but also flips horitzontally - } - if ( iter == 1 ) { - R_VerticalFlip( data, size, size ); - } else if ( iter == 3 ) { // that's so just for having less lines - R_HorizontalFlip( data, size, size ); - } +void R_ApplyCubeMapTransforms( int iter, byte* data, int size ) +{ + if( ( iter == 1 ) || ( iter == 2 ) ) + { + R_VerticalFlip( data, size, size ); + } + if( ( iter == 0 ) || ( iter == 1 ) || ( iter == 4 ) || ( iter == 5 ) ) + { + R_RotatePic( data, size ); // apparently not only rotates but also flips horitzontally + } + if( iter == 1 ) + { + R_VerticalFlip( data, size, size ); + } + else if( iter == 3 ) // that's so just for having less lines + { + R_HorizontalFlip( data, size, size ); + } } diff --git a/neo/renderer/RenderSystem_init.cpp b/neo/renderer/RenderSystem_init.cpp index 8c7360d4..3e1fc416 100644 --- a/neo/renderer/RenderSystem_init.cpp +++ b/neo/renderer/RenderSystem_init.cpp @@ -237,7 +237,7 @@ idCVar r_shadowMapPolygonOffset( "r_shadowMapPolygonOffset", "3000", CVAR_RENDER idCVar r_shadowMapOccluderFacing( "r_shadowMapOccluderFacing", "2", CVAR_RENDERER | CVAR_INTEGER, "0 = front faces, 1 = back faces, 2 = twosided" ); // RB end -const char* fileExten [3] = { "tga", "png", "jpg" }; +const char* fileExten[3] = { "tga", "png", "jpg" }; const char* envDirection[6] = { "_nx", "_py", "_ny", "_pz", "_nz", "_px" }; const char* skyDirection[6] = { "_forward", "_back", "_left", "_right", "_up", "_down" }; @@ -1231,30 +1231,35 @@ void idRenderSystemLocal::TakeScreenshot( int width, int height, const char* fil { byte* buffer; int i, j, c, temp; - const char *formatName[3] = { ".tga", ".png", ".jpg" }; - idStr finalFileName; - - sprintf( finalFileName, "%s%s", fileName, formatName[exten] ); - + idStr finalFileName; + + finalFileName.Format( "%s.%s", fileName, fileExten[exten] ); + takingScreenshot = true; - - int pix = width * height; - const int bufferSize = pix * 3 + 18; - - if ( exten == PNG ) { - buffer = ( byte* )R_StaticAlloc( pix * 3 ); - } else if ( exten == TGA ) { - buffer = (byte *)R_StaticAlloc( bufferSize ); - memset( buffer, 0, bufferSize ); - } + + int pix = width * height; + const int bufferSize = pix * 3 + 18; + + if( exten == PNG ) + { + buffer = ( byte* )R_StaticAlloc( pix * 3 ); + } + else if( exten == TGA ) + { + buffer = ( byte* )R_StaticAlloc( bufferSize ); + memset( buffer, 0, bufferSize ); + } if( blends <= 1 ) { - if ( exten == PNG ) { - R_ReadTiledPixels( width, height, buffer, ref ); - } else if ( exten == TGA ) { - R_ReadTiledPixels( width, height, buffer + 18, ref ); - } + if( exten == PNG ) + { + R_ReadTiledPixels( width, height, buffer, ref ); + } + else if( exten == TGA ) + { + R_ReadTiledPixels( width, height, buffer + 18, ref ); + } } else { @@ -1266,57 +1271,70 @@ void idRenderSystemLocal::TakeScreenshot( int width, int height, const char* fil for( i = 0 ; i < blends ; i++ ) { - if ( exten == PNG ) { - R_ReadTiledPixels( width, height, buffer, ref ); - } else if ( exten == TGA ) { - R_ReadTiledPixels( width, height, buffer + 18, ref ); - } + if( exten == PNG ) + { + R_ReadTiledPixels( width, height, buffer, ref ); + } + else if( exten == TGA ) + { + R_ReadTiledPixels( width, height, buffer + 18, ref ); + } for( j = 0 ; j < pix * 3 ; j++ ) { - if ( exten == PNG ) { - shortBuffer[j] += buffer[j]; - } else if ( exten == TGA ) { - shortBuffer[j] += buffer[18 + j]; - } + if( exten == PNG ) + { + shortBuffer[j] += buffer[j]; + } + else if( exten == TGA ) + { + shortBuffer[j] += buffer[18 + j]; + } } } // divide back to bytes for( i = 0 ; i < pix * 3 ; i++ ) { - if ( exten == PNG ) { - buffer[i] = shortBuffer[i] / blends; - } else if ( exten == TGA ) { - buffer[18 + i] = shortBuffer[i] / blends; - } + if( exten == PNG ) + { + buffer[i] = shortBuffer[i] / blends; + } + else if( exten == TGA ) + { + buffer[18 + i] = shortBuffer[i] / blends; + } } R_StaticFree( shortBuffer ); r_jitter.SetBool( false ); } - if ( exten == PNG ) { - R_WritePNG( finalFileName, buffer, 3, width, height, false ); - } else { - // fill in the header (this is vertically flipped, which qglReadPixels emits) - buffer[2] = 2; // uncompressed type - buffer[12] = width & 255; - buffer[13] = width >> 8; - buffer[14] = height & 255; - buffer[15] = height >> 8; - buffer[16] = 24; // pixel size - - // swap rgb to bgr - c = 18 + width * height * 3; - - for (i=18 ; iWriteFile( finalFileName, buffer, c ); - } + if( exten == PNG ) + { + R_WritePNG( finalFileName, buffer, 3, width, height, false ); + } + else + { + // fill in the header (this is vertically flipped, which qglReadPixels emits) + buffer[2] = 2; // uncompressed type + buffer[12] = width & 255; + buffer[13] = width >> 8; + buffer[14] = height & 255; + buffer[15] = height >> 8; + buffer[16] = 24; // pixel size + + // swap rgb to bgr + c = 18 + width * height * 3; + + for( i = 18 ; i < c ; i += 3 ) + { + temp = buffer[i]; + buffer[i] = buffer[i + 2]; + buffer[i + 2] = temp; + } + + fileSystem->WriteFile( finalFileName, buffer, c ); + } R_StaticFree( buffer ); @@ -1503,109 +1521,127 @@ envshot Saves out env/_ft.tga, etc ================== */ -void R_EnvShot_f( const idCmdArgs &args ) { +void R_EnvShot_f( const idCmdArgs& args ) +{ idStr fullname; - const char *baseName; + const char* baseName; int i; idMat3 axis[7], oldAxis; renderView_t ref; viewDef_t primary; int blends; - const char *extensions[7] = { "_wrong", "_nx", "_py", "_ny", "_pz", "_nz", "_px" }; + const char* extension; int size; - int res_w, res_h, old_fov_x, old_fov_y; - - res_w = renderSystem->GetWidth(); - res_h = renderSystem->GetHeight(); - - if ( args.Argc() != 2 && args.Argc() != 3 && args.Argc() != 4 ) { + int res_w, res_h, old_fov_x, old_fov_y; + + res_w = renderSystem->GetWidth(); + res_h = renderSystem->GetHeight(); + + if( args.Argc() != 2 && args.Argc() != 3 && args.Argc() != 4 ) + { common->Printf( "USAGE: envshot [size] [blends]\n" ); return; } baseName = args.Argv( 1 ); - + blends = 1; - if ( args.Argc() == 4 ) { + if( args.Argc() == 4 ) + { size = atoi( args.Argv( 2 ) ); blends = atoi( args.Argv( 3 ) ); - } else if ( args.Argc() == 3 ) { + } + else if( args.Argc() == 3 ) + { size = atoi( args.Argv( 2 ) ); blends = 1; - } else { + } + else + { size = 256; blends = 1; } - - if ( !tr.primaryView ) { + + if( !tr.primaryView ) + { common->Printf( "No primary view.\n" ); return; } - + primary = *tr.primaryView; - + memset( &axis, 0, sizeof( axis ) ); axis[0][0][0] = 1; // this one gets ignored as it always come out wrong. axis[0][1][2] = 1; // and so we repeat this axis as the last one. axis[0][2][1] = 1; - + axis[1][0][0] = -1; axis[1][1][2] = -1; axis[1][2][1] = 1; - + axis[2][0][1] = 1; axis[2][1][0] = -1; axis[2][2][2] = -1; - + axis[3][0][1] = -1; axis[3][1][0] = -1; axis[3][2][2] = 1; - + axis[4][0][2] = 1; axis[4][1][0] = -1; axis[4][2][1] = 1; - + axis[5][0][2] = -1; axis[5][1][0] = 1; axis[5][2][1] = 1; - - axis[6][0][0] = 1; // this is the repetition of the first axis + + axis[6][0][0] = 1; // this is the repetition of the first axis axis[6][1][2] = 1; axis[6][2][1] = 1; - - // let's get the game window to a "size" resolution - if ( ( res_w != size ) || ( res_h != size ) ) { - cvarSystem->SetCVarInteger( "r_windowWidth", size ); - cvarSystem->SetCVarInteger( "r_windowHeight", size ); - R_SetNewMode( false ); // the same as "vid_restart" - } // FIXME that's a hack!! - - for ( i = 0 ; i < 7 ; i++ ) { - - ref = primary.renderView; - - if ( i == 0 ) { - // so we return to that axis and fov after the fact. - oldAxis = ref.viewaxis; - old_fov_x = ref.fov_x; - old_fov_y = ref.fov_y; - } - + + // let's get the game window to a "size" resolution + if( ( res_w != size ) || ( res_h != size ) ) + { + cvarSystem->SetCVarInteger( "r_windowWidth", size ); + cvarSystem->SetCVarInteger( "r_windowHeight", size ); + R_SetNewMode( false ); // the same as "vid_restart" + } // FIXME that's a hack!! + + for( i = 0 ; i < 7 ; i++ ) + { + + ref = primary.renderView; + + if( i == 0 ) + { + // so we return to that axis and fov after the fact. + oldAxis = ref.viewaxis; + old_fov_x = ref.fov_x; + old_fov_y = ref.fov_y; + //this is part of the hack + extension = "_wrong"; + } + else + { + // this keeps being part of the hack + extension = envDirection[ i - 1 ]; //yes, indeed, this is totally part of the hack! + } + ref.fov_x = ref.fov_y = 90; ref.viewaxis = axis[i]; - sprintf( fullname, "env/%s%s", baseName, extensions[i] ); - + fullname.Format( "env/%s%s", baseName, extension ); + tr.TakeScreenshot( size, size, fullname, blends, &ref, TGA ); } - - // restore the original resolution, axis and fov - ref.viewaxis = oldAxis; - ref.fov_x = old_fov_x; - ref.fov_y = old_fov_y; - cvarSystem->SetCVarInteger( "r_windowWidth", res_w ); - cvarSystem->SetCVarInteger( "r_windowHeight", res_h ); - R_SetNewMode( false ); // the same as "vid_restart" - - common->Printf( "Wrote a env set with the name %s\n", baseName ); + + // restore the original resolution, axis and fov + ref.viewaxis = oldAxis; + ref.fov_x = old_fov_x; + ref.fov_y = old_fov_y; + cvarSystem->SetCVarInteger( "r_windowWidth", res_w ); + cvarSystem->SetCVarInteger( "r_windowHeight", res_h ); + R_SetNewMode( false ); // the same as "vid_restart" + + common->Printf( "Wrote a env set with the name %s\n", baseName ); } //============================================================================ @@ -1699,9 +1735,6 @@ void R_MakeAmbientMap_f( const idCmdArgs& args ) renderView_t ref; viewDef_t primary; int downSample; - const char* extensions[6] = { "_px.tga", "_nx.tga", "_py.tga", "_ny.tga", - "_pz.tga", "_nz.tga" - }; int outSize; byte* buffers[6]; int width = 0, height = 0; @@ -1751,7 +1784,7 @@ void R_MakeAmbientMap_f( const idCmdArgs& args ) // read all of the images for( i = 0 ; i < 6 ; i++ ) { - sprintf( fullname, "env/%s%s", baseName, extensions[i] ); + fullname.Format( "env/%s%s.%s", baseName, envDirection[i], fileExten[TGA] ); common->Printf( "loading %s\n", fullname.c_str() ); const bool captureToImage = false; common->UpdateScreen( captureToImage ); @@ -1826,11 +1859,11 @@ void R_MakeAmbientMap_f( const idCmdArgs& args ) if( map == 0 ) { - sprintf( fullname, "env/%s_amb%s", baseName, extensions[i] ); + fullname.Format( "env/%s_amb%s.%s", baseName, envDirection[i], fileExten[TGA] ); } else { - sprintf( fullname, "env/%s_spec%s", baseName, extensions[i] ); + fullname.Format( "env/%s_spec%s.%s", baseName, envDirection[i], fileExten[TGA] ); } common->Printf( "writing %s\n", fullname.c_str() ); const bool captureToImage = false; @@ -1850,54 +1883,59 @@ void R_MakeAmbientMap_f( const idCmdArgs& args ) void R_TransformCubemap( const char* orgDirection[6], const char* orgDir, const char* destDirection[6], const char* destDir, const char* baseName ) { - idStr fullname; + idStr fullname; int i; - const char* ext = ".tga"; - bool errorInOriginalImages = false; + bool errorInOriginalImages = false; int outSize; byte* buffers[6]; - int width = 0, height = 0; + int width = 0, height = 0; for( i = 0 ; i < 6 ; i++ ) { - // read every image images - sprintf( fullname, "%s/%s%s.%s", orgDir, baseName, orgDirection[i], fileExten [TGA] ); + // read every image images + fullname.Format( "%s/%s%s.%s", orgDir, baseName, orgDirection[i], fileExten [TGA] ); common->Printf( "loading %s\n", fullname.c_str() ); const bool captureToImage = false; common->UpdateScreen( captureToImage ); R_LoadImage( fullname, &buffers[i], &width, &height, NULL, true ); - - //check if the buffer is troublesome - if ( !buffers[i] ) + + //check if the buffer is troublesome + if( !buffers[i] ) { common->Printf( "failed.\n" ); errorInOriginalImages = true; - } else if ( width != height ) { - common->Printf( "wrong size pal!\n\n\nget your shit together and set the size according to your images!\n\n\ninept programmers are inept!\n" ); - errorInOriginalImages = true; // yeah, but don't just choke on a joke! - } else { - errorInOriginalImages = false; - } - - if ( errorInOriginalImages ) { - errorInOriginalImages = false; - for( i-- ; i >= 0 ; i-- ) { + } + else if( width != height ) + { + common->Printf( "wrong size pal!\n\n\nget your shit together and set the size according to your images!\n\n\ninept programmers are inept!\n" ); + errorInOriginalImages = true; // yeah, but don't just choke on a joke! + } + else + { + errorInOriginalImages = false; + } + + if( errorInOriginalImages ) + { + errorInOriginalImages = false; + for( i-- ; i >= 0 ; i-- ) + { Mem_Free( buffers[i] ); // clean up every buffer from this stage down } - + return; - } - - // apply rotations and flips - R_ApplyCubeMapTransforms( i, buffers[i], width ); - - //save the images with the appropiate skybox naming convention - sprintf( fullname, "%s/%s/%s%s.%s", destDir, baseName, baseName, destDirection[i], fileExten [TGA] ); - common->Printf( "writing %s\n", fullname.c_str() ); - common->UpdateScreen( false ); - R_WriteTGA( fullname, buffers[i], width, width ); + } + + // apply rotations and flips + R_ApplyCubeMapTransforms( i, buffers[i], width ); + + //save the images with the appropiate skybox naming convention + fullname.Format( "%s/%s/%s%s.%s", destDir, baseName, baseName, destDirection[i], fileExten [TGA] ); + common->Printf( "writing %s\n", fullname.c_str() ); + common->UpdateScreen( false ); + R_WriteTGA( fullname, buffers[i], width, width ); } - + for( i = 0 ; i < 6 ; i++ ) { if( buffers[i] ) @@ -1917,14 +1955,16 @@ transforms env textures (of the type px, py, pz, nx, ny, nz) to skybox textures ( forward, back, left, right, up, down) ================== */ -void R_TransformEnvToSkybox_f( const idCmdArgs& args ){ +void R_TransformEnvToSkybox_f( const idCmdArgs& args ) +{ - if( args.Argc() != 2 ) { - common->Printf( "USAGE: envToSky \n" ); + if( args.Argc() != 2 ) + { + common->Printf( "USAGE: envToSky \n" ); return; } - - R_TransformCubemap( envDirection, "env", skyDirection, "skybox", args.Argv( 1 ) ); + + R_TransformCubemap( envDirection, "env", skyDirection, "skybox", args.Argv( 1 ) ); } /* @@ -1938,14 +1978,16 @@ to env textures (of the type px, py, pz, nx, ny, nz) ================== */ -void R_TransformSkyboxToEnv_f ( const idCmdArgs& args ){ - - if( args.Argc() != 2 ) { - common->Printf( "USAGE: skyToEnv \n" ); +void R_TransformSkyboxToEnv_f( const idCmdArgs& args ) +{ + + if( args.Argc() != 2 ) + { + common->Printf( "USAGE: skyToEnv \n" ); return; } - - R_TransformCubemap( skyDirection, "skybox", envDirection, "env", args.Argv( 1 ) ); + + R_TransformCubemap( skyDirection, "skybox", envDirection, "env", args.Argv( 1 ) ); } //============================================================================ @@ -2302,10 +2344,10 @@ void R_InitCommands() cmdSystem->AddCommand( "listGuis", R_ListGuis_f, CMD_FL_RENDERER, "lists guis" ); cmdSystem->AddCommand( "touchGui", R_TouchGui_f, CMD_FL_RENDERER, "touches a gui" ); cmdSystem->AddCommand( "screenshot", R_ScreenShot_f, CMD_FL_RENDERER, "takes a screenshot" ); - cmdSystem->AddCommand( "envshot", R_EnvShot_f, CMD_FL_RENDERER, "takes an environment shot" ); + cmdSystem->AddCommand( "envshot", R_EnvShot_f, CMD_FL_RENDERER, "takes an environment shot" ); cmdSystem->AddCommand( "makeAmbientMap", R_MakeAmbientMap_f, CMD_FL_RENDERER | CMD_FL_CHEAT, "makes an ambient map" ); - cmdSystem->AddCommand( "envToSky", R_TransformEnvToSkybox_f, CMD_FL_RENDERER | CMD_FL_CHEAT, "transforms environment textures to sky box textures" ); - cmdSystem->AddCommand( "skyToEnv", R_TransformSkyboxToEnv_f, CMD_FL_RENDERER | CMD_FL_CHEAT, "transforms sky box textures to environment textures" ); + cmdSystem->AddCommand( "envToSky", R_TransformEnvToSkybox_f, CMD_FL_RENDERER | CMD_FL_CHEAT, "transforms environment textures to sky box textures" ); + cmdSystem->AddCommand( "skyToEnv", R_TransformSkyboxToEnv_f, CMD_FL_RENDERER | CMD_FL_CHEAT, "transforms sky box textures to environment textures" ); cmdSystem->AddCommand( "gfxInfo", GfxInfo_f, CMD_FL_RENDERER, "show graphics info" ); cmdSystem->AddCommand( "modulateLights", R_ModulateLights_f, CMD_FL_RENDERER | CMD_FL_CHEAT, "modifies shader parms on all lights" ); cmdSystem->AddCommand( "testImage", R_TestImage_f, CMD_FL_RENDERER | CMD_FL_CHEAT, "displays the given image centered on screen", idCmdSystem::ArgCompletion_ImageName ); From 1f993688c6908543799ee53511081626eeeaf4b6 Mon Sep 17 00:00:00 2001 From: BielBdeLuna <7318.tk@gmail.com> Date: Mon, 25 Aug 2014 16:13:16 +0200 Subject: [PATCH 7/7] image.h included --- neo/framework/common_frame.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo/framework/common_frame.cpp b/neo/framework/common_frame.cpp index ec11fbc2..bae66cc6 100644 --- a/neo/framework/common_frame.cpp +++ b/neo/framework/common_frame.cpp @@ -31,7 +31,7 @@ If you have questions concerning this license or the applicable additional terms #pragma hdrstop #include "Common_local.h" -#include "../renderer/Image.h" +#include "../renderer/Image.h" // now I did it! #include "../renderer/ImageOpts.h" // RB begin