Update ZVulkan, rename vk_raytrace to gl_light_raytrace and support turning it on and off without a restart

This commit is contained in:
Magnus Norddahl 2023-01-14 03:47:12 +01:00 committed by Christoph Oelckers
parent 2be0494413
commit 35df964d61
8 changed files with 26 additions and 20 deletions

View file

@ -15,6 +15,7 @@ EXTERN_CVAR(Int, gl_weaponlight)
EXTERN_CVAR (Bool, gl_light_sprites);
EXTERN_CVAR (Bool, gl_light_particles);
EXTERN_CVAR (Bool, gl_light_shadowmap);
EXTERN_CVAR (Bool, gl_light_raytrace);
EXTERN_CVAR (Int, gl_shadowmap_quality);
EXTERN_CVAR(Int, gl_fogmode)

View file

@ -60,6 +60,7 @@ int IShadowMap::LightsProcessed;
int IShadowMap::LightsShadowmapped;
CVAR(Bool, gl_light_shadowmap, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
CVAR(Bool, gl_light_raytrace, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
ADD_STAT(shadowmap)
{

View file

@ -103,7 +103,7 @@ void VkDescriptorSetManager::UpdateFixedSet()
WriteDescriptors update;
update.AddCombinedImageSampler(FixedSet.get(), 0, fb->GetTextureManager()->Shadowmap.View.get(), fb->GetSamplerManager()->ShadowmapSampler.get(), VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
update.AddCombinedImageSampler(FixedSet.get(), 1, fb->GetTextureManager()->Lightmap.View.get(), fb->GetSamplerManager()->LightmapSampler.get(), VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
if (fb->RaytracingEnabled())
if (fb->device->SupportsDeviceExtension(VK_KHR_RAY_QUERY_EXTENSION_NAME))
update.AddAccelerationStructure(FixedSet.get(), 2, fb->GetRaytrace()->GetAccelStruct());
update.Execute(fb->device.get());
}
@ -263,7 +263,7 @@ void VkDescriptorSetManager::CreateFixedSetLayout()
DescriptorSetLayoutBuilder builder;
builder.AddBinding(0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_FRAGMENT_BIT);
builder.AddBinding(1, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_FRAGMENT_BIT);
if (fb->RaytracingEnabled())
if (fb->device->SupportsDeviceExtension(VK_KHR_RAY_QUERY_EXTENSION_NAME))
builder.AddBinding(2, VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, 1, VK_SHADER_STAGE_FRAGMENT_BIT);
builder.DebugName("VkDescriptorSetManager.FixedSetLayout");
FixedSetLayout = builder.Create(fb->device.get());
@ -283,7 +283,7 @@ void VkDescriptorSetManager::CreateFixedSetPool()
{
DescriptorPoolBuilder poolbuilder;
poolbuilder.AddPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 2 * maxSets);
if (fb->RaytracingEnabled())
if (fb->device->SupportsDeviceExtension(VK_KHR_RAY_QUERY_EXTENSION_NAME))
poolbuilder.AddPoolSize(VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, 1 * maxSets);
poolbuilder.MaxSets(maxSets);
poolbuilder.DebugName("VkDescriptorSetManager.FixedDescriptorPool");

View file

@ -55,7 +55,7 @@ void VkRaytrace::SetLevelMesh(hwrenderer::LevelMesh* mesh)
{
Reset();
Mesh = mesh;
if (fb->RaytracingEnabled())
if (fb->device->SupportsDeviceExtension(VK_KHR_RAY_QUERY_EXTENSION_NAME))
{
CreateVulkanObjects();
}

View file

@ -361,7 +361,7 @@ std::unique_ptr<VulkanShader> VkShaderManager::LoadVertShader(FString shadername
std::unique_ptr<VulkanShader> VkShaderManager::LoadFragShader(FString shadername, const char *frag_lump, const char *material_lump, const char *light_lump, const char *defines, bool alphatest, bool gbufferpass)
{
FString code = GetTargetGlslVersion();
if (fb->RaytracingEnabled())
if (fb->device->SupportsDeviceExtension(VK_KHR_RAY_QUERY_EXTENSION_NAME))
code << "\n#define SUPPORTS_RAYTRACING\n";
code << defines;
code << "\n$placeholder$"; // here the code can later add more needed #defines.

View file

@ -91,8 +91,6 @@ public:
void WaitForCommands(bool finish) override;
bool RaytracingEnabled();
private:
void RenderTextureView(FCanvasTexture* tex, std::function<void(IntRect &)> renderFunc) override;
void PrintStartupLog();

View file

@ -165,7 +165,7 @@ void HWDrawInfo::StartScene(FRenderViewpoint &parentvp, HWViewpointUniforms *uni
VPUniforms.mPalLightLevels = static_cast<int>(gl_bandedswlight) | (static_cast<int>(gl_fogmode) << 8) | ((int)lightmode << 16);
}
VPUniforms.mClipLine.X = -10000000.0f;
VPUniforms.mShadowmapFilter = gl_shadowmap_filter;
VPUniforms.mShadowmapFilter = gl_light_raytrace ? -1 - static_cast<int>(gl_shadowmap_filter) : static_cast<int>(gl_shadowmap_filter);
VPUniforms.mLightBlendMode = (level.info ? (int)level.info->lightblendmode : 0);
}
mClipper->SetViewpoint(Viewpoint);

View file

@ -387,19 +387,15 @@ vec2 softshadow[9 * 3] = vec2[](
vec2(-0.25, 0.75)
);
float shadowAttenuation(vec4 lightpos, float lightcolorA)
float traceShadow(vec4 lightpos, int quality)
{
float shadowIndex = abs(lightcolorA) - 1.0;
if (shadowIndex >= 1024.0)
return 1.0; // Don't cast rays for this light
vec3 origin = pixelpos.xzy;
vec3 target = lightpos.xzy + 0.01; // nudge light position slightly as Doom maps tend to have their lights perfectly aligned with planes
vec3 direction = normalize(target - origin);
float dist = distance(origin, target);
if (uShadowmapFilter <= 0)
if (quality == 0)
{
return traceHit(origin, direction, dist) ? 0.0 : 1.0;
}
@ -410,7 +406,7 @@ float shadowAttenuation(vec4 lightpos, float lightcolorA)
vec3 ydir = cross(direction, xdir);
float sum = 0.0;
int step_count = uShadowmapFilter * 9;
int step_count = quality * 9;
for (int i = 0; i <= step_count; i++)
{
vec3 pos = target + xdir * softshadow[i].x + ydir * softshadow[i].y;
@ -421,6 +417,14 @@ float shadowAttenuation(vec4 lightpos, float lightcolorA)
}
#else
float traceShadow(vec4 lightpos, int quality)
{
return 1.0;
}
#endif
#ifdef SUPPORTS_SHADOWMAPS
float shadowDirToU(vec2 dir)
@ -530,9 +534,6 @@ float sampleShadowmapPCF(vec3 planePoint, float v)
float shadowmapAttenuation(vec4 lightpos, float shadowIndex)
{
if (shadowIndex >= 1024.0)
return 1.0; // No shadowmap available for this light
vec3 planePoint = pixelpos.xyz - lightpos.xyz;
planePoint += 0.01; // nudge light position slightly as Doom maps tend to have their lights perfectly aligned with planes
@ -541,7 +542,7 @@ float shadowmapAttenuation(vec4 lightpos, float shadowIndex)
float v = (shadowIndex + 0.5) / 1024.0;
if (uShadowmapFilter <= 0)
if (uShadowmapFilter == 0)
{
return sampleShadowmap(planePoint, v);
}
@ -554,6 +555,12 @@ float shadowmapAttenuation(vec4 lightpos, float shadowIndex)
float shadowAttenuation(vec4 lightpos, float lightcolorA)
{
float shadowIndex = abs(lightcolorA) - 1.0;
if (shadowIndex >= 1024.0)
return 1.0; // No shadowmap available for this light
if (uShadowmapFilter < 0)
return traceShadow(lightpos, 1 - uShadowmapFilter);
return shadowmapAttenuation(lightpos, shadowIndex);
}
@ -564,7 +571,6 @@ float shadowAttenuation(vec4 lightpos, float lightcolorA)
return 1.0;
}
#endif
#endif
float spotLightAttenuation(vec4 lightpos, vec3 spotdir, float lightCosInnerAngle, float lightCosOuterAngle)