rendering updates

This commit is contained in:
Turanszki Janos
2021-01-21 21:49:11 +01:00
parent 7eac47cc1e
commit 6d543bcf82
22 changed files with 139 additions and 76 deletions
+1
View File
@@ -77,6 +77,7 @@ add_library(WickedEngine STATIC
wiVersion.cpp
wiWidget.cpp
wiXInput.cpp
wiBlueNoise.cpp
)
target_include_directories(WickedEngine PUBLIC
+21 -12
View File
@@ -713,8 +713,6 @@ void RenderPath3D::Render() const
RenderAO(cmd);
RenderSSR(cmd);
if (wiRenderer::GetVariableRateShadingClassification() && device->CheckCapability(GRAPHICSDEVICE_CAPABILITY_VARIABLE_RATE_SHADING_TIER2))
{
wiRenderer::ComputeShadingRateClassification(
@@ -773,7 +771,7 @@ void RenderPath3D::Render() const
}
// Shadow maps:
if (getShadowsEnabled() && !wiRenderer::GetRaytracedShadowsEnabled())
if (getShadowsEnabled())
{
cmd = device->BeginCommandList();
wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) {
@@ -846,12 +844,11 @@ void RenderPath3D::Render() const
});
}
// Opaque scene + Light culling:
// Lighting effects:
cmd = device->BeginCommandList();
wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) {
GraphicsDevice* device = wiRenderer::GetDevice();
device->EventBegin("Opaque Scene", cmd);
wiRenderer::UpdateCameraCB(
*camera,
@@ -860,8 +857,6 @@ void RenderPath3D::Render() const
cmd
);
device->UnbindResources(TEXSLOT_ONDEMAND0, 1, cmd);
{
auto range = wiProfiler::BeginRangeGPU("Entity Culling", cmd);
wiRenderer::ComputeTiledLightCulling(
@@ -879,6 +874,8 @@ void RenderPath3D::Render() const
wiProfiler::EndRange(range);
}
RenderSSR(cmd);
if (wiRenderer::GetRaytracedShadowsEnabled())
{
wiRenderer::Postprocess_RTShadow(
@@ -891,12 +888,15 @@ void RenderPath3D::Render() const
rtShadow,
cmd
);
device->BindResource(PS, &rtShadow, TEXSLOT_RENDERPATH_RTSHADOW, cmd);
}
else
{
device->BindResource(PS, wiTextureHelper::getUINT4(), TEXSLOT_RENDERPATH_RTSHADOW, cmd);
}
});
// Opaque scene:
cmd = device->BeginCommandList();
wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) {
GraphicsDevice* device = wiRenderer::GetDevice();
device->EventBegin("Opaque Scene", cmd);
device->RenderPassBegin(&renderpass_main, cmd);
@@ -907,6 +907,15 @@ void RenderPath3D::Render() const
vp.Height = (float)depthBuffer_Main.GetDesc().Height;
device->BindViewports(1, &vp, cmd);
if (wiRenderer::GetRaytracedShadowsEnabled())
{
device->BindResource(PS, &rtShadow, TEXSLOT_RENDERPATH_RTSHADOW, cmd);
}
else
{
device->BindResource(PS, wiTextureHelper::getUINT4(), TEXSLOT_RENDERPATH_RTSHADOW, cmd);
}
device->BindResource(PS, &entityTiles_Opaque, TEXSLOT_RENDERPATH_ENTITYTILES, cmd);
device->BindResource(PS, getReflectionsEnabled() ? &rtReflection : wiTextureHelper::getTransparent(), TEXSLOT_RENDERPATH_REFLECTION, cmd);
device->BindResource(PS, getAOEnabled() ? &rtAO : wiTextureHelper::getWhite(), TEXSLOT_RENDERPATH_AO, cmd);
@@ -541,6 +541,7 @@
<ClCompile Include="$(MSBuildThisFileDirectory)wiArchive.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)wiAudio.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)wiAudio_BindLua.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)wiBlueNoise.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)wiEvent.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)wiFFTGenerator.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)wiGPUBVH.cpp" />
@@ -1883,6 +1883,9 @@
<ClCompile Include="$(MSBuildThisFileDirectory)Utility\spirv_reflect.c">
<Filter>UTILITY</Filter>
</ClCompile>
<ClCompile Include="$(MSBuildThisFileDirectory)wiBlueNoise.cpp">
<Filter>ENGINE\Helpers</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Text Include="$(MSBuildThisFileDirectory)ArchiveVersionHistory.txt" />
+4 -4
View File
@@ -98,7 +98,7 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(VULKAN_SDK)/Include;BULLET;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>BULLET;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<MinimalRebuild>false</MinimalRebuild>
<IntrinsicFunctions>true</IntrinsicFunctions>
@@ -134,7 +134,7 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(VULKAN_SDK)/Include;BULLET;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>BULLET;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<MinimalRebuild>false</MinimalRebuild>
<IntrinsicFunctions>true</IntrinsicFunctions>
@@ -172,7 +172,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(VULKAN_SDK)/Include;BULLET;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>BULLET;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
@@ -205,7 +205,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(VULKAN_SDK)/Include;BULLET;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>BULLET;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
+3 -5
View File
@@ -107,7 +107,7 @@ struct Surface
alphaRoughness = roughness * roughness;
alphaRoughnessSq = alphaRoughness * alphaRoughness;
NdotV = abs(dot(N, V)) + 1e-5;
NdotV = saturate(abs(dot(N, V)) + 1e-5);
f90 = saturate(50.0 * dot(f0, 0.33));
R = -reflect(V, N);
@@ -130,7 +130,6 @@ struct SurfaceToLight
float3 H; // half-vector between view vector and light vector
float NdotL; // cos angle between normal and light direction
float3 NdotL_sss; // NdotL with subsurface parameters applied
float NdotV; // cos angle between normal and view direction
float NdotH; // cos angle between normal and half vector
float LdotH; // cos angle between light direction and half vector
float VdotH; // cos angle between view direction and half vector
@@ -155,7 +154,6 @@ struct SurfaceToLight
NdotL_sss = (NdotL + surface.sss.rgb) * surface.sss_inv.rgb;
NdotV = saturate(dot(surface.N, surface.V));
NdotH = saturate(dot(surface.N, H));
LdotH = saturate(dot(L, H));
VdotH = saturate(dot(surface.V, H));
@@ -193,8 +191,8 @@ struct SurfaceToLight
// see https://google.github.io/filament/Filament.md.html#materialsystem/specularbrdf/geometricshadowing(specularg)
float visibilityOcclusion(in Surface surface, in SurfaceToLight surfaceToLight)
{
float GGXV = surfaceToLight.NdotL * sqrt(surfaceToLight.NdotV * surfaceToLight.NdotV * (1.0 - surface.alphaRoughnessSq) + surface.alphaRoughnessSq);
float GGXL = surfaceToLight.NdotV * sqrt(surfaceToLight.NdotL * surfaceToLight.NdotL * (1.0 - surface.alphaRoughnessSq) + surface.alphaRoughnessSq);
float GGXV = surfaceToLight.NdotL * sqrt(surface.NdotV * surface.NdotV * (1.0 - surface.alphaRoughnessSq) + surface.alphaRoughnessSq);
float GGXL = surface.NdotV * sqrt(surfaceToLight.NdotL * surfaceToLight.NdotL * (1.0 - surface.alphaRoughnessSq) + surface.alphaRoughnessSq);
float GGX = GGXV + GGXL;
if (GGX > 0.0)
+9 -5
View File
@@ -1,5 +1,6 @@
#define DISABLE_DECALS
#define DISABLE_ENVMAPS
#define RAYTRACED_SHADOWS_ENABLED
#include "globals.hlsli"
#include "objectHF.hlsli"
#include "hairparticleHF.hlsli"
@@ -29,14 +30,17 @@ GBuffer main(VertexToPixel input)
Lighting lighting;
lighting.create(0, 0, GetAmbient(surface.N), 0);
#ifdef RAYTRACED_SHADOWS_ENABLED
[branch]
if (g_xFrame_Options & OPTION_BIT_RAYTRACED_SHADOWS)
{
lighting.shadow_mask = texture_rtshadow[surface.pixel];
}
#endif // RAYTRACED_SHADOWS_ENABLED
float depth = input.pos.z;
float3 reflection = 0;
float2 ScreenCoord = surface.pixel * g_xFrame_InternalResolution_rcp;
float2 pos2D = ScreenCoord * 2 - 1;
pos2D.y *= -1;
float2 velocity = ((input.pos2DPrev.xy / input.pos2DPrev.w - g_xFrame_TemporalAAJitterPrev) - (pos2D.xy - g_xFrame_TemporalAAJitter)) * float2(0.5f, -0.5f);
TiledLighting(surface, lighting);
ApplyLighting(surface, lighting, color);
+8 -2
View File
@@ -3,10 +3,16 @@
TEXTURE2D(texture_color, float4, TEXSLOT_ONDEMAND0);
void main(VertexToPixel input)
float2 main(VertexToPixel input) : SV_TARGET
{
clip(dither(input.pos.xy + GetTemporalAASampleRotation()) - input.fade);
float4 color = texture_color.Sample(sampler_linear_clamp,input.tex);
clip(color.a - 0.5f);
clip(color.a - g_xMaterial.alphaTest);
float2 ScreenCoord = input.pos.xy * g_xFrame_InternalResolution_rcp;
float2 pos2D = ScreenCoord * 2 - 1;
pos2D.y *= -1;
float2 velocity = ((input.pos2DPrev.xy / input.pos2DPrev.w - g_xFrame_TemporalAAJitterPrev) - (pos2D.xy - g_xFrame_TemporalAAJitter)) * float2(0.5f, -0.5f);
return velocity;
}
+18
View File
@@ -186,6 +186,7 @@ inline void DirectionalLight(in ShaderEntity light, in Surface surface, inout Li
[branch]
if (light.IsCastingShadow())
{
#ifdef RAYTRACED_SHADOWS_ENABLED
[branch]
if (g_xFrame_Options & OPTION_BIT_RAYTRACED_SHADOWS)
{
@@ -199,6 +200,7 @@ inline void DirectionalLight(in ShaderEntity light, in Surface surface, inout Li
#endif // RAYTRACING_INLINE
}
else
#endif // RAYTRACED_SHADOWS_ENABLED
{
// Loop through cascades from closest (smallest) to furthest (biggest)
[loop]
@@ -258,6 +260,8 @@ inline void DirectionalLight(in ShaderEntity light, in Surface surface, inout Li
}
}
#ifdef RAYTRACED_SHADOWS_ENABLED
#ifndef RAYTRACING_INLINE
[branch]
if (light.IsCastingShadow())
{
@@ -269,6 +273,8 @@ inline void DirectionalLight(in ShaderEntity light, in Surface surface, inout Li
// Read more about this in rtshadowLIB.hlsl file (**)
lighting.shadow_index++;
}
#endif // RAYTRACING_INLINE
#endif // RAYTRACED_SHADOWS_ENABLED
}
inline void PointLight(in ShaderEntity light, in Surface surface, inout Lighting lighting)
{
@@ -294,6 +300,7 @@ inline void PointLight(in ShaderEntity light, in Surface surface, inout Lighting
[branch]
if (light.IsCastingShadow())
{
#ifdef RAYTRACED_SHADOWS_ENABLED
[branch]
if (g_xFrame_Options & OPTION_BIT_RAYTRACED_SHADOWS)
{
@@ -307,6 +314,7 @@ inline void PointLight(in ShaderEntity light, in Surface surface, inout Lighting
#endif // RAYTRACING_INLINE
}
else
#endif // RAYTRACED_SHADOWS_ENABLED
{
shadow *= shadowCube(light, L, Lunnormalized);
}
@@ -330,6 +338,8 @@ inline void PointLight(in ShaderEntity light, in Surface surface, inout Lighting
}
}
#ifdef RAYTRACED_SHADOWS_ENABLED
#ifndef RAYTRACING_INLINE
[branch]
if (light.IsCastingShadow())
{
@@ -341,6 +351,8 @@ inline void PointLight(in ShaderEntity light, in Surface surface, inout Lighting
// Read more about this in rtshadowLIB.hlsl file (**)
lighting.shadow_index++;
}
#endif // RAYTRACING_INLINE
#endif // RAYTRACED_SHADOWS_ENABLED
}
inline void SpotLight(in ShaderEntity light, in Surface surface, inout Lighting lighting)
{
@@ -371,6 +383,7 @@ inline void SpotLight(in ShaderEntity light, in Surface surface, inout Lighting
[branch]
if (light.IsCastingShadow())
{
#ifdef RAYTRACED_SHADOWS_ENABLED
[branch]
if (g_xFrame_Options & OPTION_BIT_RAYTRACED_SHADOWS)
{
@@ -384,6 +397,7 @@ inline void SpotLight(in ShaderEntity light, in Surface surface, inout Lighting
#endif // RAYTRACING_INLINE
}
else
#endif // RAYTRACED_SHADOWS_ENABLED
{
float4 ShPos = mul(MatrixArray[light.GetMatrixIndex() + 0], float4(surface.P, 1));
ShPos.xyz /= ShPos.w;
@@ -416,6 +430,8 @@ inline void SpotLight(in ShaderEntity light, in Surface surface, inout Lighting
}
}
#ifdef RAYTRACED_SHADOWS_ENABLED
#ifndef RAYTRACING_INLINE
[branch]
if (light.IsCastingShadow())
{
@@ -427,6 +443,8 @@ inline void SpotLight(in ShaderEntity light, in Surface surface, inout Lighting
// Read more about this in rtshadowLIB.hlsl file (**)
lighting.shadow_index++;
}
#endif // RAYTRACING_INLINE
#endif // RAYTRACED_SHADOWS_ENABLED
}
+2 -2
View File
@@ -1486,13 +1486,13 @@ float4 main(PixelInput input) : SV_TARGET
#endif
#ifndef TRANSPARENT
#ifdef RAYTRACED_SHADOWS_ENABLED
[branch]
if (g_xFrame_Options & OPTION_BIT_RAYTRACED_SHADOWS)
{
lighting.shadow_mask = texture_rtshadow[surface.pixel];
}
#endif // TRANSPARENT
#endif // RAYTRACED_SHADOWS_ENABLED
#ifdef FORWARD
+1
View File
@@ -1,5 +1,6 @@
#define OBJECTSHADER_COMPILE_PS
#define OBJECTSHADER_LAYOUT_COMMON
#define RAYTRACED_SHADOWS_ENABLED
#define OUTPUT_GBUFFER
#define TILEDFORWARD
#define DISABLE_ALPHATEST
+1
View File
@@ -1,5 +1,6 @@
#define OBJECTSHADER_COMPILE_PS
#define OBJECTSHADER_LAYOUT_COMMON
#define RAYTRACED_SHADOWS_ENABLED
#define OUTPUT_GBUFFER
#define TILEDFORWARD
#define DISABLE_ALPHATEST
+1
View File
@@ -1,5 +1,6 @@
#define OBJECTSHADER_COMPILE_PS
#define OBJECTSHADER_LAYOUT_COMMON
#define RAYTRACED_SHADOWS_ENABLED
#define OUTPUT_GBUFFER
#define TILEDFORWARD
#define DISABLE_ALPHATEST
@@ -1,5 +1,6 @@
#define OBJECTSHADER_COMPILE_PS
#define OBJECTSHADER_LAYOUT_COMMON
#define RAYTRACED_SHADOWS_ENABLED
#define OUTPUT_GBUFFER
#define TILEDFORWARD
#define DISABLE_ALPHATEST
+1
View File
@@ -1,5 +1,6 @@
#define OBJECTSHADER_COMPILE_PS
#define OBJECTSHADER_LAYOUT_COMMON
#define RAYTRACED_SHADOWS_ENABLED
#define OUTPUT_GBUFFER
#define TILEDFORWARD
#define DISABLE_ALPHATEST
+1
View File
@@ -1,5 +1,6 @@
#define OBJECTSHADER_COMPILE_PS
#define OBJECTSHADER_LAYOUT_COMMON
#define RAYTRACED_SHADOWS_ENABLED
#define OUTPUT_GBUFFER
#define TILEDFORWARD
#define DISABLE_ALPHATEST
+1 -1
View File
@@ -73,11 +73,11 @@ void GetSampleInfo(float2 velocity, float2 neighborUV, float2 uv, float3 P, floa
Surface surface;
surface.alphaRoughnessSq = pow(roughness, 4);
surface.NdotV = NdotV;
SurfaceToLight surfaceToLight;
surfaceToLight.NdotH = NdotH;
surfaceToLight.NdotL = NdotL;
surfaceToLight.NdotV = NdotV;
// Calculate BRDF where Fresnel = 1
float Vis = visibilityOcclusion(surface, surfaceToLight);
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1
View File
@@ -278,6 +278,7 @@ void wiHairParticle::Draw(const CameraComponent& camera, const MaterialComponent
}
device->BindConstantBuffer(VS, &cb, CB_GETBINDSLOT(HairParticleCB), cmd);
device->BindConstantBuffer(PS, &material.constantBuffer, CB_GETBINDSLOT(MaterialCB), cmd);
device->BindResource(VS, &particleBuffer, 0, cmd);
device->BindResource(VS, &culledIndexBuffer, 1, cmd);
+9 -16
View File
@@ -1942,29 +1942,20 @@ void LoadBuffers()
SubresourceData initData;
// Sobol
const uint32_t sobolSequenceLength = uint32_t(sizeof(wiBlueNoise::sobol_256spp_256d) / sizeof(wiBlueNoise::sobol_256spp_256d[0]));
bd.ByteWidth = bd.StructureByteStride * sobolSequenceLength;
initData.pSysMem = &wiBlueNoise::sobol_256spp_256d;
bd.ByteWidth = wiBlueNoise::GetSobolSequenceSize();
initData.pSysMem = wiBlueNoise::GetSobolSequenceData();
device->CreateBuffer(&bd, &initData, &resourceBuffers[RBTYPE_BLUENOISE_SOBOL_SEQUENCE]);
device->SetName(&resourceBuffers[RBTYPE_BLUENOISE_SOBOL_SEQUENCE], "resourceBuffers[RBTYPE_BLUENOISE_SOBOL_SEQUENCE]");
// Scrambling tile
const uint32_t scramblingTileLength = uint32_t(sizeof(wiBlueNoise::scramblingTile) / sizeof(wiBlueNoise::scramblingTile[0]));
bd.ByteWidth = bd.StructureByteStride * scramblingTileLength;
initData.pSysMem = &wiBlueNoise::scramblingTile;
bd.ByteWidth = wiBlueNoise::GetScramblingTileSize();
initData.pSysMem = wiBlueNoise::GetScramblingTileData();
device->CreateBuffer(&bd, &initData, &resourceBuffers[RBTYPE_BLUENOISE_SCRAMBLING_TILE]);
device->SetName(&resourceBuffers[RBTYPE_BLUENOISE_SCRAMBLING_TILE], "resourceBuffers[RBTYPE_BLUENOISE_SCRAMBLING_TILE]");
// Ranking tile
const uint32_t rankingTileLength = uint32_t(sizeof(wiBlueNoise::rankingTile) / sizeof(wiBlueNoise::rankingTile[0]));
bd.ByteWidth = bd.StructureByteStride * rankingTileLength;
initData.pSysMem = &wiBlueNoise::rankingTile;
bd.ByteWidth = wiBlueNoise::GetRankingTileSize();
initData.pSysMem = wiBlueNoise::GetRankingTileData();
device->CreateBuffer(&bd, &initData, &resourceBuffers[RBTYPE_BLUENOISE_RANKING_TILE]);
device->SetName(&resourceBuffers[RBTYPE_BLUENOISE_RANKING_TILE], "resourceBuffers[RBTYPE_BLUENOISE_RANKING_TILE]");
}
@@ -2715,7 +2706,7 @@ void RenderMeshes(
{
if (frusta != nullptr && !frusta[frustum_index].CheckBoxFast(instanceAABB))
{
// In case shadow cameras were provided and no intersection detected with frustum, we don't add the instance for the face:
// In case multiple cameras were provided and no intersection detected with frustum, we don't add the instance for the face:
continue;
}
@@ -2803,6 +2794,8 @@ void RenderMeshes(
instancedBatch.dataOffset
};
static_assert(arraysize(vbs) == INPUT_SLOT_COUNT, "This layout must conform to OBJECT_VERTEXINPUT enum!");
static_assert(arraysize(vbs) == arraysize(strides), "Mismatch between vertex buffers and strides!");
static_assert(arraysize(vbs) == arraysize(offsets), "Mismatch between vertex buffers and offsets!");
device->BindVertexBuffers(vbs, 0, arraysize(vbs), strides, offsets, cmd);
for (const MeshComponent::MeshSubset& subset : mesh.subsets)
+1 -1
View File
@@ -9,7 +9,7 @@ namespace wiVersion
// minor features, major updates, breaking compatibility changes
const int minor = 52;
// minor bug fixes, alterations, refactors, updates
const int revision = 3;
const int revision = 4;
const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);