mirror of https://github.com/bkaradzic/bgfx
GL: Fixed HDR example.
This commit is contained in:
parent
84f38ee954
commit
f91addf88a
|
@ -7,7 +7,6 @@
|
|||
#include "bgfx_utils.h"
|
||||
#include "imgui/imgui.h"
|
||||
|
||||
static bool s_flipV = false;
|
||||
static float s_texelHalf = 0.0f;
|
||||
|
||||
struct PosColorTexCoord0Vertex
|
||||
|
@ -208,6 +207,14 @@ int _main_(int /*_argc*/, char** /*_argv*/)
|
|||
imguiCreate(data);
|
||||
free(data);
|
||||
|
||||
const bgfx::RendererType::Enum renderer = bgfx::getRendererType();
|
||||
s_texelHalf = bgfx::RendererType::Direct3D9 == renderer ? 0.5f : 0.0f;
|
||||
const bool originBottomLeft = bgfx::RendererType::OpenGL == renderer || bgfx::RendererType::OpenGLES == renderer;
|
||||
|
||||
uint32_t oldWidth = 0;
|
||||
uint32_t oldHeight = 0;
|
||||
uint32_t oldReset = reset;
|
||||
|
||||
float speed = 0.37f;
|
||||
float middleGray = 0.18f;
|
||||
float white = 1.1f;
|
||||
|
@ -215,10 +222,6 @@ int _main_(int /*_argc*/, char** /*_argv*/)
|
|||
|
||||
int32_t scrollArea = 0;
|
||||
|
||||
uint32_t oldWidth = 0;
|
||||
uint32_t oldHeight = 0;
|
||||
uint32_t oldReset = reset;
|
||||
|
||||
float time = 0.0f;
|
||||
|
||||
entry::MouseState mouseState;
|
||||
|
@ -374,7 +377,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
|
|||
bgfx::setTexture(0, u_texColor, fbtextures[0]);
|
||||
bgfx::setProgram(lumProgram);
|
||||
bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE);
|
||||
screenSpaceQuad(128.0f, 128.0f, s_flipV);
|
||||
screenSpaceQuad(128.0f, 128.0f, originBottomLeft);
|
||||
bgfx::submit(2);
|
||||
|
||||
// Downscale luminance 0.
|
||||
|
@ -382,7 +385,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
|
|||
bgfx::setTexture(0, u_texColor, lum[0]);
|
||||
bgfx::setProgram(lumAvgProgram);
|
||||
bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE);
|
||||
screenSpaceQuad(64.0f, 64.0f, s_flipV);
|
||||
screenSpaceQuad(64.0f, 64.0f, originBottomLeft);
|
||||
bgfx::submit(3);
|
||||
|
||||
// Downscale luminance 1.
|
||||
|
@ -390,7 +393,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
|
|||
bgfx::setTexture(0, u_texColor, lum[1]);
|
||||
bgfx::setProgram(lumAvgProgram);
|
||||
bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE);
|
||||
screenSpaceQuad(16.0f, 16.0f, s_flipV);
|
||||
screenSpaceQuad(16.0f, 16.0f, originBottomLeft);
|
||||
bgfx::submit(4);
|
||||
|
||||
// Downscale luminance 2.
|
||||
|
@ -398,7 +401,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
|
|||
bgfx::setTexture(0, u_texColor, lum[2]);
|
||||
bgfx::setProgram(lumAvgProgram);
|
||||
bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE);
|
||||
screenSpaceQuad(4.0f, 4.0f, s_flipV);
|
||||
screenSpaceQuad(4.0f, 4.0f, originBottomLeft);
|
||||
bgfx::submit(5);
|
||||
|
||||
// Downscale luminance 3.
|
||||
|
@ -406,7 +409,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
|
|||
bgfx::setTexture(0, u_texColor, lum[3]);
|
||||
bgfx::setProgram(lumAvgProgram);
|
||||
bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE);
|
||||
screenSpaceQuad(1.0f, 1.0f, s_flipV);
|
||||
screenSpaceQuad(1.0f, 1.0f, originBottomLeft);
|
||||
bgfx::submit(6);
|
||||
|
||||
float tonemap[4] = { middleGray, square(white), treshold, 0.0f };
|
||||
|
@ -418,14 +421,14 @@ int _main_(int /*_argc*/, char** /*_argv*/)
|
|||
bgfx::setTexture(1, u_texLum, lum[4]);
|
||||
bgfx::setProgram(brightProgram);
|
||||
bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE);
|
||||
screenSpaceQuad( (float)width/2.0f, (float)height/2.0f, s_flipV);
|
||||
screenSpaceQuad( (float)width/2.0f, (float)height/2.0f, originBottomLeft);
|
||||
bgfx::submit(7);
|
||||
|
||||
// Blur bright pass vertically.
|
||||
bgfx::setTexture(0, u_texColor, bright);
|
||||
bgfx::setProgram(blurProgram);
|
||||
bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE);
|
||||
screenSpaceQuad( (float)width/8.0f, (float)height/8.0f, s_flipV);
|
||||
screenSpaceQuad( (float)width/8.0f, (float)height/8.0f, originBottomLeft);
|
||||
bgfx::submit(8);
|
||||
|
||||
// Blur bright pass horizontally, do tonemaping and combine.
|
||||
|
@ -434,7 +437,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
|
|||
bgfx::setTexture(2, u_texBlur, blur);
|
||||
bgfx::setProgram(tonemapProgram);
|
||||
bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE);
|
||||
screenSpaceQuad( (float)width, (float)height, s_flipV);
|
||||
screenSpaceQuad( (float)width, (float)height, originBottomLeft);
|
||||
bgfx::submit(9);
|
||||
|
||||
// Advance to next frame. Rendering thread will be kicked to
|
||||
|
|
Loading…
Reference in New Issue