mirror of
https://github.com/ZDoom/qzdoom-gpl.git
synced 2024-11-29 15:12:11 +00:00
Merge branch 'exposure_pass' into lightmath
# Conflicts: # src/gl/renderer/gl_renderbuffers.cpp # src/gl/renderer/gl_renderbuffers.h # src/gl/renderer/gl_renderer.h # src/gl/scene/gl_scene.cpp
This commit is contained in:
commit
38be2333d0
16 changed files with 327 additions and 34 deletions
|
@ -76,7 +76,10 @@ CUSTOM_CVAR(Float, gl_bloom_amount, 1.4f, 0)
|
|||
if (self < 0.1f) self = 0.1f;
|
||||
}
|
||||
|
||||
CVAR(Float, gl_exposure, 0.0f, 0)
|
||||
CVAR(Float, gl_exposure_scale, 0.75f, 0)
|
||||
CVAR(Float, gl_exposure_min, 0.35f, 0)
|
||||
CVAR(Float, gl_exposure_base, 0.35f, 0)
|
||||
CVAR(Float, gl_exposure_speed, 0.05f, 0)
|
||||
|
||||
CUSTOM_CVAR(Int, gl_tonemap, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
|
||||
{
|
||||
|
@ -120,6 +123,7 @@ void FGLRenderer::RenderScreenQuad()
|
|||
void FGLRenderer::PostProcessScene()
|
||||
{
|
||||
mBuffers->BlitSceneToTexture();
|
||||
UpdateCameraExposure();
|
||||
BloomScene();
|
||||
TonemapScene();
|
||||
ColormapScene();
|
||||
|
@ -242,6 +246,78 @@ void FGLRenderer::AmbientOccludeScene()
|
|||
FGLDebug::PopGroup();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Extracts light average from the scene and updates the camera exposure texture
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void FGLRenderer::UpdateCameraExposure()
|
||||
{
|
||||
if (!gl_bloom && gl_tonemap == 0)
|
||||
return;
|
||||
|
||||
FGLDebug::PushGroup("UpdateCameraExposure");
|
||||
|
||||
FGLPostProcessState savedState;
|
||||
savedState.SaveTextureBinding1();
|
||||
|
||||
// Extract light level from scene texture:
|
||||
const auto &level0 = mBuffers->ExposureLevels[0];
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, level0.Framebuffer);
|
||||
glViewport(0, 0, level0.Width, level0.Height);
|
||||
mBuffers->BindCurrentTexture(0);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
mExposureExtractShader->Bind();
|
||||
mExposureExtractShader->SceneTexture.Set(0);
|
||||
mExposureExtractShader->Scale.Set(mSceneViewport.width / (float)mScreenViewport.width, mSceneViewport.height / (float)mScreenViewport.height);
|
||||
mExposureExtractShader->Offset.Set(mSceneViewport.left / (float)mScreenViewport.width, mSceneViewport.top / (float)mScreenViewport.height);
|
||||
RenderScreenQuad();
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
|
||||
// Find the average value:
|
||||
for (int i = 0; i + 1 < mBuffers->ExposureLevels.Size(); i++)
|
||||
{
|
||||
const auto &level = mBuffers->ExposureLevels[i];
|
||||
const auto &next = mBuffers->ExposureLevels[i + 1];
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, next.Framebuffer);
|
||||
glViewport(0, 0, next.Width, next.Height);
|
||||
glBindTexture(GL_TEXTURE_2D, level.Texture);
|
||||
mExposureAverageShader->Bind();
|
||||
mExposureAverageShader->ExposureTexture.Set(0);
|
||||
RenderScreenQuad();
|
||||
}
|
||||
|
||||
// Combine average value with current camera exposure:
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, mBuffers->ExposureFB);
|
||||
glViewport(0, 0, 1, 1);
|
||||
if (!mBuffers->FirstExposureFrame)
|
||||
{
|
||||
glEnable(GL_BLEND);
|
||||
glBlendEquation(GL_FUNC_ADD);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
else
|
||||
{
|
||||
mBuffers->FirstExposureFrame = false;
|
||||
}
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, mBuffers->ExposureLevels.Last().Texture);
|
||||
mExposureCombineShader->Bind();
|
||||
mExposureCombineShader->ExposureTexture.Set(0);
|
||||
mExposureCombineShader->ExposureBase.Set(gl_exposure_base);
|
||||
mExposureCombineShader->ExposureMin.Set(gl_exposure_min);
|
||||
mExposureCombineShader->ExposureScale.Set(gl_exposure_scale);
|
||||
mExposureCombineShader->ExposureSpeed.Set(gl_exposure_speed);
|
||||
RenderScreenQuad();
|
||||
glViewport(mScreenViewport.left, mScreenViewport.top, mScreenViewport.width, mScreenViewport.height);
|
||||
|
||||
FGLDebug::PopGroup();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Adds bloom contribution to scene texture
|
||||
|
@ -257,6 +333,7 @@ void FGLRenderer::BloomScene()
|
|||
FGLDebug::PushGroup("BloomScene");
|
||||
|
||||
FGLPostProcessState savedState;
|
||||
savedState.SaveTextureBinding1();
|
||||
|
||||
const float blurAmount = gl_bloom_amount;
|
||||
int sampleCount = gl_bloom_kernel_size;
|
||||
|
@ -269,9 +346,12 @@ void FGLRenderer::BloomScene()
|
|||
mBuffers->BindCurrentTexture(0);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, mBuffers->ExposureTexture);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
mBloomExtractShader->Bind();
|
||||
mBloomExtractShader->SceneTexture.Set(0);
|
||||
mBloomExtractShader->Exposure.Set(mCameraExposure);
|
||||
mBloomExtractShader->ExposureTexture.Set(1);
|
||||
mBloomExtractShader->Scale.Set(mSceneViewport.width / (float)mScreenViewport.width, mSceneViewport.height / (float)mScreenViewport.height);
|
||||
mBloomExtractShader->Offset.Set(mSceneViewport.left / (float)mScreenViewport.width, mSceneViewport.top / (float)mScreenViewport.height);
|
||||
RenderScreenQuad();
|
||||
|
@ -356,7 +436,12 @@ void FGLRenderer::TonemapScene()
|
|||
}
|
||||
else
|
||||
{
|
||||
mTonemapShader->Exposure.Set(mCameraExposure);
|
||||
savedState.SaveTextureBinding1();
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, mBuffers->ExposureTexture);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
mTonemapShader->ExposureTexture.Set(1);
|
||||
}
|
||||
|
||||
RenderScreenQuad();
|
||||
|
|
|
@ -75,6 +75,7 @@ FGLRenderBuffers::~FGLRenderBuffers()
|
|||
ClearPipeline();
|
||||
ClearEyeBuffers();
|
||||
ClearBloom();
|
||||
ClearExposureLevels();
|
||||
ClearAmbientOcclusion();
|
||||
}
|
||||
|
||||
|
@ -107,13 +108,16 @@ void FGLRenderBuffers::ClearBloom()
|
|||
}
|
||||
}
|
||||
|
||||
void FGLRenderBuffers::ClearAmbientOcclusion()
|
||||
void FGLRenderBuffers::ClearExposureLevels()
|
||||
{
|
||||
DeleteFrameBuffer(AmbientFB0);
|
||||
DeleteFrameBuffer(AmbientFB1);
|
||||
DeleteTexture(AmbientTexture0);
|
||||
DeleteTexture(AmbientTexture1);
|
||||
DeleteTexture(AmbientRandomTexture);
|
||||
for (auto &level : ExposureLevels)
|
||||
{
|
||||
DeleteTexture(level.Texture);
|
||||
DeleteFrameBuffer(level.Framebuffer);
|
||||
}
|
||||
ExposureLevels.Clear();
|
||||
DeleteTexture(ExposureTexture);
|
||||
DeleteFrameBuffer(ExposureFB);
|
||||
}
|
||||
|
||||
void FGLRenderBuffers::ClearEyeBuffers()
|
||||
|
@ -128,6 +132,15 @@ void FGLRenderBuffers::ClearEyeBuffers()
|
|||
mEyeFBs.Clear();
|
||||
}
|
||||
|
||||
void FGLRenderBuffers::ClearAmbientOcclusion()
|
||||
{
|
||||
DeleteFrameBuffer(AmbientFB0);
|
||||
DeleteFrameBuffer(AmbientFB1);
|
||||
DeleteTexture(AmbientTexture0);
|
||||
DeleteTexture(AmbientTexture1);
|
||||
DeleteTexture(AmbientRandomTexture);
|
||||
}
|
||||
|
||||
void FGLRenderBuffers::DeleteTexture(GLuint &handle)
|
||||
{
|
||||
if (handle != 0)
|
||||
|
@ -198,6 +211,7 @@ bool FGLRenderBuffers::Setup(int width, int height, int sceneWidth, int sceneHei
|
|||
if (mSceneWidth != sceneWidth || mSceneHeight != sceneHeight)
|
||||
{
|
||||
CreateBloom(sceneWidth, sceneHeight);
|
||||
CreateExposureLevels(sceneWidth, sceneHeight);
|
||||
CreateAmbientOcclusion(sceneWidth, sceneHeight);
|
||||
mSceneWidth = sceneWidth;
|
||||
mSceneHeight = sceneHeight;
|
||||
|
@ -214,6 +228,7 @@ bool FGLRenderBuffers::Setup(int width, int height, int sceneWidth, int sceneHei
|
|||
ClearPipeline();
|
||||
ClearEyeBuffers();
|
||||
ClearBloom();
|
||||
ClearExposureLevels();
|
||||
mWidth = 0;
|
||||
mHeight = 0;
|
||||
mSamples = 0;
|
||||
|
@ -338,6 +353,41 @@ void FGLRenderBuffers::CreateAmbientOcclusion(int width, int height)
|
|||
AmbientRandomTexture = Create2DTexture("AmbientRandomTexture", GL_RGBA16_SNORM, 4, 4, randomValues);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Creates camera exposure level buffers
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void FGLRenderBuffers::CreateExposureLevels(int width, int height)
|
||||
{
|
||||
ClearExposureLevels();
|
||||
|
||||
int i = 0;
|
||||
do
|
||||
{
|
||||
width = MAX(width / 2, 1);
|
||||
height = MAX(height / 2, 1);
|
||||
|
||||
FString textureName, fbName;
|
||||
textureName.Format("Exposure.Texture%d", i);
|
||||
fbName.Format("Exposure.Framebuffer%d", i);
|
||||
i++;
|
||||
|
||||
FGLExposureTextureLevel level;
|
||||
level.Width = width;
|
||||
level.Height = height;
|
||||
level.Texture = Create2DTexture(textureName, GL_R32F, level.Width, level.Height);
|
||||
level.Framebuffer = CreateFrameBuffer(fbName, level.Texture);
|
||||
ExposureLevels.Push(level);
|
||||
} while (width > 1 || height > 1);
|
||||
|
||||
ExposureTexture = Create2DTexture("Exposure.CameraTexture", GL_R32F, 1, 1);
|
||||
ExposureFB = CreateFrameBuffer("Exposure.CameraFB", ExposureTexture);
|
||||
|
||||
FirstExposureFrame = true;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Creates eye buffers if needed
|
||||
|
|
|
@ -14,6 +14,15 @@ public:
|
|||
GLuint Height = 0;
|
||||
};
|
||||
|
||||
class FGLExposureTextureLevel
|
||||
{
|
||||
public:
|
||||
GLuint Texture = 0;
|
||||
GLuint Framebuffer = 0;
|
||||
GLuint Width = 0;
|
||||
GLuint Height = 0;
|
||||
};
|
||||
|
||||
class FGLRenderBuffers
|
||||
{
|
||||
public:
|
||||
|
@ -41,6 +50,11 @@ public:
|
|||
enum { NumBloomLevels = 4 };
|
||||
FGLBloomTextureLevel BloomLevels[NumBloomLevels];
|
||||
|
||||
TArray<FGLExposureTextureLevel> ExposureLevels;
|
||||
GLuint ExposureTexture = 0;
|
||||
GLuint ExposureFB = 0;
|
||||
bool FirstExposureFrame = true;
|
||||
|
||||
// Ambient occlusion buffers
|
||||
GLuint AmbientTexture0 = 0;
|
||||
GLuint AmbientTexture1 = 0;
|
||||
|
@ -63,12 +77,14 @@ private:
|
|||
void ClearPipeline();
|
||||
void ClearEyeBuffers();
|
||||
void ClearBloom();
|
||||
void ClearExposureLevels();
|
||||
void ClearAmbientOcclusion();
|
||||
void CreateScene(int width, int height, int samples);
|
||||
void CreatePipeline(int width, int height);
|
||||
void CreateBloom(int width, int height);
|
||||
void CreateAmbientOcclusion(int width, int height);
|
||||
void CreateExposureLevels(int width, int height);
|
||||
void CreateEyeBuffers(int eye);
|
||||
void CreateAmbientOcclusion(int width, int height);
|
||||
GLuint Create2DTexture(const FString &name, GLuint format, int width, int height, const void *data = nullptr);
|
||||
GLuint Create2DMultisampleTexture(const FString &name, GLuint format, int width, int height, int samples, bool fixedSampleLocations);
|
||||
GLuint CreateRenderBuffer(const FString &name, GLuint format, int width, int height);
|
||||
|
|
|
@ -105,6 +105,9 @@ FGLRenderer::FGLRenderer(OpenGLFrameBuffer *fb)
|
|||
mPresentShader = nullptr;
|
||||
mBloomExtractShader = nullptr;
|
||||
mBloomCombineShader = nullptr;
|
||||
mExposureExtractShader = nullptr;
|
||||
mExposureAverageShader = nullptr;
|
||||
mExposureCombineShader = nullptr;
|
||||
mBlurShader = nullptr;
|
||||
mTonemapShader = nullptr;
|
||||
mTonemapPalette = nullptr;
|
||||
|
@ -128,6 +131,9 @@ void FGLRenderer::Initialize(int width, int height)
|
|||
mSSAOCombineShader = new FSSAOCombineShader();
|
||||
mBloomExtractShader = new FBloomExtractShader();
|
||||
mBloomCombineShader = new FBloomCombineShader();
|
||||
mExposureExtractShader = new FExposureExtractShader();
|
||||
mExposureAverageShader = new FExposureAverageShader();
|
||||
mExposureCombineShader = new FExposureCombineShader();
|
||||
mBlurShader = new FBlurShader();
|
||||
mTonemapShader = new FTonemapShader();
|
||||
mColormapShader = new FColormapShader();
|
||||
|
@ -192,6 +198,9 @@ FGLRenderer::~FGLRenderer()
|
|||
if (mSSAOCombineShader) delete mSSAOCombineShader;
|
||||
if (mBloomExtractShader) delete mBloomExtractShader;
|
||||
if (mBloomCombineShader) delete mBloomCombineShader;
|
||||
if (mExposureExtractShader) delete mExposureExtractShader;
|
||||
if (mExposureAverageShader) delete mExposureAverageShader;
|
||||
if (mExposureCombineShader) delete mExposureCombineShader;
|
||||
if (mBlurShader) delete mBlurShader;
|
||||
if (mTonemapShader) delete mTonemapShader;
|
||||
if (mTonemapPalette) delete mTonemapPalette;
|
||||
|
|
|
@ -25,6 +25,9 @@ class FSSAOShader;
|
|||
class FSSAOCombineShader;
|
||||
class FBloomExtractShader;
|
||||
class FBloomCombineShader;
|
||||
class FExposureExtractShader;
|
||||
class FExposureAverageShader;
|
||||
class FExposureCombineShader;
|
||||
class FBlurShader;
|
||||
class FTonemapShader;
|
||||
class FColormapShader;
|
||||
|
@ -100,6 +103,9 @@ public:
|
|||
FSSAOCombineShader *mSSAOCombineShader;
|
||||
FBloomExtractShader *mBloomExtractShader;
|
||||
FBloomCombineShader *mBloomCombineShader;
|
||||
FExposureExtractShader *mExposureExtractShader;
|
||||
FExposureAverageShader *mExposureAverageShader;
|
||||
FExposureCombineShader *mExposureCombineShader;
|
||||
FBlurShader *mBlurShader;
|
||||
FTonemapShader *mTonemapShader;
|
||||
FColormapShader *mColormapShader;
|
||||
|
@ -126,7 +132,6 @@ public:
|
|||
GL_IRECT mSceneViewport;
|
||||
GL_IRECT mOutputLetterbox;
|
||||
bool mDrawingScene2D = false;
|
||||
float mCameraExposure = 1.0f;
|
||||
|
||||
float mSceneClearColor[3];
|
||||
|
||||
|
@ -176,6 +181,7 @@ public:
|
|||
void EndDrawScene(sector_t * viewsector);
|
||||
void PostProcessScene();
|
||||
void AmbientOccludeScene();
|
||||
void UpdateCameraExposure();
|
||||
void BloomScene();
|
||||
void TonemapScene();
|
||||
void ColormapScene();
|
||||
|
|
|
@ -427,7 +427,7 @@ void GLPortal::End(bool usestencil)
|
|||
gl_RenderState.SetEffect(EFF_STENCIL);
|
||||
gl_RenderState.EnableTexture(false);
|
||||
gl_RenderState.BlendFunc(GL_ONE, GL_ZERO);
|
||||
gl_RenderState.BlendEquation(GL_ADD);
|
||||
gl_RenderState.BlendEquation(GL_FUNC_ADD);
|
||||
gl_RenderState.Apply();
|
||||
DrawPortalStencil();
|
||||
gl_RenderState.SetEffect(EFF_NONE);
|
||||
|
|
|
@ -792,20 +792,6 @@ sector_t * FGLRenderer::RenderViewpoint (AActor * camera, GL_IRECT * bounds, flo
|
|||
mViewActor=camera;
|
||||
}
|
||||
|
||||
if (toscreen)
|
||||
{
|
||||
if (gl_exposure == 0.0f)
|
||||
{
|
||||
float light = viewsector->lightlevel / 255.0f;
|
||||
float exposure = MAX(1.0f + (1.0f - light * light) * 0.9f, 0.5f);
|
||||
mCameraExposure = mCameraExposure * 0.995f + exposure * 0.005f;
|
||||
}
|
||||
else
|
||||
{
|
||||
mCameraExposure = gl_exposure;
|
||||
}
|
||||
}
|
||||
|
||||
// 'viewsector' will not survive the rendering so it cannot be used anymore below.
|
||||
lviewsector = viewsector;
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ void FBloomExtractShader::Bind()
|
|||
mShader.Link("shaders/glsl/bloomextract");
|
||||
mShader.SetAttribLocation(0, "PositionInProjection");
|
||||
SceneTexture.Init(mShader, "SceneTexture");
|
||||
Exposure.Init(mShader, "ExposureAdjustment");
|
||||
ExposureTexture.Init(mShader, "ExposureTexture");
|
||||
Scale.Init(mShader, "Scale");
|
||||
Offset.Init(mShader, "Offset");
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ public:
|
|||
void Bind();
|
||||
|
||||
FBufferedUniformSampler SceneTexture;
|
||||
FBufferedUniform1f Exposure;
|
||||
FBufferedUniformSampler ExposureTexture;
|
||||
FBufferedUniform2f Scale;
|
||||
FBufferedUniform2f Offset;
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ void FTonemapShader::Bind()
|
|||
shader.Link("shaders/glsl/tonemap");
|
||||
shader.SetAttribLocation(0, "PositionInProjection");
|
||||
SceneTexture.Init(shader, "InputTexture");
|
||||
Exposure.Init(shader, "ExposureAdjustment");
|
||||
ExposureTexture.Init(shader, "ExposureTexture");
|
||||
PaletteLUT.Init(shader, "PaletteLUT");
|
||||
}
|
||||
shader.Bind();
|
||||
|
@ -70,3 +70,51 @@ const char *FTonemapShader::GetDefines(int mode)
|
|||
case Palette: return "#define PALETTE\n";
|
||||
}
|
||||
}
|
||||
|
||||
void FExposureExtractShader::Bind()
|
||||
{
|
||||
if (!mShader)
|
||||
{
|
||||
mShader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
|
||||
mShader.Compile(FShaderProgram::Fragment, "shaders/glsl/exposureextract.fp", "", 330);
|
||||
mShader.SetFragDataLocation(0, "FragColor");
|
||||
mShader.Link("shaders/glsl/exposureextract");
|
||||
mShader.SetAttribLocation(0, "PositionInProjection");
|
||||
SceneTexture.Init(mShader, "SceneTexture");
|
||||
Scale.Init(mShader, "Scale");
|
||||
Offset.Init(mShader, "Offset");
|
||||
}
|
||||
mShader.Bind();
|
||||
}
|
||||
|
||||
void FExposureAverageShader::Bind()
|
||||
{
|
||||
if (!mShader)
|
||||
{
|
||||
mShader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 400);
|
||||
mShader.Compile(FShaderProgram::Fragment, "shaders/glsl/exposureaverage.fp", "", 400);
|
||||
mShader.SetFragDataLocation(0, "FragColor");
|
||||
mShader.Link("shaders/glsl/exposureaverage");
|
||||
mShader.SetAttribLocation(0, "PositionInProjection");
|
||||
ExposureTexture.Init(mShader, "ExposureTexture");
|
||||
}
|
||||
mShader.Bind();
|
||||
}
|
||||
|
||||
void FExposureCombineShader::Bind()
|
||||
{
|
||||
if (!mShader)
|
||||
{
|
||||
mShader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
|
||||
mShader.Compile(FShaderProgram::Fragment, "shaders/glsl/exposurecombine.fp", "", 330);
|
||||
mShader.SetFragDataLocation(0, "FragColor");
|
||||
mShader.Link("shaders/glsl/exposurecombine");
|
||||
mShader.SetAttribLocation(0, "PositionInProjection");
|
||||
ExposureTexture.Init(mShader, "ExposureTexture");
|
||||
ExposureBase.Init(mShader, "ExposureBase");
|
||||
ExposureMin.Init(mShader, "ExposureMin");
|
||||
ExposureScale.Init(mShader, "ExposureScale");
|
||||
ExposureSpeed.Init(mShader, "ExposureSpeed");
|
||||
}
|
||||
mShader.Bind();
|
||||
}
|
|
@ -9,7 +9,7 @@ public:
|
|||
void Bind();
|
||||
|
||||
FBufferedUniformSampler SceneTexture;
|
||||
FBufferedUniform1f Exposure;
|
||||
FBufferedUniformSampler ExposureTexture;
|
||||
FBufferedUniformSampler PaletteLUT;
|
||||
|
||||
static bool IsPaletteMode();
|
||||
|
@ -31,4 +31,43 @@ private:
|
|||
FShaderProgram mShader[NumTonemapModes];
|
||||
};
|
||||
|
||||
class FExposureExtractShader
|
||||
{
|
||||
public:
|
||||
void Bind();
|
||||
|
||||
FBufferedUniformSampler SceneTexture;
|
||||
FBufferedUniform2f Scale;
|
||||
FBufferedUniform2f Offset;
|
||||
|
||||
private:
|
||||
FShaderProgram mShader;
|
||||
};
|
||||
|
||||
class FExposureAverageShader
|
||||
{
|
||||
public:
|
||||
void Bind();
|
||||
|
||||
FBufferedUniformSampler ExposureTexture;
|
||||
|
||||
private:
|
||||
FShaderProgram mShader;
|
||||
};
|
||||
|
||||
class FExposureCombineShader
|
||||
{
|
||||
public:
|
||||
void Bind();
|
||||
|
||||
FBufferedUniformSampler ExposureTexture;
|
||||
FBufferedUniform1f ExposureBase;
|
||||
FBufferedUniform1f ExposureMin;
|
||||
FBufferedUniform1f ExposureScale;
|
||||
FBufferedUniform1f ExposureSpeed;
|
||||
|
||||
private:
|
||||
FShaderProgram mShader;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -3,12 +3,13 @@ in vec2 TexCoord;
|
|||
out vec4 FragColor;
|
||||
|
||||
uniform sampler2D SceneTexture;
|
||||
uniform float ExposureAdjustment;
|
||||
uniform sampler2D ExposureTexture;
|
||||
uniform vec2 Scale;
|
||||
uniform vec2 Offset;
|
||||
|
||||
void main()
|
||||
{
|
||||
float exposureAdjustment = texture(ExposureTexture, vec2(0.5)).x;
|
||||
vec4 color = texture(SceneTexture, Offset + TexCoord * Scale);
|
||||
FragColor = max(vec4(color.rgb * ExposureAdjustment - 1, 1), vec4(0));
|
||||
FragColor = max(vec4((color.rgb + vec3(0.001)) * exposureAdjustment - 1, 1), vec4(0));
|
||||
}
|
||||
|
|
23
wadsrc/static/shaders/glsl/exposureaverage.fp
Normal file
23
wadsrc/static/shaders/glsl/exposureaverage.fp
Normal file
|
@ -0,0 +1,23 @@
|
|||
|
||||
in vec2 TexCoord;
|
||||
out vec4 FragColor;
|
||||
|
||||
uniform sampler2D ExposureTexture;
|
||||
|
||||
void main()
|
||||
{
|
||||
#if __VERSION__ < 400
|
||||
ivec2 size = textureSize(ExposureTexture, 0);
|
||||
ivec2 tl = max(ivec2(TexCoord * vec2(size) - 0.5), ivec2(0));
|
||||
ivec2 br = min(tl + ivec2(1), size - ivec2(1));
|
||||
vec4 values = vec4(
|
||||
texelFetch(ExposureTexture, tl, 0).x,
|
||||
texelFetch(ExposureTexture, ivec2(tl.x, br.y), 0).x,
|
||||
texelFetch(ExposureTexture, ivec2(br.x, tl.y), 0).x,
|
||||
texelFetch(ExposureTexture, br, 0).x);
|
||||
#else
|
||||
vec4 values = textureGather(ExposureTexture, TexCoord);
|
||||
#endif
|
||||
|
||||
FragColor = vec4((values.x + values.y + values.z + values.w) * 0.25, 0.0, 0.0, 1.0);
|
||||
}
|
16
wadsrc/static/shaders/glsl/exposurecombine.fp
Normal file
16
wadsrc/static/shaders/glsl/exposurecombine.fp
Normal file
|
@ -0,0 +1,16 @@
|
|||
|
||||
in vec2 TexCoord;
|
||||
out vec4 FragColor;
|
||||
|
||||
uniform sampler2D ExposureTexture;
|
||||
uniform float ExposureBase;
|
||||
uniform float ExposureMin;
|
||||
uniform float ExposureScale;
|
||||
uniform float ExposureSpeed;
|
||||
|
||||
void main()
|
||||
{
|
||||
float light = texture(ExposureTexture, TexCoord).x;
|
||||
float exposureAdjustment = 1.0 / max(ExposureBase + light * ExposureScale, ExposureMin);
|
||||
FragColor = vec4(exposureAdjustment, 0.0, 0.0, ExposureSpeed);
|
||||
}
|
13
wadsrc/static/shaders/glsl/exposureextract.fp
Normal file
13
wadsrc/static/shaders/glsl/exposureextract.fp
Normal file
|
@ -0,0 +1,13 @@
|
|||
|
||||
in vec2 TexCoord;
|
||||
out vec4 FragColor;
|
||||
|
||||
uniform sampler2D SceneTexture;
|
||||
uniform vec2 Scale;
|
||||
uniform vec2 Offset;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = texture(SceneTexture, Offset + TexCoord * Scale);
|
||||
FragColor = vec4(max(max(color.r, color.g), color.b), 0.0, 0.0, 1.0);
|
||||
}
|
|
@ -3,7 +3,7 @@ in vec2 TexCoord;
|
|||
out vec4 FragColor;
|
||||
|
||||
uniform sampler2D InputTexture;
|
||||
uniform float ExposureAdjustment;
|
||||
uniform sampler2D ExposureTexture;
|
||||
|
||||
vec3 Linear(vec3 c)
|
||||
{
|
||||
|
@ -84,7 +84,8 @@ void main()
|
|||
{
|
||||
vec3 color = texture(InputTexture, TexCoord).rgb;
|
||||
#ifndef PALETTE
|
||||
color = color * ExposureAdjustment;
|
||||
float exposureAdjustment = texture(ExposureTexture, vec2(0.5)).x;
|
||||
color = color * exposureAdjustment;
|
||||
color = Linear(color); // needed because gzdoom's scene texture is not linear at the moment
|
||||
#endif
|
||||
FragColor = vec4(Tonemap(color), 1.0);
|
||||
|
|
Loading…
Reference in a new issue