mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2026-04-27 04:41:39 +00:00
Initial DoF fix experiments.
This commit is contained in:
parent
aa59eae8c8
commit
27b7812215
3 changed files with 73 additions and 0 deletions
|
|
@ -284,6 +284,7 @@ function(compile_pixel_shader FILE_PATH)
|
|||
endfunction()
|
||||
|
||||
compile_vertex_shader(copy_vs)
|
||||
compile_pixel_shader(gaussian_blur_ps)
|
||||
compile_pixel_shader(gamma_correction_ps)
|
||||
compile_pixel_shader(imgui_ps)
|
||||
compile_vertex_shader(imgui_vs)
|
||||
|
|
|
|||
60
UnleashedRecomp/gpu/shader/gaussian_blur_ps.hlsl
Normal file
60
UnleashedRecomp/gpu/shader/gaussian_blur_ps.hlsl
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
#include "../../../thirdparty/ShaderRecomp/ShaderRecomp/shader_common.h"
|
||||
|
||||
#ifdef __spirv__
|
||||
|
||||
#define g_ViewportSize vk::RawBufferLoad<float4>(g_PushConstants.PixelShaderConstants + 384, 0x10)
|
||||
#define g_offsets(INDEX) select((INDEX) < 74, vk::RawBufferLoad<float4>(g_PushConstants.PixelShaderConstants + (150 + min(INDEX, 73)) * 16, 0x10), 0.0)
|
||||
#define g_weights vk::RawBufferLoad<float4>(g_PushConstants.PixelShaderConstants + 2656, 0x10)
|
||||
|
||||
#define s0_Texture2DDescriptorIndex vk::RawBufferLoad<uint>(g_PushConstants.SharedConstants + 0)
|
||||
#define s0_SamplerDescriptorIndex vk::RawBufferLoad<uint>(g_PushConstants.SharedConstants + 192)
|
||||
|
||||
#else
|
||||
|
||||
cbuffer PixelShaderConstants : register(b1, space4)
|
||||
{
|
||||
float4 g_ViewportSize : packoffset(c24);
|
||||
float4 g_offsets[2] : packoffset(c150);
|
||||
#define g_offsets(INDEX) select((INDEX) < 74, g_offsets[min(INDEX, 73)], 0.0)
|
||||
float4 g_weights : packoffset(c166);
|
||||
};
|
||||
|
||||
cbuffer SharedConstants : register(b2, space4)
|
||||
{
|
||||
uint s0_Texture2DDescriptorIndex : packoffset(c0.x);
|
||||
uint s0_SamplerDescriptorIndex : packoffset(c12.x);
|
||||
DEFINE_SHARED_CONSTANTS();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
float4 main(in float4 iPosition : SV_Position, in float4 iTexCoord0 : TEXCOORD0) : SV_Target
|
||||
{
|
||||
Texture2D<float4> texture = g_Texture2DDescriptorHeap[s0_Texture2DDescriptorIndex];
|
||||
SamplerState samplerState = g_SamplerDescriptorHeap[s0_SamplerDescriptorIndex];
|
||||
|
||||
float scaleFactor = g_ViewportSize.y / 360.0;
|
||||
|
||||
float2 offsets[5];
|
||||
offsets[0] = g_offsets(0).xy * scaleFactor;
|
||||
offsets[2] = g_offsets(0).zw * scaleFactor;
|
||||
offsets[4] = g_offsets(1).xy * scaleFactor;
|
||||
|
||||
offsets[1] = lerp(offsets[2], offsets[0], 0.5);
|
||||
offsets[3] = lerp(offsets[2], offsets[4], 0.5);
|
||||
|
||||
float weights[5];
|
||||
weights[0] = 0.1131226076;
|
||||
weights[1] = 0.2360540033;
|
||||
weights[2] = 0.3016467782;
|
||||
weights[3] = 0.2360540033;
|
||||
weights[4] = 0.1131226076;
|
||||
|
||||
float4 c0 = texture.Sample(samplerState, iTexCoord0.xy + offsets[0]) * weights[0];
|
||||
float4 c1 = texture.Sample(samplerState, iTexCoord0.xy + offsets[1]) * weights[1];
|
||||
float4 c2 = texture.Sample(samplerState, iTexCoord0.xy + offsets[2]) * weights[2];
|
||||
float4 c3 = texture.Sample(samplerState, iTexCoord0.xy + offsets[3]) * weights[3];
|
||||
float4 c4 = texture.Sample(samplerState, iTexCoord0.xy + offsets[4]) * weights[4];
|
||||
|
||||
return c0 + c1 + c2 + c3 + c4;
|
||||
}
|
||||
|
|
@ -34,6 +34,8 @@
|
|||
#include "../../thirdparty/ShaderRecomp/ShaderRecomp/shader_common.h"
|
||||
#include "shader/copy_vs.hlsl.dxil.h"
|
||||
#include "shader/copy_vs.hlsl.spirv.h"
|
||||
#include "shader/gaussian_blur_ps.hlsl.dxil.h"
|
||||
#include "shader/gaussian_blur_ps.hlsl.spirv.h"
|
||||
#include "shader/gamma_correction_ps.hlsl.dxil.h"
|
||||
#include "shader/gamma_correction_ps.hlsl.spirv.h"
|
||||
#include "shader/imgui_ps.hlsl.dxil.h"
|
||||
|
|
@ -1024,6 +1026,7 @@ static const std::pair<GuestRenderState, void*> g_setRenderStateFunctions[] =
|
|||
};
|
||||
|
||||
static std::unique_ptr<RenderPipeline> g_resolveMsaaDepthPipelines[3];
|
||||
static std::unique_ptr<GuestShader> g_gaussianBlurShader;
|
||||
|
||||
#define CREATE_SHADER(NAME) \
|
||||
g_device->createShader( \
|
||||
|
|
@ -1416,6 +1419,9 @@ void Video::CreateHostDevice()
|
|||
g_resolveMsaaDepthPipelines[i] = g_device->createGraphicsPipeline(desc);
|
||||
}
|
||||
|
||||
g_gaussianBlurShader = std::make_unique<GuestShader>(ResourceType::PixelShader);
|
||||
g_gaussianBlurShader->shader = CREATE_SHADER(gaussian_blur_ps);
|
||||
|
||||
CreateImGuiBackend();
|
||||
|
||||
auto gammaCorrectionShader = CREATE_SHADER(gamma_correction_ps);
|
||||
|
|
@ -3836,6 +3842,12 @@ static GuestShader* CreatePixelShader(const be<uint32_t>* function)
|
|||
|
||||
static void SetPixelShader(GuestDevice* device, GuestShader* shader)
|
||||
{
|
||||
if (shader != nullptr && shader->shaderCacheEntry != nullptr && shader->shaderCacheEntry->hash == 0x4294510C775F4EE8)
|
||||
{
|
||||
if (!(GetAsyncKeyState(VK_F4) & 0x8000))
|
||||
shader = g_gaussianBlurShader.get();
|
||||
}
|
||||
|
||||
RenderCommand cmd;
|
||||
cmd.type = RenderCommandType::SetPixelShader;
|
||||
cmd.setPixelShader.shader = shader;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue