- Move custom postprocess shader to its own file
This commit is contained in:
parent
1cfaae78d9
commit
8a0e801cb5
7 changed files with 237 additions and 156 deletions
|
|
@ -42,7 +42,6 @@
|
|||
#include "r_utility.h"
|
||||
#include "p_local.h"
|
||||
#include "colormatcher.h"
|
||||
#include "w_wad.h"
|
||||
#include "gl/gl_functions.h"
|
||||
#include "gl/system/gl_interface.h"
|
||||
#include "gl/system/gl_framebuffer.h"
|
||||
|
|
@ -63,6 +62,7 @@
|
|||
#include "gl/shaders/gl_lensshader.h"
|
||||
#include "gl/shaders/gl_fxaashader.h"
|
||||
#include "gl/shaders/gl_presentshader.h"
|
||||
#include "gl/shaders/gl_postprocessshader.h"
|
||||
#include "gl/renderer/gl_2ddrawer.h"
|
||||
#include "gl/stereo3d/gl_stereo3d.h"
|
||||
|
||||
|
|
@ -147,20 +147,9 @@ CUSTOM_CVAR(Bool, gl_paltonemap_reverselookup, true, CVAR_ARCHIVE | CVAR_NOINITC
|
|||
}
|
||||
|
||||
|
||||
CVAR(Bool, gl_custompost, true, 0)
|
||||
|
||||
EXTERN_CVAR(Float, vid_brightness)
|
||||
EXTERN_CVAR(Float, vid_contrast)
|
||||
|
||||
class PostProcessShaderInstance
|
||||
{
|
||||
public:
|
||||
FShaderProgram Program;
|
||||
FBufferedUniformSampler InputTexture;
|
||||
FBufferedUniformSampler CustomTexture;
|
||||
FHardwareTexture *HWTexture = nullptr;
|
||||
};
|
||||
|
||||
void FGLRenderer::RenderScreenQuad()
|
||||
{
|
||||
mVBO->BindVBO();
|
||||
|
|
@ -172,136 +161,15 @@ void FGLRenderer::PostProcessScene(int fixedcm)
|
|||
{
|
||||
mBuffers->BlitSceneToTexture();
|
||||
UpdateCameraExposure();
|
||||
mCustomPostProcessShaders->Run("beforebloom");
|
||||
BloomScene(fixedcm);
|
||||
TonemapScene();
|
||||
ColormapScene(fixedcm);
|
||||
LensDistortScene();
|
||||
ApplyFXAA();
|
||||
RunCustomPostProcessShaders("scene");
|
||||
mCustomPostProcessShaders->Run("scene");
|
||||
}
|
||||
|
||||
#include "vm.h"
|
||||
|
||||
DEFINE_ACTION_FUNCTION(_Shader, SetUniform1f)
|
||||
{
|
||||
PARAM_PROLOGUE;
|
||||
PARAM_STRING(shaderName);
|
||||
PARAM_STRING(uniformName);
|
||||
PARAM_FLOAT_DEF(value);
|
||||
|
||||
for (unsigned int i = 0; i < PostProcessShaders.Size(); i++)
|
||||
{
|
||||
PostProcessShader &shader = PostProcessShaders[i];
|
||||
if (shader.Name == shaderName)
|
||||
shader.Uniform1f[uniformName] = value;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(_Shader, SetUniform1i)
|
||||
{
|
||||
PARAM_PROLOGUE;
|
||||
PARAM_STRING(shaderName);
|
||||
PARAM_STRING(uniformName);
|
||||
PARAM_INT_DEF(value);
|
||||
|
||||
for (unsigned int i = 0; i < PostProcessShaders.Size(); i++)
|
||||
{
|
||||
PostProcessShader &shader = PostProcessShaders[i];
|
||||
if (shader.Name == shaderName)
|
||||
shader.Uniform1i[uniformName] = value;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void FGLRenderer::RunCustomPostProcessShaders(FString target)
|
||||
{
|
||||
if (!gl_custompost)
|
||||
return;
|
||||
|
||||
for (unsigned int i = 0; i < PostProcessShaders.Size(); i++)
|
||||
{
|
||||
PostProcessShader &shader = PostProcessShaders[i];
|
||||
|
||||
if (shader.Target != target)
|
||||
continue;
|
||||
|
||||
if (!shader.Instance)
|
||||
{
|
||||
const char *lumpName = shader.ShaderLumpName.GetChars();
|
||||
int lump = Wads.CheckNumForFullName(lumpName);
|
||||
if (lump == -1) I_FatalError("Unable to load '%s'", lumpName);
|
||||
FString code = Wads.ReadLump(lump).GetString().GetChars();
|
||||
|
||||
shader.Instance = std::make_shared<PostProcessShaderInstance>();
|
||||
shader.Instance->Program.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330); // Hmm, should this use shader.shaderversion?
|
||||
shader.Instance->Program.Compile(FShaderProgram::Fragment, lumpName, code, "", shader.ShaderVersion);
|
||||
shader.Instance->Program.SetFragDataLocation(0, "FragColor");
|
||||
shader.Instance->Program.Link(shader.ShaderLumpName.GetChars());
|
||||
shader.Instance->Program.SetAttribLocation(0, "PositionInProjection");
|
||||
shader.Instance->InputTexture.Init(shader.Instance->Program, "InputTexture");
|
||||
shader.Instance->CustomTexture.Init(shader.Instance->Program, "CustomTexture");
|
||||
|
||||
if (shader.Texture)
|
||||
{
|
||||
shader.Instance->HWTexture = new FHardwareTexture(shader.Texture->GetWidth(), shader.Texture->GetHeight(), false);
|
||||
shader.Instance->HWTexture->CreateTexture((unsigned char*)shader.Texture->GetPixelsBgra(), shader.Texture->GetWidth(), shader.Texture->GetHeight(), 0, false, 0, "CustomTexture");
|
||||
}
|
||||
}
|
||||
|
||||
FGLDebug::PushGroup(shader.ShaderLumpName.GetChars());
|
||||
|
||||
FGLPostProcessState savedState;
|
||||
savedState.SaveTextureBindings(2);
|
||||
|
||||
mBuffers->BindNextFB();
|
||||
mBuffers->BindCurrentTexture(0);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
shader.Instance->Program.Bind();
|
||||
|
||||
TMap<FString, float>::Iterator it1f(shader.Uniform1f);
|
||||
TMap<FString, float>::Pair *pair1f;
|
||||
while (it1f.NextPair(pair1f))
|
||||
{
|
||||
int location = glGetUniformLocation(shader.Instance->Program, pair1f->Key.GetChars());
|
||||
if (location != -1)
|
||||
glUniform1f(location, pair1f->Value);
|
||||
}
|
||||
|
||||
TMap<FString, int>::Iterator it1i(shader.Uniform1i);
|
||||
TMap<FString, int>::Pair *pair1i;
|
||||
while (it1i.NextPair(pair1i))
|
||||
{
|
||||
int location = glGetUniformLocation(shader.Instance->Program, pair1i->Key.GetChars());
|
||||
if (location != -1)
|
||||
glUniform1i(location, pair1i->Value);
|
||||
}
|
||||
|
||||
shader.Instance->InputTexture.Set(0);
|
||||
|
||||
if (shader.Instance->HWTexture)
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, shader.Instance->HWTexture->GetTextureHandle(0));
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
shader.Instance->CustomTexture.Set(1);
|
||||
}
|
||||
RenderScreenQuad();
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
mBuffers->NextTexture();
|
||||
|
||||
FGLDebug::PopGroup();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
|
|
@ -869,7 +737,7 @@ void FGLRenderer::CopyToBackbuffer(const GL_IRECT *bounds, bool applyGamma)
|
|||
m2DDrawer->Draw(); // draw all pending 2D stuff before copying the buffer
|
||||
m2DDrawer->Clear();
|
||||
|
||||
RunCustomPostProcessShaders("screen");
|
||||
mCustomPostProcessShaders->Run("screen");
|
||||
|
||||
FGLDebug::PushGroup("CopyToBackbuffer");
|
||||
if (FGLRenderBuffers::IsEnabled())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue