Reorganize code
This commit is contained in:
BIN
Content/Shaders/PostProcessing.flax
(Stored with Git LFS)
BIN
Content/Shaders/PostProcessing.flax
(Stored with Git LFS)
Binary file not shown.
@@ -9,19 +9,61 @@
|
|||||||
#include "Engine/Graphics/RenderTargetPool.h"
|
#include "Engine/Graphics/RenderTargetPool.h"
|
||||||
#include "Engine/Engine/Time.h"
|
#include "Engine/Engine/Time.h"
|
||||||
|
|
||||||
PostProcessingPass::PostProcessingPass()
|
#define GB_RADIUS 6
|
||||||
: _shader(nullptr)
|
#define GB_KERNEL_SIZE (GB_RADIUS * 2 + 1)
|
||||||
, _psBloomBrightPass(nullptr)
|
|
||||||
, _psBloomDownsample(nullptr)
|
GPU_CB_STRUCT(Data{
|
||||||
, _psBloomDualFilterUpsample(nullptr)
|
float BloomIntensity; // Overall bloom strength multiplier
|
||||||
, _psBlurH(nullptr)
|
float BloomClamp; // Maximum brightness limit for bloom
|
||||||
, _psBlurV(nullptr)
|
float BloomThreshold; // Luminance threshold where bloom begins
|
||||||
, _psGenGhosts(nullptr)
|
float BloomThresholdKnee; // Controls the threshold rolloff curve
|
||||||
, _defaultLensColor(nullptr)
|
|
||||||
, _defaultLensStar(nullptr)
|
float BloomBaseMix; // Base mip contribution
|
||||||
, _defaultLensDirt(nullptr)
|
float BloomHighMix; // High mip contribution
|
||||||
{
|
float BloomMipCount;
|
||||||
}
|
float BloomLayer;
|
||||||
|
|
||||||
|
Float3 VignetteColor;
|
||||||
|
float VignetteShapeFactor;
|
||||||
|
|
||||||
|
Float2 InputSize;
|
||||||
|
float InputAspect;
|
||||||
|
float GrainAmount;
|
||||||
|
|
||||||
|
float GrainTime;
|
||||||
|
float GrainParticleSize;
|
||||||
|
int32 Ghosts;
|
||||||
|
float HaloWidth;
|
||||||
|
|
||||||
|
float HaloIntensity;
|
||||||
|
float Distortion;
|
||||||
|
float GhostDispersal;
|
||||||
|
float LensFlareIntensity;
|
||||||
|
|
||||||
|
Float2 LensInputDistortion;
|
||||||
|
float LensScale;
|
||||||
|
float LensBias;
|
||||||
|
|
||||||
|
Float2 InvInputSize;
|
||||||
|
float ChromaticDistortion;
|
||||||
|
float Time;
|
||||||
|
|
||||||
|
float Dummy1;
|
||||||
|
float PostExposure;
|
||||||
|
float VignetteIntensity;
|
||||||
|
float LensDirtIntensity;
|
||||||
|
|
||||||
|
Color ScreenFadeColor;
|
||||||
|
|
||||||
|
Matrix LensFlareStarMat;
|
||||||
|
});
|
||||||
|
|
||||||
|
GPU_CB_STRUCT(GaussianBlurData{
|
||||||
|
Float2 Size;
|
||||||
|
float Dummy3;
|
||||||
|
float Dummy4;
|
||||||
|
Float4 GaussianBlurCache[GB_KERNEL_SIZE]; // x-weight, y-offset
|
||||||
|
});
|
||||||
|
|
||||||
String PostProcessingPass::ToString() const
|
String PostProcessingPass::ToString() const
|
||||||
{
|
{
|
||||||
@@ -116,7 +158,7 @@ bool PostProcessingPass::setupResources()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
GPUTexture* PostProcessingPass::getCustomOrDefault(Texture* customTexture, AssetReference<Texture>& defaultTexture, const Char* defaultName)
|
GPUTexture* GetCustomOrDefault(Texture* customTexture, AssetReference<Texture>& defaultTexture, const Char* defaultName)
|
||||||
{
|
{
|
||||||
// Check if use custom texture
|
// Check if use custom texture
|
||||||
if (customTexture)
|
if (customTexture)
|
||||||
@@ -133,7 +175,15 @@ GPUTexture* PostProcessingPass::getCustomOrDefault(Texture* customTexture, Asset
|
|||||||
return defaultTexture ? defaultTexture->GetTexture() : nullptr;
|
return defaultTexture ? defaultTexture->GetTexture() : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PostProcessingPass::GB_ComputeKernel(float sigma, float width, float height)
|
/// <summary>
|
||||||
|
/// Calculates the Gaussian blur filter kernel. This implementation is
|
||||||
|
/// ported from the original Java code appearing in chapter 16 of
|
||||||
|
/// "Filthy Rich Clients: Developing Animated and Graphical Effects for Desktop Java".
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sigma">Gaussian Blur sigma parameter</param>
|
||||||
|
/// <param name="width">Texture to blur width in pixels</param>
|
||||||
|
/// <param name="height">Texture to blur height in pixels</param>
|
||||||
|
void GB_ComputeKernel(float sigma, float width, float height, Float4 gaussianBlurCacheH[GB_KERNEL_SIZE], Float4 gaussianBlurCacheV[GB_KERNEL_SIZE])
|
||||||
{
|
{
|
||||||
float total = 0.0f;
|
float total = 0.0f;
|
||||||
float twoSigmaSquare = 2.0f * sigma * sigma;
|
float twoSigmaSquare = 2.0f * sigma * sigma;
|
||||||
@@ -154,19 +204,16 @@ void PostProcessingPass::GB_ComputeKernel(float sigma, float width, float height
|
|||||||
// Calculate total weights sum
|
// Calculate total weights sum
|
||||||
total += weight;
|
total += weight;
|
||||||
|
|
||||||
GaussianBlurCacheH[index] = Float4(weight, i * xOffset, 0, 0);
|
gaussianBlurCacheH[index] = Float4(weight, i * xOffset, 0, 0);
|
||||||
GaussianBlurCacheV[index] = Float4(weight, i * yOffset, 0, 0);
|
gaussianBlurCacheV[index] = Float4(weight, i * yOffset, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normalize weights
|
// Normalize weights
|
||||||
for (int32 i = 0; i < GB_KERNEL_SIZE; i++)
|
for (int32 i = 0; i < GB_KERNEL_SIZE; i++)
|
||||||
{
|
{
|
||||||
GaussianBlurCacheH[i].X /= total;
|
gaussianBlurCacheH[i].X /= total;
|
||||||
GaussianBlurCacheV[i].X /= total;
|
gaussianBlurCacheV[i].X /= total;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assign size
|
|
||||||
_gbData.Size = Float2(width, height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PostProcessingPass::Dispose()
|
void PostProcessingPass::Dispose()
|
||||||
@@ -405,8 +452,8 @@ void PostProcessingPass::Render(RenderContext& renderContext, GPUTexture* input,
|
|||||||
if (useLensFlares)
|
if (useLensFlares)
|
||||||
{
|
{
|
||||||
// Prepare lens flares helper textures
|
// Prepare lens flares helper textures
|
||||||
context->BindSR(5, getCustomOrDefault(settings.LensFlares.LensStar, _defaultLensStar, TEXT("Engine/Textures/DefaultLensStarburst")));
|
context->BindSR(5, GetCustomOrDefault(settings.LensFlares.LensStar, _defaultLensStar, TEXT("Engine/Textures/DefaultLensStarburst")));
|
||||||
context->BindSR(6, getCustomOrDefault(settings.LensFlares.LensColor, _defaultLensColor, TEXT("Engine/Textures/DefaultLensColor")));
|
context->BindSR(6, GetCustomOrDefault(settings.LensFlares.LensColor, _defaultLensColor, TEXT("Engine/Textures/DefaultLensColor")));
|
||||||
|
|
||||||
// Render lens flares
|
// Render lens flares
|
||||||
context->SetRenderTarget(bloomBuffer2->View(0, 1));
|
context->SetRenderTarget(bloomBuffer2->View(0, 1));
|
||||||
@@ -418,11 +465,15 @@ void PostProcessingPass::Render(RenderContext& renderContext, GPUTexture* input,
|
|||||||
context->UnBindSR(3);
|
context->UnBindSR(3);
|
||||||
|
|
||||||
// Gaussian blur kernel
|
// Gaussian blur kernel
|
||||||
GB_ComputeKernel(2.0f, static_cast<float>(w4), static_cast<float>(h4));
|
GaussianBlurData gbData;
|
||||||
|
Float4 GaussianBlurCacheH[GB_KERNEL_SIZE];
|
||||||
|
Float4 GaussianBlurCacheV[GB_KERNEL_SIZE];
|
||||||
|
gbData.Size = Float2(static_cast<float>(w4), static_cast<float>(h4));
|
||||||
|
GB_ComputeKernel(2.0f, gbData.Size.X, gbData.Size.Y, GaussianBlurCacheH, GaussianBlurCacheV);
|
||||||
|
|
||||||
// Gaussian blur H
|
// Gaussian blur H
|
||||||
Platform::MemoryCopy(_gbData.GaussianBlurCache, GaussianBlurCacheH, sizeof(GaussianBlurCacheH));
|
Platform::MemoryCopy(gbData.GaussianBlurCache, GaussianBlurCacheH, sizeof(GaussianBlurCacheH));
|
||||||
context->UpdateCB(cb1, &_gbData);
|
context->UpdateCB(cb1, &gbData);
|
||||||
context->BindCB(1, cb1);
|
context->BindCB(1, cb1);
|
||||||
context->SetRenderTarget(bloomBuffer1->View(0, 1));
|
context->SetRenderTarget(bloomBuffer1->View(0, 1));
|
||||||
context->BindSR(0, bloomBuffer2->View(0, 1));
|
context->BindSR(0, bloomBuffer2->View(0, 1));
|
||||||
@@ -431,8 +482,8 @@ void PostProcessingPass::Render(RenderContext& renderContext, GPUTexture* input,
|
|||||||
context->ResetRenderTarget();
|
context->ResetRenderTarget();
|
||||||
|
|
||||||
// Gaussian blur V
|
// Gaussian blur V
|
||||||
Platform::MemoryCopy(_gbData.GaussianBlurCache, GaussianBlurCacheV, sizeof(GaussianBlurCacheV));
|
Platform::MemoryCopy(gbData.GaussianBlurCache, GaussianBlurCacheV, sizeof(GaussianBlurCacheV));
|
||||||
context->UpdateCB(cb1, &_gbData);
|
context->UpdateCB(cb1, &gbData);
|
||||||
context->BindCB(1, cb1);
|
context->BindCB(1, cb1);
|
||||||
context->SetRenderTarget(bloomBuffer2->View(0, 1));
|
context->SetRenderTarget(bloomBuffer2->View(0, 1));
|
||||||
context->BindSR(0, bloomBuffer1->View(0, 1));
|
context->BindSR(0, bloomBuffer1->View(0, 1));
|
||||||
@@ -481,7 +532,7 @@ void PostProcessingPass::Render(RenderContext& renderContext, GPUTexture* input,
|
|||||||
// - 5 - LensStar - lens star texture
|
// - 5 - LensStar - lens star texture
|
||||||
// - 7 - ColorGradingLUT
|
// - 7 - ColorGradingLUT
|
||||||
context->BindSR(0, input->View());
|
context->BindSR(0, input->View());
|
||||||
context->BindSR(4, getCustomOrDefault(settings.LensFlares.LensDirt, _defaultLensDirt, TEXT("Engine/Textures/DefaultLensDirt")));
|
context->BindSR(4, GetCustomOrDefault(settings.LensFlares.LensDirt, _defaultLensDirt, TEXT("Engine/Textures/DefaultLensDirt")));
|
||||||
context->BindSR(7, colorGradingLutView);
|
context->BindSR(7, colorGradingLutView);
|
||||||
|
|
||||||
// Composite final frame during single pass (done in full resolution)
|
// Composite final frame during single pass (done in full resolution)
|
||||||
|
|||||||
@@ -5,96 +5,25 @@
|
|||||||
#include "RendererPass.h"
|
#include "RendererPass.h"
|
||||||
#include "Engine/Graphics/GPUPipelineStatePermutations.h"
|
#include "Engine/Graphics/GPUPipelineStatePermutations.h"
|
||||||
|
|
||||||
#define GB_RADIUS 6
|
|
||||||
#define GB_KERNEL_SIZE (GB_RADIUS * 2 + 1)
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Post processing rendering service
|
/// Post-processing rendering service.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class PostProcessingPass : public RendererPass<PostProcessingPass>
|
class PostProcessingPass : public RendererPass<PostProcessingPass>
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
||||||
GPU_CB_STRUCT(Data{
|
|
||||||
float BloomIntensity; // Overall bloom strength multiplier
|
|
||||||
float BloomClamp; // Maximum brightness limit for bloom
|
|
||||||
float BloomThreshold; // Luminance threshold where bloom begins
|
|
||||||
float BloomThresholdKnee; // Controls the threshold rolloff curve
|
|
||||||
|
|
||||||
float BloomBaseMix; // Base mip contribution
|
|
||||||
float BloomHighMix; // High mip contribution
|
|
||||||
float BloomMipCount;
|
|
||||||
float BloomLayer;
|
|
||||||
|
|
||||||
Float3 VignetteColor;
|
|
||||||
float VignetteShapeFactor;
|
|
||||||
|
|
||||||
Float2 InputSize;
|
|
||||||
float InputAspect;
|
|
||||||
float GrainAmount;
|
|
||||||
|
|
||||||
float GrainTime;
|
|
||||||
float GrainParticleSize;
|
|
||||||
int32 Ghosts;
|
|
||||||
float HaloWidth;
|
|
||||||
|
|
||||||
float HaloIntensity;
|
|
||||||
float Distortion;
|
|
||||||
float GhostDispersal;
|
|
||||||
float LensFlareIntensity;
|
|
||||||
|
|
||||||
Float2 LensInputDistortion;
|
|
||||||
float LensScale;
|
|
||||||
float LensBias;
|
|
||||||
|
|
||||||
Float2 InvInputSize;
|
|
||||||
float ChromaticDistortion;
|
|
||||||
float Time;
|
|
||||||
|
|
||||||
float Dummy1;
|
|
||||||
float PostExposure;
|
|
||||||
float VignetteIntensity;
|
|
||||||
float LensDirtIntensity;
|
|
||||||
|
|
||||||
Color ScreenFadeColor;
|
|
||||||
|
|
||||||
Matrix LensFlareStarMat;
|
|
||||||
});
|
|
||||||
|
|
||||||
GPU_CB_STRUCT(GaussianBlurData{
|
|
||||||
Float2 Size;
|
|
||||||
float Dummy3;
|
|
||||||
float Dummy4;
|
|
||||||
Float4 GaussianBlurCache[GB_KERNEL_SIZE]; // x-weight, y-offset
|
|
||||||
});
|
|
||||||
|
|
||||||
// Post Processing
|
|
||||||
AssetReference<Shader> _shader;
|
AssetReference<Shader> _shader;
|
||||||
GPUPipelineState* _psBloomBrightPass;
|
GPUPipelineState* _psBloomBrightPass = nullptr;
|
||||||
GPUPipelineState* _psBloomDownsample;
|
GPUPipelineState* _psBloomDownsample = nullptr;
|
||||||
GPUPipelineState* _psBloomDualFilterUpsample;
|
GPUPipelineState* _psBloomDualFilterUpsample = nullptr;
|
||||||
GPUPipelineState* _psBlurH;
|
GPUPipelineState* _psBlurH = nullptr;
|
||||||
GPUPipelineState* _psBlurV;
|
GPUPipelineState* _psBlurV = nullptr;
|
||||||
GPUPipelineState* _psGenGhosts;
|
GPUPipelineState* _psGenGhosts = nullptr;
|
||||||
GPUPipelineStatePermutationsPs<3> _psComposite;
|
GPUPipelineStatePermutationsPs<3> _psComposite;
|
||||||
|
|
||||||
GaussianBlurData _gbData;
|
|
||||||
Float4 GaussianBlurCacheH[GB_KERNEL_SIZE];
|
|
||||||
Float4 GaussianBlurCacheV[GB_KERNEL_SIZE];
|
|
||||||
|
|
||||||
AssetReference<Texture> _defaultLensColor;
|
AssetReference<Texture> _defaultLensColor;
|
||||||
AssetReference<Texture> _defaultLensStar;
|
AssetReference<Texture> _defaultLensStar;
|
||||||
AssetReference<Texture> _defaultLensDirt;
|
AssetReference<Texture> _defaultLensDirt;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Init
|
|
||||||
/// </summary>
|
|
||||||
PostProcessingPass();
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Perform postFx rendering for the input task
|
/// Perform postFx rendering for the input task
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -105,19 +34,6 @@ public:
|
|||||||
void Render(RenderContext& renderContext, GPUTexture* input, GPUTexture* output, GPUTexture* colorGradingLUT);
|
void Render(RenderContext& renderContext, GPUTexture* input, GPUTexture* output, GPUTexture* colorGradingLUT);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
GPUTexture* getCustomOrDefault(Texture* customTexture, AssetReference<Texture>& defaultTexture, const Char* defaultName);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Calculates the Gaussian blur filter kernel. This implementation is
|
|
||||||
/// ported from the original Java code appearing in chapter 16 of
|
|
||||||
/// "Filthy Rich Clients: Developing Animated and Graphical Effects for Desktop Java".
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sigma">Gaussian Blur sigma parameter</param>
|
|
||||||
/// <param name="width">Texture to blur width in pixels</param>
|
|
||||||
/// <param name="height">Texture to blur height in pixels</param>
|
|
||||||
void GB_ComputeKernel(float sigma, float width, float height);
|
|
||||||
|
|
||||||
#if COMPILE_WITH_DEV_ENV
|
#if COMPILE_WITH_DEV_ENV
|
||||||
void OnShaderReloading(Asset* obj)
|
void OnShaderReloading(Asset* obj)
|
||||||
{
|
{
|
||||||
@@ -133,14 +49,12 @@ private:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// [RendererPass]
|
// [RendererPass]
|
||||||
String ToString() const override;
|
String ToString() const override;
|
||||||
bool Init() override;
|
bool Init() override;
|
||||||
void Dispose() override;
|
void Dispose() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// [RendererPass]
|
// [RendererPass]
|
||||||
bool setupResources() override;
|
bool setupResources() override;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user