mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-28 15:02:01 +00:00
- add some helper functions
This commit is contained in:
parent
da5ecf1e5b
commit
684a97f300
2 changed files with 111 additions and 81 deletions
|
@ -2,28 +2,15 @@
|
|||
#include "v_video.h"
|
||||
#include "hw_postprocess.h"
|
||||
#include "hwrenderer/utility/hw_cvars.h"
|
||||
#include "gl_load/gl_load.h" // for GL_RGBA16F - should we create our own enum instead?
|
||||
|
||||
Postprocess hw_postprocess;
|
||||
|
||||
void PPBloom::DeclareShaders()
|
||||
{
|
||||
PPShader shader;
|
||||
shader.VertexShader = "shaders/glsl/screenquad.vp";
|
||||
shader.FragmentShader = "shaders/glsl/bloomcombine.fp";
|
||||
hw_postprocess.Shaders["BloomCombine"] = shader;
|
||||
|
||||
shader.Uniforms = ExtractUniforms::Desc();
|
||||
shader.FragmentShader = "shaders/glsl/bloomextract.fp";
|
||||
hw_postprocess.Shaders["BloomExtract"] = shader;
|
||||
|
||||
shader.Uniforms = BlurUniforms::Desc();
|
||||
shader.FragmentShader = "shaders/glsl/blur.fp";
|
||||
shader.Defines = "#define BLUR_VERTICAL\n";
|
||||
hw_postprocess.Shaders["BlurVertical"] = shader;
|
||||
|
||||
shader.Defines = "#define BLUR_HORIZONTAL\n";
|
||||
hw_postprocess.Shaders["BlurHorizontal"] = shader;
|
||||
hw_postprocess.Shaders["BloomCombine"] = { "shaders/glsl/bloomcombine.fp", "", {} };
|
||||
hw_postprocess.Shaders["BloomExtract"] = { "shaders/glsl/bloomextract.fp", "", ExtractUniforms::Desc() };
|
||||
hw_postprocess.Shaders["BlurVertical"] = { "shaders/glsl/blur.fp", "#define BLUR_VERTICAL\n", BlurUniforms::Desc() };
|
||||
hw_postprocess.Shaders["BlurHorizontal"] = { "shaders/glsl/blur.fp", "#define BLUR_HORIZONTAL\n", BlurUniforms::Desc() };
|
||||
}
|
||||
|
||||
void PPBloom::UpdateTextures(int width, int height)
|
||||
|
@ -47,11 +34,7 @@ void PPBloom::UpdateTextures(int width, int height)
|
|||
level.Viewport.width = (bloomWidth + 1) / 2;
|
||||
level.Viewport.height = (bloomHeight + 1) / 2;
|
||||
|
||||
PPTextureDesc texture;
|
||||
texture.Width = level.Viewport.width;
|
||||
texture.Height = level.Viewport.height;
|
||||
texture.Format = GL_RGBA16F;
|
||||
|
||||
PPTextureDesc texture = { level.Viewport.width, level.Viewport.height, PixelFormat::Rgba16f };
|
||||
hw_postprocess.Textures[vtexture] = texture;
|
||||
hw_postprocess.Textures[htexture] = texture;
|
||||
|
||||
|
@ -72,7 +55,6 @@ void PPBloom::UpdateSteps(int fixedcm)
|
|||
}
|
||||
|
||||
PPStep step;
|
||||
step.Textures.Resize(1);
|
||||
|
||||
ExtractUniforms extractUniforms;
|
||||
extractUniforms.Scale = screen->SceneScale();
|
||||
|
@ -82,15 +64,11 @@ void PPBloom::UpdateSteps(int fixedcm)
|
|||
|
||||
// Extract blooming pixels from scene texture:
|
||||
step.Viewport = level0.Viewport;
|
||||
step.Textures[0].Type = PPTextureType::CurrentPipelineTexture;
|
||||
step.Textures[0].Filter = PPFilterMode::Linear;
|
||||
step.SetInputCurrent(0, PPFilterMode::Linear);
|
||||
step.ShaderName = "BloomExtract";
|
||||
step.Uniforms.Set(extractUniforms);
|
||||
step.Output.Type = PPTextureType::PPTexture;
|
||||
step.Output.Texture = level0.VTexture;
|
||||
step.BlendMode.BlendOp = STYLEOP_Add;
|
||||
step.BlendMode.SrcAlpha = STYLEALPHA_One;
|
||||
step.BlendMode.DestAlpha = STYLEALPHA_Zero;
|
||||
step.SetOutputTexture(level0.VTexture);
|
||||
step.SetDisabledBlend();
|
||||
steps.Push(step);
|
||||
|
||||
const float blurAmount = gl_bloom_amount;
|
||||
|
@ -116,10 +94,8 @@ void PPBloom::UpdateSteps(int fixedcm)
|
|||
steps.Push(BlurStep(blurUniforms, level.HTexture, level.VTexture, level.Viewport, true));
|
||||
|
||||
// Linear upscale:
|
||||
step.Textures[0].Type = PPTextureType::PPTexture;
|
||||
step.Textures[0].Filter = PPFilterMode::Linear;
|
||||
step.Textures[0].Texture = next.VTexture;
|
||||
step.Output.Texture = next.HTexture;
|
||||
step.SetInputTexture(0, next.VTexture, PPFilterMode::Linear);
|
||||
step.SetOutputTexture(next.HTexture);
|
||||
step.Viewport = next.Viewport;
|
||||
step.ShaderName = "BloomCombine";
|
||||
steps.Push(step);
|
||||
|
@ -129,16 +105,11 @@ void PPBloom::UpdateSteps(int fixedcm)
|
|||
steps.Push(BlurStep(blurUniforms, level0.HTexture, level0.VTexture, level0.Viewport, true));
|
||||
|
||||
// Add bloom back to scene texture:
|
||||
step.Textures[0].Type = PPTextureType::PPTexture;
|
||||
step.Textures[0].Filter = PPFilterMode::Linear;
|
||||
step.Textures[0].Texture = level0.VTexture;
|
||||
step.Output.Type = PPTextureType::CurrentPipelineTexture;
|
||||
step.SetInputTexture(0, level0.VTexture, PPFilterMode::Linear);
|
||||
step.SetOutputCurrent();
|
||||
step.Viewport = screen->mSceneViewport;
|
||||
step.ShaderName = "BloomCombine";
|
||||
step.BlendMode.BlendOp = STYLEOP_Add;
|
||||
step.BlendMode.SrcAlpha = STYLEALPHA_One;
|
||||
step.BlendMode.DestAlpha = STYLEALPHA_One;
|
||||
step.BlendMode.Flags = 0;
|
||||
step.SetAdditiveBlend();
|
||||
steps.Push(step);
|
||||
|
||||
hw_postprocess.Effects["BloomScene"] = steps;
|
||||
|
@ -147,19 +118,12 @@ void PPBloom::UpdateSteps(int fixedcm)
|
|||
PPStep PPBloom::BlurStep(const BlurUniforms &blurUniforms, PPTextureName input, PPTextureName output, PPViewport viewport, bool vertical)
|
||||
{
|
||||
PPStep step;
|
||||
step.Textures.Resize(1);
|
||||
step.Viewport = viewport;
|
||||
step.Textures[0].Type = PPTextureType::PPTexture;
|
||||
step.Textures[0].Filter = PPFilterMode::Nearest;
|
||||
step.Textures[0].Texture = input;
|
||||
step.SetInputTexture(0, input);
|
||||
step.ShaderName = vertical ? "BlurVertical" : "BlurHorizontal";
|
||||
step.Uniforms.Set(blurUniforms);
|
||||
step.Output.Type = PPTextureType::PPTexture;
|
||||
step.Output.Texture = output;
|
||||
step.BlendMode.BlendOp = STYLEOP_Add;
|
||||
step.BlendMode.SrcAlpha = STYLEALPHA_One;
|
||||
step.BlendMode.DestAlpha = STYLEALPHA_Zero;
|
||||
step.BlendMode.Flags = 0;
|
||||
step.SetOutputTexture(output);
|
||||
step.SetDisabledBlend();
|
||||
return step;
|
||||
}
|
||||
|
||||
|
|
|
@ -91,6 +91,60 @@ public:
|
|||
class PPStep
|
||||
{
|
||||
public:
|
||||
void SetInputTexture(int index, PPTextureName texture, PPFilterMode filter = PPFilterMode::Nearest)
|
||||
{
|
||||
if ((int)Textures.Size() < index)
|
||||
Textures.Resize(index + 1);
|
||||
auto &tex = Textures[index];
|
||||
tex.Filter = filter;
|
||||
tex.Type = PPTextureType::PPTexture;
|
||||
tex.Texture = texture;
|
||||
}
|
||||
|
||||
void SetInputCurrent(int index, PPFilterMode filter = PPFilterMode::Nearest)
|
||||
{
|
||||
if ((int)Textures.Size() < index)
|
||||
Textures.Resize(index + 1);
|
||||
auto &tex = Textures[index];
|
||||
tex.Filter = filter;
|
||||
tex.Type = PPTextureType::CurrentPipelineTexture;
|
||||
tex.Texture = {};
|
||||
}
|
||||
|
||||
void SetOutputTexture(PPTextureName texture)
|
||||
{
|
||||
Output.Type = PPTextureType::PPTexture;
|
||||
Output.Texture = texture;
|
||||
}
|
||||
|
||||
void SetOutputCurrent()
|
||||
{
|
||||
Output.Type = PPTextureType::CurrentPipelineTexture;
|
||||
Output.Texture = {};
|
||||
}
|
||||
|
||||
void SetOutputNext()
|
||||
{
|
||||
Output.Type = PPTextureType::NextPipelineTexture;
|
||||
Output.Texture = {};
|
||||
}
|
||||
|
||||
void SetDisabledBlend()
|
||||
{
|
||||
BlendMode.BlendOp = STYLEOP_Add;
|
||||
BlendMode.SrcAlpha = STYLEALPHA_One;
|
||||
BlendMode.DestAlpha = STYLEALPHA_Zero;
|
||||
BlendMode.Flags = 0;
|
||||
}
|
||||
|
||||
void SetAdditiveBlend()
|
||||
{
|
||||
BlendMode.BlendOp = STYLEOP_Add;
|
||||
BlendMode.SrcAlpha = STYLEALPHA_One;
|
||||
BlendMode.DestAlpha = STYLEALPHA_One;
|
||||
BlendMode.Flags = 0;
|
||||
}
|
||||
|
||||
PPShaderName ShaderName;
|
||||
TArray<PPTextureInput> Textures;
|
||||
PPUniforms Uniforms;
|
||||
|
@ -99,6 +153,47 @@ public:
|
|||
PPOutput Output;
|
||||
};
|
||||
|
||||
enum class PixelFormat
|
||||
{
|
||||
Rgba8,
|
||||
Rgba16f
|
||||
};
|
||||
|
||||
class PPTextureDesc
|
||||
{
|
||||
public:
|
||||
PPTextureDesc() { }
|
||||
PPTextureDesc(int width, int height, PixelFormat format) : Width(width), Height(height), Format(format) { }
|
||||
|
||||
int Width;
|
||||
int Height;
|
||||
PixelFormat Format;
|
||||
};
|
||||
|
||||
class PPShader
|
||||
{
|
||||
public:
|
||||
PPShader() { }
|
||||
PPShader(const FString &fragment, const FString &defines, const std::vector<UniformFieldDesc> &uniforms) : FragmentShader(fragment), Defines(defines), Uniforms(uniforms) { }
|
||||
|
||||
FString VertexShader = "shaders/glsl/screenquad.vp";
|
||||
FString FragmentShader;
|
||||
FString Defines;
|
||||
std::vector<UniformFieldDesc> Uniforms;
|
||||
};
|
||||
|
||||
class Postprocess
|
||||
{
|
||||
public:
|
||||
TMap<FString, TArray<PPStep>> Effects;
|
||||
TMap<FString, PPTextureDesc> Textures;
|
||||
TMap<FString, PPShader> Shaders;
|
||||
};
|
||||
|
||||
extern Postprocess hw_postprocess;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct ExtractUniforms
|
||||
{
|
||||
FVector2 Scale;
|
||||
|
@ -134,35 +229,6 @@ struct BlurUniforms
|
|||
}
|
||||
};
|
||||
|
||||
class PPTextureDesc
|
||||
{
|
||||
public:
|
||||
int Width;
|
||||
int Height;
|
||||
int Format;
|
||||
};
|
||||
|
||||
class PPShader
|
||||
{
|
||||
public:
|
||||
FString VertexShader;
|
||||
FString FragmentShader;
|
||||
FString Defines;
|
||||
std::vector<UniformFieldDesc> Uniforms;
|
||||
};
|
||||
|
||||
class Postprocess
|
||||
{
|
||||
public:
|
||||
TMap<FString, TArray<PPStep>> Effects;
|
||||
TMap<FString, PPTextureDesc> Textures;
|
||||
TMap<FString, PPShader> Shaders;
|
||||
};
|
||||
|
||||
extern Postprocess hw_postprocess;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum { NumBloomLevels = 4 };
|
||||
|
||||
class PPBlurLevel
|
||||
|
|
Loading…
Reference in a new issue