To implement HDR tone mapping, we'll perform the following steps:
- In the first pass, we want to just render the scene to the high-resolution texture. Bind to the framebuffer that has the texture attached and render the scene normally.
- Compute the log average luminance of the pixels in the texture. To do so, we'll pull the data from the texture and loop through the pixels on the CPU side. We do this on the CPU for simplicity; a GPU implementation, perhaps with a compute shader, would be faster:
int size = width * height;std::vector<GLfloat> texData(size*3);glActiveTexture(GL_TEXTURE0);glBindTexture(GL_TEXTURE_2D, hdrTex);glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_FLOAT, texData.data());float sum = 0.0f;for( int i = 0; i ...