inline void storeFramebuffer(int resultIndex, const FilePath& pngDir, const FilePath& exrDir, const FilePath& baseName, float gamma, const Framebuffer& framebuffer) { // Create output directories in case they don't exist createDirectory(pngDir.str()); createDirectory(exrDir.str()); // Path of primary output image files FilePath pngFile = pngDir + baseName.addExt(".png"); FilePath exrFile = exrDir + baseName.addExt(".exr"); // Make a copy of the image Image copy = framebuffer.getChannel(0); // Store the EXR image "as is" storeEXRImage(exrFile.str(), copy); // Post-process copy of image and store PNG file copy.flipY(); copy.divideByAlpha(); copy.applyGamma(gamma); storeImage(pngFile.str(), copy); // Store complete framebuffer as a single EXR multi layer image auto exrFramebufferFilePath = exrDir + baseName.addExt(".bnzframebuffer.exr"); storeEXRFramebuffer(exrFramebufferFilePath.str(), framebuffer); // Store complete framebuffer as PNG indivual files in a dediacted subdirectory auto pngFramebufferDirPath = pngDir + "framebuffers/"; createDirectory(pngFramebufferDirPath.str()); if(resultIndex >= 0) { pngFramebufferDirPath = pngFramebufferDirPath + toString3(resultIndex); // Split different results of the same batch in different subdirectories } createDirectory(pngFramebufferDirPath.str()); // Store each channel of the framebuffer for(auto i = 0u; i < framebuffer.getChannelCount(); ++i) { auto name = framebuffer.getChannelName(i); // Prefix by the index of the channel FilePath pngFile = pngFramebufferDirPath + FilePath(toString3(i)).addExt("_" + name + ".png"); auto copy = framebuffer.getChannel(i); copy.flipY(); copy.divideByAlpha(); copy.applyGamma(gamma); storeImage(pngFile.str(), copy); } }
void AnimInfo::save(const FilePath& path) { FILE* file = fopen(path.str(), "w"); if (!file) { printf("cannot open for write \"%s\"\n", path.str()); return; } fprintf(file, "%s", _tex_name.c_str()); for (int i = 0; i < _frames.size(); i++) { Frame& frame = _frames[i]; fprintf(file, "\n%d %d %d %d %d %d", frame.x(), frame.y(), frame.w(), frame.h(), frame.dx(), frame.dy()); } fclose(file); }
PG15RendererManager(const Scene& scene, const Sensor& sensor, Vec2u framebufferSize, const FilePath& referenceImagePath, const FilePath& resultPath, tinyxml2::XMLDocument& configDoc, tinyxml2::XMLDocument& sceneDoc, float gamma, std::size_t renderTimeMsOrIterationCount, std::size_t maxPathDepth, std::size_t resamplingPathCount, const PG15ICBPTSettings& icBPTSettings, const std::vector<PG15SkelBPTSettings>& skelBPTSettings, bool equalTime): m_ResultPath(resultPath), m_Params(scene, sensor, framebufferSize, maxPathDepth, resamplingPathCount), m_SharedData(framebufferSize.x * framebufferSize.y, m_Params.m_nMaxDepth - 1u), m_pReferenceImage(loadEXRImage(referenceImagePath.str())), m_ICBPTRenderer(m_Params, m_SharedData, icBPTSettings), m_RenderStatistics(2 + skelBPTSettings.size()), m_fGamma(gamma), m_nRenderTimeMsOrIterationCount(renderTimeMsOrIterationCount), m_bEqualTime(equalTime) { for(const auto& settings: skelBPTSettings) { m_SkelBPTRenderers.emplace_back(m_Params, m_SharedData, settings); } m_Rng.init(getSystemThreadCount(), m_nSeed); m_SharedData.m_LightSampler.initFrame(scene); initResultDir(configDoc, sceneDoc); }
// Load source code from files and build a GLSL program Program loadProgramShader(const FilePath& vsFile, const FilePath& fsFile) { Shader vs = loadShader(GL_VERTEX_SHADER, vsFile); Shader fs = loadShader(GL_FRAGMENT_SHADER, fsFile); if(!vs.compile()) { throw std::runtime_error("Compilation error for vertex shader (from file " + std::string(vsFile) + "): " + vs.getInfoLog()); } if(!fs.compile()) { throw std::runtime_error("Compilation error for fragment shader (from file " + std::string(fsFile) + "): " + fs.getInfoLog()); } Program program; program.attachShader(vs); program.attachShader(fs); if(!program.link()) { throw std::runtime_error("Link error (for files " + vsFile.str() + " and " + fsFile.str() + "): " + program.getInfoLog()); } return program; }
Shader loadShader(GLenum type, const FilePath& filepath) { std::ifstream input(filepath.c_str()); if(!input) { throw std::runtime_error("Unable to load the file " + filepath.str()); } std::stringstream buffer; buffer << input.rdbuf(); Shader shader(type); shader.setSource(buffer.str().c_str()); return shader; }
void AnimInfo::load(const FilePath& path) { TextFile file(path); if (!file.open()) { printf("cannot open for read \"%s\"\n", path.str()); return; } clear(); _tex_name = strip(file.read_line()); std::string current_frame = file.read_line(); while (!current_frame.empty()) { std::string result; std::vector<int> results; for (int i = 0; i < current_frame.size(); i++) { char c = current_frame[i]; if (c == ' ' || c == '\n') { results.push_back(atoi(result.c_str())); result = ""; continue; } result.push_back(c); } if (!result.empty()) { results.push_back(atoi(result.c_str())); } int xx = results[0]; int yy = results[1]; int w = results[2]; int h = results[3]; int dx = results[4]; int dy = results[5]; _frames.push_back(Frame(xx, yy, w, h, dx, dy)); current_frame = file.read_line(); } }