Bloom and Tonemap
Posted: Fri Jul 29, 2016 21:08
Pull request: https://github.com/coelckers/gzdoom/pull/65
I've finished my bloom and tonemapping changes. That makes the pipeline roughly look like this:
render scene -> scene texture -> bloom -> bloom down/upscale textures -> moar bloom! -> scene texture -> tonemap -> 2D/hud texture -> hud/menu drawing -> hud texture -> present -> back buffer
The various parts of the pipeline can be disabled in the menus. For example if bloom is disabled it skips those parts entirely. Likewise, if there is no tonemap mode enabled it leaves out the 2D/HUD texture entirely and draws the 2D parts directly on top of the scene. If render buffers are disabled entirely (via gl_renderbuffers 0) it renders the scene and 2D directly to the back buffer.
Because the scene texture is in the RGBA16F floating point format we are technically doing HDR rendering now - we can do lights beyond 1 (light level 255). As tonemap operators aren't really needed unless we go beyond this range (they map things down to 0-1) it opens the question whether we should try extend Doom in ways that allow for more fancy lighting. For example maybe we could allow sector lights beyond 255? I'm not sure what possibilities we have here - maybe gzdoom already supports it.
I've added a gl_exposure cvar that works like the exposure control/shutter on a camera. At 1.0 anything above 1 in the scene begins to bloom. At 2.0 anything above 0.5 blooms and, if tonemap is enabled, this range is mapped to 0-1. If it is set to 0.5 you need something above 2.0 in the scene before it starts to bloom and so on.
There's also a gl_bloom_amount cvar that controls how much gaussian blur is being done, and a gl_bloom_kernel_size that sets the blur kernel (3x3, 5x5, 7x7, etc.). I could imagine some modders would find it interesting to be able to set light values above 1, along with changing the exposure and which tonemap operator (if any) should be used. For now, I've made it so that if exposure is set to 0 (the default) the code automatically calculates an exposure based on the view sector. If you stand in dark areas the more bright areas begin to bloom.
The pull request also addresses the OpenGL 2 issue we talked about in the gamma thread. It now should work with all versions as long as shaders aren't completely disabled. I tried to make the patching share a little code with FShader although not completely.
Phew! That's about it I think!
I've finished my bloom and tonemapping changes. That makes the pipeline roughly look like this:
render scene -> scene texture -> bloom -> bloom down/upscale textures -> moar bloom! -> scene texture -> tonemap -> 2D/hud texture -> hud/menu drawing -> hud texture -> present -> back buffer
The various parts of the pipeline can be disabled in the menus. For example if bloom is disabled it skips those parts entirely. Likewise, if there is no tonemap mode enabled it leaves out the 2D/HUD texture entirely and draws the 2D parts directly on top of the scene. If render buffers are disabled entirely (via gl_renderbuffers 0) it renders the scene and 2D directly to the back buffer.
Because the scene texture is in the RGBA16F floating point format we are technically doing HDR rendering now - we can do lights beyond 1 (light level 255). As tonemap operators aren't really needed unless we go beyond this range (they map things down to 0-1) it opens the question whether we should try extend Doom in ways that allow for more fancy lighting. For example maybe we could allow sector lights beyond 255? I'm not sure what possibilities we have here - maybe gzdoom already supports it.
I've added a gl_exposure cvar that works like the exposure control/shutter on a camera. At 1.0 anything above 1 in the scene begins to bloom. At 2.0 anything above 0.5 blooms and, if tonemap is enabled, this range is mapped to 0-1. If it is set to 0.5 you need something above 2.0 in the scene before it starts to bloom and so on.
There's also a gl_bloom_amount cvar that controls how much gaussian blur is being done, and a gl_bloom_kernel_size that sets the blur kernel (3x3, 5x5, 7x7, etc.). I could imagine some modders would find it interesting to be able to set light values above 1, along with changing the exposure and which tonemap operator (if any) should be used. For now, I've made it so that if exposure is set to 0 (the default) the code automatically calculates an exposure based on the view sector. If you stand in dark areas the more bright areas begin to bloom.
The pull request also addresses the OpenGL 2 issue we talked about in the gamma thread. It now should work with all versions as long as shaders aren't completely disabled. I tried to make the patching share a little code with FShader although not completely.
Phew! That's about it I think!