This commit is contained in:
Rachael Alexanderson 2019-04-16 08:14:47 -04:00
commit 231f967d80
87 changed files with 70 additions and 62 deletions

View file

@ -95,7 +95,7 @@ EXTERN_CVAR(Bool, vid_vsync)
EXTERN_CVAR(Bool, vid_hidpi)
EXTERN_CVAR(Int, vid_defwidth)
EXTERN_CVAR(Int, vid_defheight)
EXTERN_CVAR(Int, vid_backend)
EXTERN_CVAR(Int, vid_enablevulkan)
EXTERN_CVAR(Bool, vk_debug)
CUSTOM_CVAR(Bool, vid_autoswitch, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL)
@ -342,7 +342,7 @@ class CocoaVideo : public IVideo
public:
CocoaVideo()
{
ms_isVulkanEnabled = vid_backend == 0 && NSAppKitVersionNumber >= 1404; // NSAppKitVersionNumber10_11
ms_isVulkanEnabled = vid_enablevulkan == 1 && NSAppKitVersionNumber >= 1404; // NSAppKitVersionNumber10_11
}
~CocoaVideo()

View file

@ -73,7 +73,7 @@ EXTERN_CVAR (Int, vid_adapter)
EXTERN_CVAR (Int, vid_displaybits)
EXTERN_CVAR (Int, vid_defwidth)
EXTERN_CVAR (Int, vid_defheight)
EXTERN_CVAR (Int, vid_backend)
EXTERN_CVAR (Int, vid_enablevulkan)
EXTERN_CVAR (Bool, cl_capfps)
// PUBLIC DATA DEFINITIONS -------------------------------------------------
@ -238,7 +238,7 @@ SDLVideo::SDLVideo ()
}
#ifdef HAVE_VULKAN
Priv::vulkanEnabled = vid_backend == 0
Priv::vulkanEnabled = vid_enablevulkan == 1
&& Priv::Vulkan_GetDrawableSize && Priv::Vulkan_GetInstanceExtensions && Priv::Vulkan_CreateSurface;
if (Priv::vulkanEnabled)

View file

