bool VTerrainSectorRenderer::SaveRenderTarget(VTerrainSector* pSector, VisRenderableTexture_cl *pTex, const char *szFilePath) { VASSERT(pSector); // since the functions below require an absolute path, we somehow need to get from a relative path to an absolute path // opening a file and getting its then final path is the only way, that I found, to accomplish this char szAbsFilename[FS_MAX_PATH]; // create the file and convert the relative path into an absolute path IVFileOutStream* pStream = Vision::File.Create (szFilePath); if (!pStream) return false; strcpy (szAbsFilename, pStream->GetFileName()); pStream->Close(); VRCSHelper::RCSEditFile(szAbsFilename); if (pTex==NULL) return false; int sx = pTex->GetTextureWidth(); int sy = pTex->GetTextureHeight(); Image_cl image; VMemoryTempBuffer<512*512*3> buffer(sx*sy*3); UBYTE* pDest = (UBYTE*)buffer.GetBuffer(); Vision::Game.WriteScreenToBuffer(0, 0, sx, sy, pDest, pTex); if(Vision::Renderer.GetSRGBMode() == V_SRGB_ASSUME_FOR_DIFFUSE) { for (int i = 0; i < sx*sy*3; ++i) pDest[i] = (UBYTE) (LinearToSrgb (((float) pDest[i]) / 255.0f) * 255.0f); } // The terrain sector renderer leaves a border area around the sector being rendered, // this is required to ensure proper texture filtering on sector edges. Into this border area // the neighbor sectors are rendered to, but not each sector has a neighbor on each side, thus the next // step fills all the pixels where nothing has been rendered to. FillBorders(pSector, sx, sy, m_iBorderWidth, pDest); image.AddColorMap(sx,sy,COLORDEPTH_24BPP,pDest); int iSavingResult = -1; if (VFileHelper::HasExtension(szAbsFilename,"BMP")) iSavingResult = image.SaveBMP(szAbsFilename); else if (VFileHelper::HasExtension(szAbsFilename,"JPG")) iSavingResult = image.SaveJPEG(szAbsFilename); else if (VFileHelper::HasExtension(szAbsFilename,"JPEG")) iSavingResult = image.SaveJPEG(szAbsFilename); else if (VFileHelper::HasExtension(szAbsFilename,"TGA")) iSavingResult = image.SaveTGA(szAbsFilename); else if (VFileHelper::HasExtension(szAbsFilename,"DDS")) iSavingResult = image.SaveUncompressedDDS(szAbsFilename); VRCSHelper::RCSAddFile(szAbsFilename, true /* Binary file */); return iSavingResult == 0; }
void Fluid::ComputePressureField( int maxIterations, const View<float, 1>& velocitiesDivergence, View<float, 1>* pressureField) const { const float alpha = -_gridScale * _gridScale; const float beta = 4.0f; // TODO: What would be a meaningfull initial guess? FillImage(0.0f, pressureField); FillBorders(1.0f, velocitiesDivergence, pressureField); _pressureSolver.Solve(alpha, beta, maxIterations, velocitiesDivergence, pressureField); }
void Fluid::Diffuse( float timeStep, int maxIterations, const View2f& velocities, View2f* velocitiesDiffused) const { const float alpha = (_gridScale * _gridScale) / (_viscosity * timeStep); const float beta = 4.0f + alpha; // TODO: What would be a meaningfull initial guess ? FillImage(Vector2(0.0f, 0.0f), velocitiesDiffused); FillBorders(-1.0f, velocities, velocitiesDiffused); _diffusionSolver.Solve(alpha, beta, maxIterations, velocities, velocitiesDiffused); }