mirror of
https://github.com/barkeser2002/flower.git
synced 2026-09-25 14:56:14 +03:00
141 lines
6.3 KiB
C++
141 lines
6.3 KiB
C++
#pragma once
|
|
#include <rhi/rhi.h>
|
|
#include <util/util.h>
|
|
|
|
namespace engine
|
|
{
|
|
// 128 * 128 blue noise.
|
|
struct TemporalBlueNoise : NonCopyable
|
|
{
|
|
struct BufferMisc
|
|
{
|
|
// The Sobol sequence buffer.
|
|
std::unique_ptr<VulkanBuffer> sobolBuffer = nullptr;
|
|
|
|
// The ranking tile buffer for sampling.
|
|
std::unique_ptr<VulkanBuffer> rankingTileBuffer = nullptr;
|
|
|
|
// The scrambling tile buffer for sampling.
|
|
std::unique_ptr<VulkanBuffer> scramblingTileBuffer = nullptr;
|
|
|
|
VkDescriptorSet set;
|
|
VkDescriptorSetLayout setLayouts;
|
|
|
|
void buildSet();
|
|
};
|
|
|
|
BufferMisc spp_1_buffer;
|
|
BufferMisc spp_2_buffer;
|
|
BufferMisc spp_4_buffer;
|
|
BufferMisc spp_8_buffer;
|
|
BufferMisc spp_16_buffer;
|
|
BufferMisc spp_32_buffer;
|
|
BufferMisc spp_64_buffer;
|
|
BufferMisc spp_128_buffer;
|
|
BufferMisc spp_256_buffer;
|
|
|
|
explicit TemporalBlueNoise();
|
|
};
|
|
|
|
class SharedTextures : NonCopyable
|
|
{
|
|
public:
|
|
std::unique_ptr<VulkanImage> brdfLut = nullptr;
|
|
std::unique_ptr<VulkanImage> cloudBasicNoise = nullptr;
|
|
std::unique_ptr<VulkanImage> cloudDetailNoise = nullptr;
|
|
|
|
explicit SharedTextures();
|
|
|
|
private:
|
|
void compute(VkCommandBuffer cmd);
|
|
};
|
|
|
|
struct AtmosphereTextures
|
|
{
|
|
PoolImageSharedRef transmittance = nullptr;
|
|
PoolImageSharedRef skyView = nullptr;
|
|
PoolImageSharedRef multiScatter = nullptr;
|
|
PoolImageSharedRef froxelScatter = nullptr;
|
|
PoolImageSharedRef envCapture = nullptr;
|
|
|
|
bool isValid()
|
|
{
|
|
return
|
|
transmittance != nullptr &&
|
|
skyView != nullptr &&
|
|
multiScatter != nullptr &&
|
|
froxelScatter != nullptr &&
|
|
envCapture != nullptr;
|
|
}
|
|
};
|
|
|
|
class GBufferTextures
|
|
{
|
|
public:
|
|
static GBufferTextures build(class RendererInterface* renderer, VulkanContext* context);
|
|
void clearValue(VkCommandBuffer graphicsCmd);
|
|
|
|
// Id of submesh, used for editor pick select or temporal reproject.
|
|
PoolImageSharedRef idTexture = nullptr;
|
|
inline static auto getIdTextureFormat() { return VK_FORMAT_R32_UINT; }
|
|
|
|
PoolImageSharedRef selectionOutlineMask = nullptr;
|
|
inline static auto gbufferSelectionOutlineMaskFormat() { return VK_FORMAT_R8_UNORM; }
|
|
|
|
PoolImageSharedRef hdrSceneColor = nullptr; // R16G16B16A16
|
|
PoolImageSharedRef hdrSceneColorUpscale = nullptr;
|
|
inline static auto hdrSceneColorFormat() { return VK_FORMAT_R16G16B16A16_SFLOAT; }
|
|
PoolImageSharedRef depthTexture = nullptr; // Scene depth texutre, r32_unorm
|
|
inline static auto depthTextureFormat() { return VK_FORMAT_D32_SFLOAT; }
|
|
|
|
PoolImageSharedRef gbufferA = nullptr; // GBuffer A: r8g8b8a8 unorm, .rgb store base color.
|
|
inline static auto gbufferAFormat() { return VK_FORMAT_R8G8B8A8_UNORM; }
|
|
|
|
PoolImageSharedRef gbufferB = nullptr; // GBuffer B : r16g16b16a16 .rgb store worldspace normal.
|
|
inline static auto gbufferBFormat() { return VK_FORMAT_R16G16B16A16_SFLOAT; }
|
|
|
|
PoolImageSharedRef gbufferS = nullptr; // GBuffer S: r8g8b8a8 unorm, .r is metal, .g is roughness, .b is mesh ao.
|
|
inline static auto gbufferSFormat() { return VK_FORMAT_R8G8B8A8_UNORM; }
|
|
|
|
PoolImageSharedRef gbufferV = nullptr; // GBuffer V: r16g16 sfloat.
|
|
inline static auto gbufferVFormat() { return VK_FORMAT_R16G16_SFLOAT; }
|
|
|
|
/*
|
|
In the context of FSR2, the term "reactivity" means how much influence the samples rendered for the current frame have over the production of the final upscaled image. Typically,
|
|
samples rendered for the current frame contribute a relatively modest amount to the result computed by FSR2; however, there are exceptions. To produce the best results for fast moving,
|
|
alpha-blended objects, FSR2 requires the Reproject & accumulate stage to become more reactive for such pixels. As there is no good way to determine from either color,
|
|
depth or motion vectors which pixels have been rendered using alpha blending, FSR2 performs best when applications explicitly mark such areas.
|
|
|
|
Therefore, it is strongly encouraged that applications provide a reactive mask to FSR2.
|
|
The reactive mask guides FSR2 on where it should reduce its reliance on historical information when compositing the current pixel,
|
|
and instead allow the current frame's samples to contribute more to the final result.
|
|
The reactive mask allows the application to provide a value from [0..1] where 0 indicates that the pixel is not at all reactive (and should use the default FSR2 composition strategy),
|
|
and a value of 1 indicates the pixel should be fully reactive.
|
|
|
|
While there are other applications for the reactive mask,
|
|
the primary application for the reactive mask is producing better results of upscaling images which include alpha-blended objects.
|
|
A good proxy for reactiveness is actually the alpha value used when compositing an alpha-blended object into the scene,
|
|
therefore, applications should write alpha to the reactive mask.
|
|
It should be noted that it is unlikely that a reactive value of close to 1 will ever produce good results. Therefore, we recommend clamping the maximum reactive value to around 0.9.
|
|
|
|
If a Reactive mask is not provided to FSR2 (by setting the reactive field of FfxFsr2DispatchDescription to NULL),
|
|
then an internally generated 1x1 texture with a cleared reactive value will be used.
|
|
*/
|
|
PoolImageSharedRef gbufferUpscaleReactive = nullptr;
|
|
inline static auto gbufferUpscaleReactiveFormat() { return VK_FORMAT_R8_UNORM; }
|
|
|
|
/*
|
|
In addition to the Reactive mask, FSR2 provides for the application to denote areas of other specialist rendering which should be accounted for during the upscaling process.
|
|
Examples of such special rendering include areas of raytraced reflections or animated textures.
|
|
|
|
While the Reactive mask adjusts the accumulation balance, the Transparency & composition mask adjusts the pixel locks created by FSR2.
|
|
A pixel with a value of 0 in the Transparency & composition mask does not perform any additional modification to the lock for that pixel.
|
|
Conversely, a value of 1 denotes that the lock for that pixel should be completely removed.
|
|
|
|
If a Transparency & composition mask is not provided to FSR2 (by setting the transparencyAndComposition field of FfxFsr2DispatchDescription to NULL),
|
|
then an internally generated 1x1 texture with a cleared transparency and composition value will be used.
|
|
*/
|
|
PoolImageSharedRef gbufferUpscaleTranslucencyAndComposition = nullptr;
|
|
inline static auto gbufferUpscaleTranslucencyAndCompositionFormat() { return VK_FORMAT_R8_UNORM; }
|
|
};
|
|
} |