@ -697,15 +697,11 @@ void PPAmbientOcclusion::Render(PPRenderState *renderstate, float m5, int sceneW
ssaoUniforms.Scale = sceneScale;
ssaoUniforms.Offset = sceneOffset;
DepthBlurUniforms blurUniforms;
blurUniforms.BlurSharpness = blurSharpness;
blurUniforms.InvFullResolution = { 1.0f / AmbientWidth, 1.0f / AmbientHeight };
blurUniforms.PowExponent = gl_ssao_exponent;
AmbientCombineUniforms combineUniforms;
combineUniforms.SampleCount = gl_multisample;
combineUniforms.Scale = screen->SceneScale();
combineUniforms.Offset = screen->SceneOffset();
combineUniforms.DebugMode = gl_ssao_debug;
IntRect ambientViewport;
ambientViewport.left = 0;
@ -739,6 +735,11 @@ void PPAmbientOcclusion::Render(PPRenderState *renderstate, float m5, int sceneW
// Blur SSAO texture
if (gl_ssao_debug < 2)
{
DepthBlurUniforms blurUniforms;
blurUniforms.BlurSharpness = blurSharpness;
blurUniforms.PowExponent = gl_ssao_exponent;
blurUniforms.InvFullResolution = { 1.0f / AmbientWidth, 0.0f };
renderstate->Clear();
renderstate->Shader = &BlurHorizontal;
renderstate->Uniforms.Set(blurUniforms);
@ -748,9 +749,15 @@ void PPAmbientOcclusion::Render(PPRenderState *renderstate, float m5, int sceneW
renderstate->SetNoBlend();
renderstate->Draw();
blurUniforms.InvFullResolution = { 0.0f, 1.0f / AmbientHeight };
renderstate->Clear();
renderstate->Shader = &BlurVertical;
renderstate->Uniforms.Set(blurUniforms);
renderstate->Viewport = ambientViewport;
renderstate->SetInputTexture(0, &Ambient1);
renderstate->SetOutputTexture(&Ambient0);
renderstate->SetNoBlend();
renderstate->Draw();
}
@ -759,7 +766,10 @@ void PPAmbientOcclusion::Render(PPRenderState *renderstate, float m5, int sceneW
renderstate->Shader = gl_multisample > 1 ? &CombineMS : &Combine;
renderstate->Uniforms.Set(combineUniforms);
renderstate->Viewport = screen->mSceneViewport;
renderstate->SetInputTexture(0, &Ambient0, PPFilterMode::Linear);
if (gl_ssao_debug < 4)
renderstate->SetInputTexture(0, &Ambient0, PPFilterMode::Linear);
else
renderstate->SetInputSceneNormal(0, PPFilterMode::Linear);
renderstate->SetInputSceneFog(1);
renderstate->SetOutputSceneColor();
if (gl_ssao_debug != 0)

View file

@ -650,7 +650,7 @@ struct DepthBlurUniforms
struct AmbientCombineUniforms
{
int SampleCount;
int Padding0, Padding1, Padding2;
int DebugMode, Padding1, Padding2;
FVector2 Scale;
FVector2 Offset;
@ -659,7 +659,7 @@ struct AmbientCombineUniforms
return
{
{ "SampleCount", UniformType::Int, offsetof(AmbientCombineUniforms, SampleCount) },
{ "Padding0", UniformType::Int, offsetof(AmbientCombineUniforms, Padding0) },
{ "DebugMode", UniformType::Int, offsetof(AmbientCombineUniforms, DebugMode) },
{ "Padding1", UniformType::Int, offsetof(AmbientCombineUniforms, Padding1) },
{ "Padding2", UniformType::Int, offsetof(AmbientCombineUniforms, Padding2) },
{ "Scale", UniformType::Vec2, offsetof(AmbientCombineUniforms, Scale) },

View file

@ -108,7 +108,7 @@ CUSTOM_CVAR(Int, vid_rendermode, 4, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOIN
// No further checks needed. All this changes now is which scene drawer the render backend calls.
}
CUSTOM_CVAR(Int, vid_backend, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL)
CUSTOM_CVAR(Int, vid_enablevulkan, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL)
{
// [SP] This may seem pointless - but I don't want to implement live switching just
// yet - I'm pretty sure it's going to require a lot of reinits and destructions to

View file

@ -51,7 +51,7 @@
#include "i_system.h"
#include "swrenderer/r_swrenderer.h"
EXTERN_CVAR(Int, vid_backend)
EXTERN_CVAR(Int, vid_enablevulkan)
extern HWND Window;
@ -130,7 +130,7 @@ void I_InitGraphics ()
}
#ifdef HAVE_VULKAN
if (vid_backend == 0)
if (vid_enablevulkan == 1)
{
// first try Vulkan, if that fails OpenGL
try

View file

@ -2709,8 +2709,10 @@ OptionString "LanguageOptions"
"es", "Español (España)"
"esm", "Español (Latino)"
"fr", "Français"
"ko", "한국의 (Korean)"
"it", "Italiano"
"ru", "Русский"
"pt", "Portugues do Brasil"
"ru", "Русский (Russian)"
}
/*=======================================
@ -2743,7 +2745,7 @@ OptionMenu "vkoptions"
StaticText "$VK_WARNING"
StaticText "$VK_RESTART"
StaticText ""
Option "$VKMNU_ENABLE", "vid_backend", "OffOn"
Option "$VKMNU_ENABLE", "vid_enablevulkan", "OnOff"
TextField "$VKMNU_DEVICE", vk_device
Option "$VKMNU_HDR", "vk_hdr", "OnOff"
}

View file

@ -6,61 +6,48 @@ layout(binding=0) uniform sampler2D AODepthTexture;
#define KERNEL_RADIUS 3.0
float CrossBilateralWeight(float r, float sampleDepth, float centerDepth)
void main()
{
const float blurSigma = KERNEL_RADIUS * 0.5;
const float blurFalloff = 1.0 / (2.0 * blurSigma * blurSigma);
float deltaZ = (sampleDepth - centerDepth) * BlurSharpness;
vec2 centerSample = texture(AODepthTexture, TexCoord).xy;
return exp2(-r * r * blurFalloff - deltaZ * deltaZ);
}
void ProcessSample(float ao, float z, float r, float centerDepth, inout float totalAO, inout float totalW)
{
float w = CrossBilateralWeight(r, z, centerDepth);
totalAO += w * ao;
totalW += w;
}
void ProcessRadius(vec2 deltaUV, float centerDepth, inout float totalAO, inout float totalW)
{
for (float r = 1; r <= KERNEL_RADIUS; r += 1.0)
{
vec2 uv = r * deltaUV + TexCoord;
vec2 aoZ = texture(AODepthTexture, uv).xy;
ProcessSample(aoZ.x, aoZ.y, r, centerDepth, totalAO, totalW);
}
}
vec2 ComputeBlur(vec2 deltaUV)
{
vec2 aoZ = texture(AODepthTexture, TexCoord).xy;
float totalAO = aoZ.x;
float centerDepth = centerSample.y;
float totalAO = centerSample.x;
float totalW = 1.0;
ProcessRadius(deltaUV, aoZ.y, totalAO, totalW);
ProcessRadius(-deltaUV, aoZ.y, totalAO, totalW);
for (float r = 1.0; r <= KERNEL_RADIUS; r += 1.0)
{
vec4 blurSample = texture(AODepthTexture, TexCoord - InvFullResolution * r);
float ao = blurSample.x;
float z = blurSample.y;
return vec2(totalAO / totalW, aoZ.y);
}
float deltaZ = (z - centerDepth) * BlurSharpness;
float w = exp2(-r * r * blurFalloff - deltaZ * deltaZ);
vec2 BlurX()
{
return ComputeBlur(vec2(InvFullResolution.x, 0.0));
}
totalAO += w * ao;
totalW += w;
}
float BlurY()
{
return pow(clamp(ComputeBlur(vec2(0.0, InvFullResolution.y)).x, 0.0, 1.0), PowExponent);
}
for (float r = 1.0; r <= KERNEL_RADIUS; r += 1.0)
{
vec4 blurSample = texture(AODepthTexture, InvFullResolution * r + TexCoord);
float ao = blurSample.x;
float z = blurSample.y;
float deltaZ = (z - centerDepth) * BlurSharpness;
float w = exp2(-r * r * blurFalloff - deltaZ * deltaZ);
totalAO += w * ao;
totalW += w;
}
float fragAO = totalAO / totalW;
void main()
{
#if defined(BLUR_HORIZONTAL)
FragColor = vec4(BlurX(), 0.0, 1.0);
FragColor = vec4(fragAO, centerDepth, 0.0, 1.0);
#else
FragColor = vec4(BlurY(), 0.0, 0.0, 1.0);
FragColor = vec4(pow(clamp(fragAO, 0.0, 1.0), PowExponent), 0.0, 0.0, 1.0);
#endif
}

View file

@ -30,6 +30,15 @@ void main()
vec3 fogColor = texelFetch(SceneFogTexture, ipos, 0).rgb;
#endif
float attenutation = texture(AODepthTexture, TexCoord).x;
FragColor = vec4(fogColor, 1.0 - attenutation);
vec4 ssao = texture(AODepthTexture, TexCoord);
float attenutation = ssao.x;
if (DebugMode == 0)
FragColor = vec4(fogColor, 1.0 - attenutation);
else if (DebugMode < 3)
FragColor = vec4(attenutation, attenutation, attenutation, 1.0);
else if (DebugMode == 3)
FragColor = vec4(ssao.yyy / 1000.0, 1.0);
else
FragColor = vec4(ssao.xyz, 1.0);
}