Make linearized depth data available to translucent material shaders via the texture name SceneLinearDepth. Does it work? Who knows!
This commit is contained in:
parent
e65b3058cf
commit
1b8effe1ea
17 changed files with 183 additions and 32 deletions
|
|
@ -43,6 +43,12 @@ VkHardwareTexture::VkHardwareTexture(VulkanRenderDevice* fb, int numchannels) :
|
|||
fb->GetTextureManager()->AddTexture(this);
|
||||
}
|
||||
|
||||
VkHardwareTexture::VkHardwareTexture(VulkanRenderDevice* fb, FSceneTextureType sceneTextureType) : fb(fb), mSceneTextureType(sceneTextureType)
|
||||
{
|
||||
mTexelsize = 4;
|
||||
fb->GetTextureManager()->AddTexture(this);
|
||||
}
|
||||
|
||||
VkHardwareTexture::~VkHardwareTexture()
|
||||
{
|
||||
if (fb)
|
||||
|
|
@ -66,6 +72,11 @@ void VkHardwareTexture::Reset()
|
|||
|
||||
VkTextureImage *VkHardwareTexture::GetImage(FTexture *tex, int translation, int flags)
|
||||
{
|
||||
if (mSceneTextureType == FSceneTextureType::LinearDepth)
|
||||
{
|
||||
return &fb->GetBuffers()->SceneLinearDepth;
|
||||
}
|
||||
|
||||
if (!mImage.Image)
|
||||
{
|
||||
CreateImage(tex, translation, flags);
|
||||
|
|
|
|||
|
|
@ -21,12 +21,14 @@ class VulkanImageView;
|
|||
class VulkanBuffer;
|
||||
class VulkanRenderDevice;
|
||||
class FGameTexture;
|
||||
enum class FSceneTextureType;
|
||||
|
||||
class VkHardwareTexture : public IHardwareTexture
|
||||
{
|
||||
friend class VkMaterial;
|
||||
public:
|
||||
VkHardwareTexture(VulkanRenderDevice* fb, int numchannels);
|
||||
VkHardwareTexture(VulkanRenderDevice* fb, FSceneTextureType sceneTextureType);
|
||||
~VkHardwareTexture();
|
||||
|
||||
void Reset();
|
||||
|
|
@ -51,6 +53,8 @@ private:
|
|||
void CreateTexture(int w, int h, int pixelsize, VkFormat format, const void *pixels, bool mipmap);
|
||||
static int GetMipLevels(int w, int h);
|
||||
|
||||
FSceneTextureType mSceneTextureType = FSceneTextureType::None;
|
||||
|
||||
VkTextureImage mImage;
|
||||
int mTexelsize = 4;
|
||||
|
||||
|
|
|
|||
|
|
@ -174,11 +174,13 @@ void VkRenderBuffers::CreateScene(int width, int height, VkSampleCountFlagBits s
|
|||
SceneDepthStencil.Reset(fb);
|
||||
SceneNormal.Reset(fb);
|
||||
SceneFog.Reset(fb);
|
||||
SceneLinearDepth.Reset(fb);
|
||||
|
||||
CreateSceneColor(width, height, samples);
|
||||
CreateSceneDepthStencil(width, height, samples);
|
||||
CreateSceneNormal(width, height, samples);
|
||||
CreateSceneFog(width, height, samples);
|
||||
CreateSceneLinearDepth(width, height);
|
||||
|
||||
VkImageTransition()
|
||||
.AddImage(&SceneColor, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, true)
|
||||
|
|
@ -252,6 +254,21 @@ void VkRenderBuffers::CreateSceneFog(int width, int height, VkSampleCountFlagBit
|
|||
.Create(fb->GetDevice());
|
||||
}
|
||||
|
||||
void VkRenderBuffers::CreateSceneLinearDepth(int width, int height)
|
||||
{
|
||||
SceneLinearDepth.Image = ImageBuilder()
|
||||
.Size(width, height)
|
||||
.Format(VK_FORMAT_R32_SFLOAT)
|
||||
.Usage(VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT)
|
||||
.DebugName("VkRenderBuffers.SceneLinearDepth")
|
||||
.Create(fb->GetDevice());
|
||||
|
||||
SceneLinearDepth.View = ImageViewBuilder()
|
||||
.Image(SceneLinearDepth.Image.get(), VK_FORMAT_R32_SFLOAT)
|
||||
.DebugName("VkRenderBuffers.SceneLinearDepthView")
|
||||
.Create(fb->GetDevice());
|
||||
}
|
||||
|
||||
void VkRenderBuffers::CreateSceneNormal(int width, int height, VkSampleCountFlagBits samples)
|
||||
{
|
||||
ImageBuilder builder;
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ public:
|
|||
VkTextureImage SceneDepthStencil;
|
||||
VkTextureImage SceneNormal;
|
||||
VkTextureImage SceneFog;
|
||||
VkTextureImage SceneLinearDepth;
|
||||
|
||||
VkFormat PipelineDepthStencilFormat = VK_FORMAT_D24_UNORM_S8_UINT;
|
||||
VkFormat SceneDepthStencilFormat = VK_FORMAT_D24_UNORM_S8_UINT;
|
||||
|
|
@ -53,6 +54,7 @@ private:
|
|||
void CreateSceneDepthStencil(int width, int height, VkSampleCountFlagBits samples);
|
||||
void CreateSceneFog(int width, int height, VkSampleCountFlagBits samples);
|
||||
void CreateSceneNormal(int width, int height, VkSampleCountFlagBits samples);
|
||||
void CreateSceneLinearDepth(int width, int height);
|
||||
VkSampleCountFlagBits GetBestSampleCount();
|
||||
|
||||
VulkanRenderDevice* fb = nullptr;
|
||||
|
|
|
|||
|
|
@ -114,6 +114,10 @@ VkTextureImage* VkTextureManager::GetTexture(const PPTextureType& type, PPTextur
|
|||
{
|
||||
return &fb->GetBuffers()->SceneDepthStencil;
|
||||
}
|
||||
else if (type == PPTextureType::SceneLinearDepth)
|
||||
{
|
||||
return &fb->GetBuffers()->SceneLinearDepth;
|
||||
}
|
||||
else if (type == PPTextureType::ShadowMap)
|
||||
{
|
||||
return &Shadowmap;
|
||||
|
|
|
|||
|
|
@ -244,6 +244,17 @@ void VkPostprocess::DrawPresentTexture(const IntRect &box, bool applyGamma, bool
|
|||
renderstate.Draw();
|
||||
}
|
||||
|
||||
void VkPostprocess::UpdateLinearDepthTexture()
|
||||
{
|
||||
int sceneWidth = fb->GetBuffers()->GetSceneWidth();
|
||||
int sceneHeight = fb->GetBuffers()->GetSceneHeight();
|
||||
|
||||
VkPPRenderState renderstate(fb);
|
||||
hw_postprocess.linearDepth.Render(&renderstate, sceneWidth, sceneHeight);
|
||||
|
||||
ImageTransitionScene(false);
|
||||
}
|
||||
|
||||
void VkPostprocess::AmbientOccludeScene(float m5)
|
||||
{
|
||||
int sceneWidth = fb->GetBuffers()->GetSceneWidth();
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ public:
|
|||
void SetActiveRenderTarget();
|
||||
void PostProcessScene(int fixedcm, float flash, const std::function<void()> &afterBloomDrawEndScene2D);
|
||||
|
||||
void UpdateLinearDepthTexture();
|
||||
void AmbientOccludeScene(float m5);
|
||||
void BlurScene(float gameinfobluramount);
|
||||
void ClearTonemapPalette();
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ void VkPPRenderState::Draw()
|
|||
key.OutputFormat = fb->GetTextureManager()->GetTextureFormat(Output.Texture);
|
||||
else if (Output.Type == PPTextureType::SwapChain)
|
||||
key.OutputFormat = fb->GetFramebufferManager()->SwapChain->Format().format;
|
||||
else if (Output.Type == PPTextureType::ShadowMap)
|
||||
else if (Output.Type == PPTextureType::ShadowMap || Output.Type == PPTextureType::SceneLinearDepth)
|
||||
key.OutputFormat = VK_FORMAT_R32_SFLOAT;
|
||||
else
|
||||
key.OutputFormat = VK_FORMAT_R16G16B16A16_SFLOAT;
|
||||
|
|
|
|||
|
|
@ -355,6 +355,12 @@ IHardwareTexture *VulkanRenderDevice::CreateHardwareTexture(int numchannels)
|
|||
return new VkHardwareTexture(this, numchannels);
|
||||
}
|
||||
|
||||
IHardwareTexture* VulkanRenderDevice::CreateSceneTexture(FSceneTexture* owner)
|
||||
{
|
||||
mSceneTextureOwners[owner->Type] = owner;
|
||||
return new VkHardwareTexture(this, owner->Type);
|
||||
}
|
||||
|
||||
FMaterial* VulkanRenderDevice::CreateMaterial(FGameTexture* tex, int scaleflags)
|
||||
{
|
||||
return new VkMaterial(this, tex, scaleflags);
|
||||
|
|
@ -535,6 +541,7 @@ void VulkanRenderDevice::BeginFrame()
|
|||
mTextureManager->BeginFrame();
|
||||
mScreenBuffers->BeginFrame(screen->mScreenViewport.width, screen->mScreenViewport.height, screen->mSceneViewport.width, screen->mSceneViewport.height);
|
||||
mSaveBuffers->BeginFrame(SAVEPICWIDTH, SAVEPICHEIGHT, SAVEPICWIDTH, SAVEPICHEIGHT);
|
||||
UpdateSceneTextureSizes();
|
||||
mRenderState->BeginFrame();
|
||||
mDescriptorSetManager->BeginFrame();
|
||||
mLightmapper->BeginFrame();
|
||||
|
|
@ -622,6 +629,18 @@ void VulkanRenderDevice::SetSaveBuffers(bool yes)
|
|||
{
|
||||
if (yes) mActiveRenderBuffers = mSaveBuffers.get();
|
||||
else mActiveRenderBuffers = mScreenBuffers.get();
|
||||
UpdateSceneTextureSizes();
|
||||
}
|
||||
|
||||
void VulkanRenderDevice::UpdateSceneTextureSizes()
|
||||
{
|
||||
for (auto& it : mSceneTextureOwners)
|
||||
{
|
||||
if (it.second)
|
||||
{
|
||||
it.second->SetSize(mActiveRenderBuffers->GetSceneWidth(), mActiveRenderBuffers->GetSceneHeight());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void VulkanRenderDevice::ImageTransitionScene(bool unknown)
|
||||
|
|
@ -634,6 +653,11 @@ FRenderState* VulkanRenderDevice::RenderState()
|
|||
return mRenderState.get();
|
||||
}
|
||||
|
||||
void VulkanRenderDevice::UpdateLinearDepthTexture()
|
||||
{
|
||||
mPostprocess->UpdateLinearDepthTexture();
|
||||
}
|
||||
|
||||
void VulkanRenderDevice::AmbientOccludeScene(float m5)
|
||||
{
|
||||
mPostprocess->AmbientOccludeScene(m5);
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ public:
|
|||
void BeginFrame() override;
|
||||
void BlurScene(float amount) override;
|
||||
void PostProcessScene(bool swscene, int fixedcm, float flash, const std::function<void()> &afterBloomDrawEndScene2D) override;
|
||||
void UpdateLinearDepthTexture() override;
|
||||
void AmbientOccludeScene(float m5) override;
|
||||
void SetSceneRenderTarget(bool useSSAO) override;
|
||||
void SetLevelMesh(LevelMesh* mesh) override;
|
||||
|
|
@ -73,6 +74,7 @@ public:
|
|||
void SetActiveRenderTarget() override;
|
||||
|
||||
IHardwareTexture *CreateHardwareTexture(int numchannels) override;
|
||||
IHardwareTexture* CreateSceneTexture(FSceneTexture* owner) override;
|
||||
FMaterial* CreateMaterial(FGameTexture* tex, int scaleflags) override;
|
||||
|
||||
IBuffer* CreateVertexBuffer(int numBindingPoints, int numAttributes, size_t stride, const FVertexBufferAttribute* attrs) override;
|
||||
|
|
@ -101,6 +103,8 @@ private:
|
|||
void PrintStartupLog();
|
||||
void CopyScreenToBuffer(int w, int h, uint8_t *data) override;
|
||||
|
||||
void UpdateSceneTextureSizes();
|
||||
|
||||
std::shared_ptr<VulkanDevice> mDevice;
|
||||
std::unique_ptr<VkCommandBufferManager> mCommands;
|
||||
std::unique_ptr<VkBufferManager> mBufferManager;
|
||||
|
|
@ -117,6 +121,8 @@ private:
|
|||
std::unique_ptr<VkLightmapper> mLightmapper;
|
||||
std::unique_ptr<VkRenderState> mRenderState;
|
||||
|
||||
std::unordered_map<FSceneTextureType, FSceneTexture*> mSceneTextureOwners;
|
||||
|
||||
VkRenderBuffers *mActiveRenderBuffers = nullptr;
|
||||
|
||||
bool mVSync = false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue