diff --git a/imgui.ini b/imgui.ini index ab70a0b0..3c74e25c 100644 --- a/imgui.ini +++ b/imgui.ini @@ -1,162 +1,176 @@ -[Window][DockspaceViewport_11111111] -Pos=0,21 -Size=1280,699 -Collapsed=0 - -[Window][Debug##Default] -Pos=1022,401 -Size=228,150 -Collapsed=1 - -[Window][Theme] -Pos=1032,376 -Size=248,201 -Collapsed=0 -DockId=0x00000009,0 - -[Window][ImGui Details] -Pos=1032,607 -Size=248,113 -Collapsed=0 - -[Window][Camera Settings] -Pos=0,342 -Size=270,378 -Collapsed=0 -DockId=0x00000008,0 - -[Window][Light Editor] -Pos=0,21 -Size=32,32 -Collapsed=0 - -[Window][Shader Registry] -Pos=340,105 -Size=590,455 -Collapsed=0 - -[Window][Pipeline Registry] -Pos=317,134 -Size=312,443 -Collapsed=0 - -[Window][Root Signature Registry] -Pos=748,338 -Size=169,259 -Collapsed=0 - -[Window][DirectX 12 Settings] -Pos=1032,376 -Size=248,201 -Collapsed=0 -DockId=0x00000009,2 - -[Window][Hardware Info] -Pos=1032,376 -Size=248,201 -Collapsed=0 -DockId=0x00000009,1 - -[Window][Model Editor] -Pos=0,31 -Size=32,32 -Collapsed=0 - -[Window][Light Details] -Pos=0,403 -Size=220,129 -Collapsed=0 - -[Window][Inspect] -Pos=26,21 -Size=32,32 -Collapsed=0 - -[Window][Viewport] -Pos=272,21 -Size=758,699 -Collapsed=0 -DockId=0x00000002,0 - -[Window][Scene Graph Editor] -Pos=0,21 -Size=270,319 -Collapsed=0 -DockId=0x00000007,1 - -[Window][Inspector] -Pos=1032,21 -Size=248,353 -Collapsed=0 -DockId=0x00000006,0 - -[Window][DockSpaceViewport_11111111] -Pos=0,21 -Size=1280,699 -Collapsed=0 - -[Window][Stats] -Pos=280,121 -Size=205,85 -Collapsed=0 - -[Window][Test popup] -ViewportPos=1503,395 -ViewportId=0xB4FE7E97 -Size=151,177 -Collapsed=0 - -[Window][Emissive Multiplier] -Pos=944,589 -Size=303,134 -Collapsed=0 - -[Window][RTAO Settings] -Pos=1032,579 -Size=248,141 -Collapsed=0 -DockId=0x0000000A,0 - -[Window][HBAO+ Settings] -Pos=1032,579 -Size=248,141 -Collapsed=0 -DockId=0x0000000A,0 - -[Window][NVIDIA Ansel Settings] -Pos=1032,376 -Size=248,201 -Collapsed=0 -DockId=0x00000009,3 - -[Window][Acceleration Structure Settings] -Pos=1032,579 -Size=248,141 -Collapsed=0 -DockId=0x0000000A,1 - -[Window][Shadow Settings] -Pos=1032,579 -Size=248,141 -Collapsed=0 -DockId=0x0000000A,2 - -[Window][Demo Scene] -Pos=0,21 -Size=270,319 -Collapsed=0 -DockId=0x00000007,0 - -[Docking][Data] -DockSpace ID=0x8B93E3BD Pos=0,21 Size=1280,699 Split=X - DockNode ID=0x00000003 Parent=0x8B93E3BD SizeRef=1030,699 Split=X - DockNode ID=0x00000001 Parent=0x00000003 SizeRef=270,699 Split=Y SelectedTab=0xF4865B00 - DockNode ID=0x00000007 Parent=0x00000001 SizeRef=219,319 SelectedTab=0xF4865B00 - DockNode ID=0x00000008 Parent=0x00000001 SizeRef=219,378 SelectedTab=0x8722C6A1 - DockNode ID=0x00000002 Parent=0x00000003 SizeRef=758,699 CentralNode=1 SelectedTab=0x995B0CF8 - DockNode ID=0x00000004 Parent=0x8B93E3BD SizeRef=248,699 Split=Y SelectedTab=0x070A839D - DockNode ID=0x00000006 Parent=0x00000004 SizeRef=248,353 SelectedTab=0xF02CD328 - DockNode ID=0x00000005 Parent=0x00000004 SizeRef=248,344 Split=Y SelectedTab=0xDA48A090 - DockNode ID=0x00000009 Parent=0x00000005 SizeRef=248,201 SelectedTab=0x4BB5AED3 - DockNode ID=0x0000000A Parent=0x00000005 SizeRef=248,141 SelectedTab=0xDCA1C528 - +[Window][DockspaceViewport_11111111] +Pos=0,21 +Size=1280,699 +Collapsed=0 + +[Window][Debug##Default] +Pos=1022,401 +Size=228,150 +Collapsed=1 + +[Window][Theme] +Pos=1032,222 +Size=248,219 +Collapsed=0 +DockId=0x00000009,0 + +[Window][ImGui Details] +Pos=1032,607 +Size=248,113 +Collapsed=0 + +[Window][Camera Settings] +Pos=0,342 +Size=270,378 +Collapsed=0 +DockId=0x00000008,0 + +[Window][Light Editor] +Pos=0,21 +Size=32,32 +Collapsed=0 + +[Window][Shader Registry] +Pos=340,105 +Size=590,455 +Collapsed=0 + +[Window][Pipeline Registry] +Pos=317,134 +Size=312,443 +Collapsed=0 + +[Window][Root Signature Registry] +Pos=748,338 +Size=169,259 +Collapsed=0 + +[Window][DirectX 12 Settings] +Pos=1032,222 +Size=248,219 +Collapsed=0 +DockId=0x00000009,2 + +[Window][Hardware Info] +Pos=1032,222 +Size=248,219 +Collapsed=0 +DockId=0x00000009,1 + +[Window][Model Editor] +Pos=0,31 +Size=32,32 +Collapsed=0 + +[Window][Light Details] +Pos=0,403 +Size=220,129 +Collapsed=0 + +[Window][Inspect] +Pos=26,21 +Size=32,32 +Collapsed=0 + +[Window][Viewport] +Pos=272,21 +Size=758,699 +Collapsed=0 +DockId=0x00000002,0 + +[Window][Scene Graph Editor] +Pos=0,21 +Size=270,319 +Collapsed=0 +DockId=0x00000007,1 + +[Window][Inspector] +Pos=1032,21 +Size=248,199 +Collapsed=0 +DockId=0x00000006,0 + +[Window][DockSpaceViewport_11111111] +Pos=0,21 +Size=1280,699 +Collapsed=0 + +[Window][Stats] +Pos=280,121 +Size=205,85 +Collapsed=0 + +[Window][Test popup] +ViewportPos=1503,395 +ViewportId=0xB4FE7E97 +Size=151,177 +Collapsed=0 + +[Window][Emissive Multiplier] +Pos=944,589 +Size=303,134 +Collapsed=0 + +[Window][RTAO Settings] +Pos=1032,443 +Size=248,121 +Collapsed=0 +DockId=0x0000000B,0 + +[Window][HBAO+ Settings] +Pos=1032,443 +Size=248,277 +Collapsed=0 +DockId=0x0000000B,0 + +[Window][NVIDIA Ansel Settings] +Pos=1032,222 +Size=248,219 +Collapsed=0 +DockId=0x00000009,3 + +[Window][Acceleration Structure Settings] +Pos=1032,566 +Size=248,154 +Collapsed=0 +DockId=0x0000000C,0 + +[Window][Shadow Settings] +Pos=1032,443 +Size=248,121 +Collapsed=0 +DockId=0x0000000B,1 + +[Window][Demo Scene] +Pos=0,21 +Size=270,319 +Collapsed=0 +DockId=0x00000007,0 + +[Window][Path Tracing Settings] +Pos=1548,797 +Size=372,220 +Collapsed=0 +DockId=0x0000000C,1 + +[Window][Recorder] +Pos=1032,21 +Size=248,199 +Collapsed=0 +DockId=0x00000006,1 + +[Docking][Data] +DockSpace ID=0x8B93E3BD Pos=0,21 Size=1280,699 Split=X + DockNode ID=0x00000003 Parent=0x8B93E3BD SizeRef=1030,699 Split=X + DockNode ID=0x00000001 Parent=0x00000003 SizeRef=270,699 Split=Y SelectedTab=0xF4865B00 + DockNode ID=0x00000007 Parent=0x00000001 SizeRef=219,319 SelectedTab=0xF4865B00 + DockNode ID=0x00000008 Parent=0x00000001 SizeRef=219,378 SelectedTab=0x8722C6A1 + DockNode ID=0x00000002 Parent=0x00000003 SizeRef=758,699 CentralNode=1 SelectedTab=0x995B0CF8 + DockNode ID=0x00000004 Parent=0x8B93E3BD SizeRef=248,699 Split=Y SelectedTab=0x070A839D + DockNode ID=0x00000006 Parent=0x00000004 SizeRef=248,199 SelectedTab=0xF02CD328 + DockNode ID=0x00000005 Parent=0x00000004 SizeRef=248,498 Split=Y SelectedTab=0xDA48A090 + DockNode ID=0x00000009 Parent=0x00000005 SizeRef=248,219 SelectedTab=0x4BB5AED3 + DockNode ID=0x0000000A Parent=0x00000005 SizeRef=248,277 Split=Y SelectedTab=0x23DB2B59 + DockNode ID=0x0000000B Parent=0x0000000A SizeRef=248,121 SelectedTab=0x23DB2B59 + DockNode ID=0x0000000C Parent=0x0000000A SizeRef=248,154 SelectedTab=0xA06991A0 + diff --git a/resources/shaders/dxr_ambient_occlusion.hlsl b/resources/shaders/dxr_ambient_occlusion.hlsl index 7bfdf483..ae2ee612 100644 --- a/resources/shaders/dxr_ambient_occlusion.hlsl +++ b/resources/shaders/dxr_ambient_occlusion.hlsl @@ -18,15 +18,29 @@ #include "rand_util.hlsl" #include "dxr_global.hlsl" +#include "dxr_functions.hlsl" +#include "dxr_structs.hlsl" +#include "material_util.hlsl" RWTexture2D output : register(u0); // x: AO value -Texture2D gbuffer_normal : register(t1); -Texture2D gbuffer_depth : register(t2); + +ByteAddressBuffer g_indices : register(t1); +StructuredBuffer g_vertices : register(t2); +StructuredBuffer g_materials : register(t3); +StructuredBuffer g_offsets : register(t4); + +Texture2D g_textures[1000] : register(t5); +Texture2D gbuffer_normal : register(t1005); +Texture2D gbuffer_depth : register(t1006); + +SamplerState s0 : register(s0); + +typedef BuiltInTriangleIntersectionAttributes Attributes; struct AOHitInfo { float is_hit; - float thisvariablesomehowmakeshybridrenderingwork_killme; + float padding_for_fallback; }; cbuffer CBData : register(b0) @@ -44,17 +58,32 @@ cbuffer CBData : register(b0) unsigned int sample_count; }; -struct Attributes { }; - -float3 unpack_position(float2 uv, float depth) +bool TraceAORay(uint idx, float3 origin, float3 direction, float far, unsigned int depth) { - // Get world space position - const float4 ndc = float4(uv * 2.0 - 1.0, depth, 1.0); - float4 wpos = mul(inv_vp, ndc); - return (wpos.xyz / wpos.w).xyz; + // Define a ray, consisting of origin, direction, and the min-max distance values + RayDesc ray; + ray.Origin = origin; + ray.Direction = direction; + ray.TMin = 0.f; + ray.TMax = far; + + AOHitInfo payload = { 1.0f, 0.0f }; + + // Trace the ray + TraceRay( + Scene, + RAY_FLAG_NONE, + ~0, // InstanceInclusionMask + 0, // RayContributionToHitGroupIndex + 0, // MultiplierForGeometryContributionToHitGroupIndex + 0, // miss shader index is set to idx but can probably be anything. + ray, + payload); + + return payload.is_hit; } -bool TraceAORay(uint idx, float3 origin, float3 direction, float far, unsigned int depth) +bool TraceAORay_SkipClosestHit(uint idx, float3 origin, float3 direction, float far, unsigned int depth) { // Define a ray, consisting of origin, direction, and the min-max distance values RayDesc ray; @@ -79,9 +108,43 @@ bool TraceAORay(uint idx, float3 origin, float3 direction, float far, unsigned i return payload.is_hit; } - [shader("raygeneration")] void AORaygenEntry() +{ + // Texture UV coordinates [0, 1] + float2 uv = float2(DispatchRaysIndex().xy) / float2(DispatchRaysDimensions().xy - 1); + + uint rand_seed = initRand(DispatchRaysIndex().x + DispatchRaysIndex().y * DispatchRaysDimensions().x, frame_idx); + + // Screen coordinates [0, resolution] (inverted y) + int2 screen_co = DispatchRaysIndex().xy; + + float3 normal = gbuffer_normal[screen_co].xyz; + float depth = gbuffer_depth[screen_co].x; + float3 wpos = unpack_position(float2(uv.x, 1.f - uv.y), depth, inv_vp); + + float3 camera_pos = float3(inv_view[0][3], inv_view[1][3], inv_view[2][3]); + float cam_distance = length(wpos - camera_pos); + if (cam_distance < max_distance) + { + //SPP decreases the closer a pixel is to the max distance + //Total is always calculated using the full sample count to have further pixels less occluded + int spp = min(sample_count, round(sample_count * ((max_distance - cam_distance) / max_distance))); + int ao_value = sample_count; + for (uint i = 0; i < spp; i++) + { + ao_value -= TraceAORay_SkipClosestHit(0, wpos + normal * bias, getCosHemisphereSample(rand_seed, normal), radius, 0); + } + output[DispatchRaysIndex().xy].x = pow(ao_value / float(sample_count), power); + } + else + { + output[DispatchRaysIndex().xy].x = 1.f; + } +} + +[shader("raygeneration")] +void AORaygenEntry_Transparency() { // Texture UV coordinates [0, 1] float2 uv = float2(DispatchRaysIndex().xy) / float2(DispatchRaysDimensions().xy - 1); @@ -93,7 +156,7 @@ void AORaygenEntry() float3 normal = gbuffer_normal[screen_co].xyz; float depth = gbuffer_depth[screen_co].x; - float3 wpos = unpack_position(float2(uv.x, 1.f - uv.y), depth); + float3 wpos = unpack_position(float2(uv.x, 1.f - uv.y), depth, inv_vp); float3 camera_pos = float3(inv_view[0][3], inv_view[1][3], inv_view[2][3]); float cam_distance = length(wpos-camera_pos); @@ -101,9 +164,9 @@ void AORaygenEntry() { //SPP decreases the closer a pixel is to the max distance //Total is always calculated using the full sample count to have further pixels less occluded - int spp = min(sample_count, round(sample_count * ((max_distance - cam_distance)/max_distance))); + int spp = min(sample_count, round(sample_count * ((max_distance - cam_distance) / max_distance))); int ao_value = sample_count; - for(uint i = 0; i< spp; i++) + for(uint i = 0; i < spp; i++) { ao_value -= TraceAORay(0, wpos + normal * bias , getCosHemisphereSample(rand_seed, normal), radius, 0); } @@ -113,13 +176,74 @@ void AORaygenEntry() { output[DispatchRaysIndex().xy].x = 1.f; } +} +[shader("closesthit")] +void AOClosestHitEntry(inout AOHitInfo hit, in Attributes attr) +{ + hit.is_hit = 1.0f; } [shader("miss")] -void MissEntry(inout AOHitInfo hit : SV_RayPayload) +void AOMissEntry(inout AOHitInfo hit : SV_RayPayload) { hit.is_hit = 0.0f; } +[shader("anyhit")] +void AOAnyHitEntry(inout AOHitInfo hit, in Attributes attr) +{ +#ifndef FALLBACK + // Calculate the essentials + const Offset offset = g_offsets[InstanceID()]; + const Material material = g_materials[offset.material_idx]; + const float index_offset = offset.idx_offset; + const float vertex_offset = offset.vertex_offset; + + // Find first index location + const uint index_size = 4; + const uint indices_per_triangle = 3; + const uint triangle_idx_stride = indices_per_triangle * index_size; + + uint base_idx = PrimitiveIndex() * triangle_idx_stride; + base_idx += index_offset * 4; // offset the start + + uint3 indices = Load3x32BitIndices(g_indices, base_idx); + indices += float3(vertex_offset, vertex_offset, vertex_offset); // offset the start + + // Gather triangle vertices + const Vertex v0 = g_vertices[indices.x]; + const Vertex v1 = g_vertices[indices.y]; + const Vertex v2 = g_vertices[indices.z]; + + //Get data from VBO + float2 uv = HitAttribute(float3(v0.uv, 0), float3(v1.uv, 0), float3(v2.uv, 0), attr).xy; + uv.y = 1.0f - uv.y; + + OutputMaterialData output_data = InterpretMaterialDataRT(material.data, + g_textures[material.albedo_id], + g_textures[material.normal_id], + g_textures[material.roughness_id], + g_textures[material.metalicness_id], + g_textures[material.emissive_id], + g_textures[material.ao_id], + 0, + s0, + uv); + + float alpha = output_data.alpha; + + if (alpha < 0.5f) + { + IgnoreHit(); + } + else + { + AcceptHitAndEndSearch(); + } +#else + AcceptHitAndEndSearch(); +#endif +} + #endif //__DXR_AMBIENT_OCCLUSION_HLSL__ \ No newline at end of file diff --git a/resources/shaders/dxr_pathtracer_entries.hlsl b/resources/shaders/dxr_pathtracer_entries.hlsl index 6e4d3f03..a8b39279 100644 --- a/resources/shaders/dxr_pathtracer_entries.hlsl +++ b/resources/shaders/dxr_pathtracer_entries.hlsl @@ -98,4 +98,60 @@ void ReflectionMiss(inout PathTracingHitInfoCone payload) payload.color = skybox.SampleLevel(s0, WorldRayDirection(), 0).rgb; } +[shader("anyhit")] +void ReflectionAnyHit(inout PathTracingHitInfoCone payload, in Attributes attr) +{ +#ifndef FALLBACK + // Calculate the essentials + const Offset offset = g_offsets[InstanceID()]; + const Material material = g_materials[offset.material_idx]; + const float index_offset = offset.idx_offset; + const float vertex_offset = offset.vertex_offset; + + // Find first index location + const uint index_size = 4; + const uint indices_per_triangle = 3; + const uint triangle_idx_stride = indices_per_triangle * index_size; + + uint base_idx = PrimitiveIndex() * triangle_idx_stride; + base_idx += index_offset * 4; // offset the start + + uint3 indices = Load3x32BitIndices(g_indices, base_idx); + indices += float3(vertex_offset, vertex_offset, vertex_offset); // offset the start + + // Gather triangle vertices + const Vertex v0 = g_vertices[indices.x]; + const Vertex v1 = g_vertices[indices.y]; + const Vertex v2 = g_vertices[indices.z]; + + //Get data from VBO + float2 uv = HitAttribute(float3(v0.uv, 0), float3(v1.uv, 0), float3(v2.uv, 0), attr).xy; + uv.y = 1.0f - uv.y; + + OutputMaterialData output_data = InterpretMaterialDataRT(material.data, + g_textures[material.albedo_id], + g_textures[material.normal_id], + g_textures[material.roughness_id], + g_textures[material.metalicness_id], + g_textures[material.emissive_id], + g_textures[material.ao_id], + 0, + s0, + uv); + + float alpha = output_data.alpha; + + if (alpha < 0.5f) + { + IgnoreHit(); + } + else + { + AcceptHitAndEndSearch(); + } +#else + AcceptHitAndEndSearch(); +#endif +} + #endif //__DXR_PATHTRACER_ENTRIES_HLSL__ diff --git a/resources/shaders/dxr_raytracing.hlsl b/resources/shaders/dxr_raytracing.hlsl index f963587e..a5b831f2 100644 --- a/resources/shaders/dxr_raytracing.hlsl +++ b/resources/shaders/dxr_raytracing.hlsl @@ -44,9 +44,10 @@ Texture2D g_textures[1000] : register(t9); SamplerState s0 : register(s0); SamplerState point_sampler : register(s1); -typedef BuiltInTriangleIntersectionAttributes MyAttributes; +typedef BuiltInTriangleIntersectionAttributes Attributes; #include "dxr_pathtracer_functions.hlsl" +#include "dxr_shadow_entries.hlsl" cbuffer CameraProperties : register(b0) { @@ -161,7 +162,7 @@ void MissEntry(inout FullRTHitInfo payload) } [shader("closesthit")] -void ClosestHitEntry(inout FullRTHitInfo payload, in MyAttributes attr) +void ClosestHitEntry(inout FullRTHitInfo payload, in Attributes attr) { // Calculate the essentials const Offset offset = g_offsets[InstanceID()]; @@ -236,16 +237,4 @@ void ClosestHitEntry(inout FullRTHitInfo payload, in MyAttributes attr) payload.color += emissive; } -[shader("closesthit")] -void ShadowClosestHitEntry(inout ShadowHitInfo hit, MyAttributes bary) -{ - hit.is_hit = true; -} - -[shader("miss")] -void ShadowMissEntry(inout ShadowHitInfo hit : SV_RayPayload) -{ - hit.is_hit = false; -} - #endif //__DXR_RAYTRACING_HLSL__ diff --git a/resources/shaders/dxr_reflection_entries.hlsl b/resources/shaders/dxr_reflection_entries.hlsl index e16a1f31..ffb48308 100644 --- a/resources/shaders/dxr_reflection_entries.hlsl +++ b/resources/shaders/dxr_reflection_entries.hlsl @@ -150,4 +150,60 @@ void ReflectionMiss(inout ReflectionHitInfo payload) payload.hit_t = RayTCurrent(); } +[shader("anyhit")] +void ReflectionAnyHit(inout ReflectionHitInfo payload, in Attributes attr) +{ +#ifndef FALLBACK + // Calculate the essentials + const Offset offset = g_offsets[InstanceID()]; + const Material material = g_materials[offset.material_idx]; + const float index_offset = offset.idx_offset; + const float vertex_offset = offset.vertex_offset; + + // Find first index location + const uint index_size = 4; + const uint indices_per_triangle = 3; + const uint triangle_idx_stride = indices_per_triangle * index_size; + + uint base_idx = PrimitiveIndex() * triangle_idx_stride; + base_idx += index_offset * 4; // offset the start + + uint3 indices = Load3x32BitIndices(g_indices, base_idx); + indices += float3(vertex_offset, vertex_offset, vertex_offset); // offset the start + + // Gather triangle vertices + const Vertex v0 = g_vertices[indices.x]; + const Vertex v1 = g_vertices[indices.y]; + const Vertex v2 = g_vertices[indices.z]; + + //Get data from VBO + float2 uv = HitAttribute(float3(v0.uv, 0), float3(v1.uv, 0), float3(v2.uv, 0), attr).xy; + uv.y = 1.0f - uv.y; + + OutputMaterialData output_data = InterpretMaterialDataRT(material.data, + g_textures[material.albedo_id], + g_textures[material.normal_id], + g_textures[material.roughness_id], + g_textures[material.metalicness_id], + g_textures[material.emissive_id], + g_textures[material.ao_id], + 0, + s0, + uv); + + float alpha = output_data.alpha; + + if (alpha < 0.5f) + { + IgnoreHit(); + } + else + { + AcceptHitAndEndSearch(); + } +#else + payload.color = float3(0.0f, 0.0f, 0.0f); +#endif +} + #endif //__DXR_REFLECTION_ENTRIES_HLSL__ diff --git a/resources/shaders/dxr_shadow_entries.hlsl b/resources/shaders/dxr_shadow_entries.hlsl index d682b8c0..a26541c6 100644 --- a/resources/shaders/dxr_shadow_entries.hlsl +++ b/resources/shaders/dxr_shadow_entries.hlsl @@ -36,4 +36,68 @@ void ShadowMissEntry(inout ShadowHitInfo hit : SV_RayPayload) hit.is_hit = false; } +[shader("anyhit")] +void ShadowAnyHitEntry(inout ShadowHitInfo hit, Attributes attr) +{ +#ifndef FALLBACK + // Calculate the essentials + const Offset offset = g_offsets[InstanceID()]; + const Material material = g_materials[offset.material_idx]; + const float index_offset = offset.idx_offset; + const float vertex_offset = offset.vertex_offset; + + // Find first index location + const uint index_size = 4; + const uint indices_per_triangle = 3; + const uint triangle_idx_stride = indices_per_triangle * index_size; + + uint base_idx = PrimitiveIndex() * triangle_idx_stride; + base_idx += index_offset * 4; // offset the start + + uint3 indices = Load3x32BitIndices(g_indices, base_idx); + indices += float3(vertex_offset, vertex_offset, vertex_offset); // offset the start + + // Gather triangle vertices + const Vertex v0 = g_vertices[indices.x]; + const Vertex v1 = g_vertices[indices.y]; + const Vertex v2 = g_vertices[indices.z]; + + //Get data from VBO + float2 uv = HitAttribute(float3(v0.uv, 0), float3(v1.uv, 0), float3(v2.uv, 0), attr).xy; + uv.y = 1.0f - uv.y; + + OutputMaterialData output_data = InterpretMaterialDataRT(material.data, + g_textures[material.albedo_id], + g_textures[material.normal_id], + g_textures[material.roughness_id], + g_textures[material.metalicness_id], + g_textures[material.emissive_id], + g_textures[material.ao_id], + 0, + s0, + uv); + + if (material.data.use_alpha_masking == 1.0f) + { + float alpha = output_data.alpha; + + if (alpha <= 0.5f) + { + IgnoreHit(); + } + else + { + AcceptHitAndEndSearch(); + } + } + else + { + AcceptHitAndEndSearch(); + } + +#else + hit.is_hit = false; +#endif +} + #endif //__DXR_SHADOW_ENTRIES_HLSL__ \ No newline at end of file diff --git a/resources/shaders/dxr_shadow_functions.hlsl b/resources/shaders/dxr_shadow_functions.hlsl index 60bca065..2dfda25d 100644 --- a/resources/shaders/dxr_shadow_functions.hlsl +++ b/resources/shaders/dxr_shadow_functions.hlsl @@ -33,7 +33,7 @@ bool TraceShadowRay(float3 origin, float3 direction, float far, uint calling_pas ray.TMin = 0; ray.TMax = far; - ShadowHitInfo payload = { false, 0 }; + ShadowHitInfo payload = { false, 0.0f }; uint ray_contr_idx = 1; uint miss_idx = 1; diff --git a/resources/shaders/dxr_structs.hlsl b/resources/shaders/dxr_structs.hlsl index 5dc230a2..0de68a33 100644 --- a/resources/shaders/dxr_structs.hlsl +++ b/resources/shaders/dxr_structs.hlsl @@ -91,7 +91,7 @@ struct ReflectionHitInfo struct ShadowHitInfo { float is_hit; - float thisvariablesomehowmakeshybridrenderingwork_killme; + float padding; }; struct PathTracingHitInfo diff --git a/src/d3d12/d3d12_acceleration_structure..cpp b/src/d3d12/d3d12_acceleration_structure..cpp index 79fd25e9..4ff5bce2 100644 --- a/src/d3d12/d3d12_acceleration_structure..cpp +++ b/src/d3d12/d3d12_acceleration_structure..cpp @@ -253,7 +253,8 @@ namespace wr::d3d12 [[nodiscard]] AccelerationStructure CreateBottomLevelAccelerationStructures(Device* device, CommandList* cmd_list, DescriptorHeap* desc_heap, - std::vector geometry) + std::vector geometry, + bool allow_transparency) { AccelerationStructure blas = {}; @@ -281,7 +282,13 @@ namespace wr::d3d12 geometry_descs[i].Triangles.VertexCount = geom.m_num_vertices; geometry_descs[i].Triangles.VertexBuffer.StartAddress = geom.vertex_buffer->m_buffer->GetGPUVirtualAddress() + (geom.m_vertices_offset * geom.m_vertex_stride); geometry_descs[i].Triangles.VertexBuffer.StrideInBytes = geom.m_vertex_stride; - geometry_descs[i].Flags = D3D12_RAYTRACING_GEOMETRY_FLAG_OPAQUE; + geometry_descs[i].Flags = allow_transparency ? D3D12_RAYTRACING_GEOMETRY_FLAG_NONE : D3D12_RAYTRACING_GEOMETRY_FLAG_OPAQUE; + + if (GetRaytracingType(device) == RaytracingType::FALLBACK) + { + geometry_descs[i].Flags = D3D12_RAYTRACING_GEOMETRY_FLAG_OPAQUE; + } + } D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BUILD_FLAGS build_flags = D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BUILD_FLAG_PREFER_FAST_TRACE; diff --git a/src/d3d12/d3d12_functions.hpp b/src/d3d12/d3d12_functions.hpp index 71dcdc83..ce3043f2 100644 --- a/src/d3d12/d3d12_functions.hpp +++ b/src/d3d12/d3d12_functions.hpp @@ -296,7 +296,8 @@ namespace wr::d3d12 [[nodiscard]] AccelerationStructure CreateBottomLevelAccelerationStructures(Device* device, CommandList* cmd_list, DescriptorHeap* desc_heap, - std::vector geometry); + std::vector geometry, + bool allow_transparency); [[nodiscard]] AccelerationStructure CreateTopLevelAccelerationStructure(Device* device, CommandList* cmd_list, @@ -324,6 +325,6 @@ namespace wr::d3d12 std::uint64_t shader_record_size); void AddShaderRecord(ShaderTable* table, ShaderRecord record); void SetName(AccelerationStructure& acceleration_structure, std::wstring name); - void Destroy(ShaderTable* table); + void Destroy(ShaderTable*& table); } /* wr::d3d12 */ diff --git a/src/d3d12/d3d12_shader_table.cpp b/src/d3d12/d3d12_shader_table.cpp index e1608116..338adc9c 100644 --- a/src/d3d12/d3d12_shader_table.cpp +++ b/src/d3d12/d3d12_shader_table.cpp @@ -85,10 +85,11 @@ namespace wr::d3d12 table->m_mapped_shader_records += table->m_shader_record_size; } - void Destroy(ShaderTable* table) + void Destroy(ShaderTable*& table) { SAFE_RELEASE(table->m_resource); delete table; + table = nullptr; } } /* wr::d3d12 */ diff --git a/src/d3d12/d3d12_state_object.cpp b/src/d3d12/d3d12_state_object.cpp index 4d5f8bfb..5ee654bd 100644 --- a/src/d3d12/d3d12_state_object.cpp +++ b/src/d3d12/d3d12_state_object.cpp @@ -54,12 +54,25 @@ namespace wr::d3d12 // Hitgroup { - for (auto def : desc.m_hit_groups) + for (auto& def : desc.m_hit_groups) { + if (d3d12::GetRaytracingType(device) == RaytracingType::FALLBACK) + { + def.m_anyhit = std::nullopt; + } + auto hitGroup = n_desc.CreateSubobject(); - hitGroup->SetClosestHitShaderImport(def.second.c_str()); - hitGroup->SetHitGroupExport(def.first.c_str()); - hitGroup->SetHitGroupType(D3D12_HIT_GROUP_TYPE_TRIANGLES); + + hitGroup->SetHitGroupExport(def.m_hitgroup.c_str()); + + hitGroup->SetClosestHitShaderImport(def.m_closesthit.c_str()); + + if (def.m_anyhit.has_value()) + { + hitGroup->SetAnyHitShaderImport(def.m_anyhit.value().c_str()); + } + + hitGroup->SetHitGroupType(D3D12_HIT_GROUP_TYPE_TRIANGLES);; } } diff --git a/src/d3d12/d3d12_structs.hpp b/src/d3d12/d3d12_structs.hpp index fb2cf05d..95dbea05 100644 --- a/src/d3d12/d3d12_structs.hpp +++ b/src/d3d12/d3d12_structs.hpp @@ -125,11 +125,18 @@ namespace wr::d3d12 std::uint32_t m_vertex_stride = 0u; }; + struct HitGroupDesc + { + std::wstring m_hitgroup; + std::wstring m_closesthit; + std::optional m_anyhit; + }; + struct StateObjectDesc { Shader* m_library = nullptr; std::vector m_library_exports; - std::vector> m_hit_groups; // first = hit group | second = entry + std::vector m_hit_groups; // hitgroup, closesthit and anyhit std::uint32_t max_payload_size = 0u; std::uint32_t max_attributes_size = 0u; diff --git a/src/engine_registry.cpp b/src/engine_registry.cpp index 87f923fc..a80e8fb0 100644 --- a/src/engine_registry.cpp +++ b/src/engine_registry.cpp @@ -588,8 +588,8 @@ namespace wr lib.exports.push_back(L"MissEntry"); lib.exports.push_back(L"ShadowClosestHitEntry"); lib.exports.push_back(L"ShadowMissEntry"); - lib.m_hit_groups.push_back({ L"MyHitGroup", L"ClosestHitEntry" }); - lib.m_hit_groups.push_back({ L"ShadowHitGroup", L"ShadowClosestHitEntry" }); + lib.m_hit_groups.push_back({ L"MyHitGroup", L"ClosestHitEntry"}); + lib.m_hit_groups.push_back({ L"ShadowHitGroup", L"ShadowClosestHitEntry"}); return lib; }(); @@ -1206,6 +1206,10 @@ namespace wr DESC_RANGE_ARRAY(rt_ao_ranges, DESC_RANGE(params::rt_ao, Type::UAV_RANGE, params::RTAOE::OUTPUT), + DESC_RANGE(params::rt_ao, Type::SRV_RANGE, params::RTAOE::INDICES), + DESC_RANGE(params::rt_ao, Type::SRV_RANGE, params::RTAOE::MATERIALS), + DESC_RANGE(params::rt_ao, Type::SRV_RANGE, params::RTAOE::OFFSETS), + DESC_RANGE(params::rt_ao, Type::SRV_RANGE, params::RTAOE::TEXTURES), DESC_RANGE(params::rt_ao, Type::SRV_RANGE, params::RTAOE::GBUFFERS), DESC_RANGE_H(D3D12_DESCRIPTOR_RANGE_TYPE::D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 9, d3d12::settings::fallback_ptrs_offset), ); @@ -1215,24 +1219,50 @@ namespace wr ROOT_PARAM_DESC_TABLE(rt_ao_ranges, D3D12_SHADER_VISIBILITY_ALL), ROOT_PARAM(GetSRV(params::rt_ao, params::RTAOE::ACCELERATION_STRUCTURE)), ROOT_PARAM(GetCBV(params::rt_ao, params::RTAOE::CAMERA_PROPERTIES)), + ROOT_PARAM(GetSRV(params::rt_ao, params::RTAOE::VERTICES)), + }, + .m_samplers = { + { TextureFilter::FILTER_POINT, TextureAddressMode::TAM_WRAP } }, - .m_samplers = {}, .m_rtx = true }); - StateObjectDescription::LibraryDesc rt_ao_so_library = []() + StateObjectDescription::LibraryDesc rt_ao_so_transparency_library = []() + { + StateObjectDescription::LibraryDesc lib; + lib.shader_handle = shaders::rt_ao_lib; + lib.exports.push_back(L"AORaygenEntry_Transparency"); + lib.exports.push_back(L"AOClosestHitEntry"); + lib.exports.push_back(L"AOMissEntry"); + lib.exports.push_back(L"AOAnyHitEntry"); + lib.m_hit_groups.push_back({ L"AOHitGroup", L"AOClosestHitEntry", L"AOAnyHitEntry" }); + return lib; + }(); + + StateObjectDescription::LibraryDesc rt_ao_so_no_transparency_library = []() { StateObjectDescription::LibraryDesc lib; lib.shader_handle = shaders::rt_ao_lib; lib.exports.push_back(L"AORaygenEntry"); - lib.exports.push_back(L"MissEntry"); + lib.exports.push_back(L"AOMissEntry"); return lib; }(); - REGISTER(state_objects::rt_ao_state_opbject, RTPipelineRegistry)( + REGISTER(state_objects::rt_ao_state_object, RTPipelineRegistry)( + { + .desc = D3D12_STATE_OBJECT_TYPE_RAYTRACING_PIPELINE, + .library_desc = rt_ao_so_no_transparency_library, + .max_payload_size = (sizeof(float) * 2), + .max_attributes_size = sizeof(float) * 4, + .max_recursion_depth = 1, + .global_root_signature = root_signatures::rt_ao_global, + .local_root_signatures = {}, + }); + + REGISTER(state_objects::rt_ao_state_object_transparency, RTPipelineRegistry)( { .desc = D3D12_STATE_OBJECT_TYPE_RAYTRACING_PIPELINE, - .library_desc = rt_ao_so_library, + .library_desc = rt_ao_so_transparency_library, .max_payload_size = (sizeof(float) * 2), .max_attributes_size = sizeof(float) * 4, .max_recursion_depth = 1, @@ -1276,17 +1306,34 @@ namespace wr .m_rtx = true }); - StateObjectDescription::LibraryDesc path_tracer_so_library = []() + StateObjectDescription::LibraryDesc path_tracer_so_library_transparency = []() { StateObjectDescription::LibraryDesc lib; lib.shader_handle = shaders::path_tracer_lib; lib.exports.push_back(L"RaygenEntry"); lib.exports.push_back(L"ReflectionHit"); lib.exports.push_back(L"ReflectionMiss"); + lib.exports.push_back(L"ReflectionAnyHit"); lib.exports.push_back(L"ShadowClosestHitEntry"); lib.exports.push_back(L"ShadowMissEntry"); - lib.m_hit_groups.push_back({ L"ReflectionHitGroup", L"ReflectionHit" }); - lib.m_hit_groups.push_back({ L"ShadowHitGroup", L"ShadowClosestHitEntry" }); + lib.exports.push_back(L"ShadowAnyHitEntry"); + lib.m_hit_groups.push_back({ L"ReflectionHitGroup", L"ReflectionHit", L"ReflectionAnyHit" }); + lib.m_hit_groups.push_back({ L"ShadowHitGroup", L"ShadowClosestHitEntry", L"ShadowAnyHitEntry" }); + + return lib; + }(); + + StateObjectDescription::LibraryDesc path_tracer_so_library_no_transparency = []() + { + StateObjectDescription::LibraryDesc lib; + lib.shader_handle = shaders::path_tracer_lib; + lib.exports.push_back(L"RaygenEntry"); + lib.exports.push_back(L"ReflectionHit"); + lib.exports.push_back(L"ReflectionMiss"); + lib.exports.push_back(L"ShadowClosestHitEntry"); + lib.exports.push_back(L"ShadowMissEntry"); + lib.m_hit_groups.push_back({ L"ReflectionHitGroup", L"ReflectionHit"}); + lib.m_hit_groups.push_back({ L"ShadowHitGroup", L"ShadowClosestHitEntry"}); return lib; }(); @@ -1294,7 +1341,18 @@ namespace wr REGISTER(state_objects::path_tracer_state_object, RTPipelineRegistry)( { .desc = D3D12_STATE_OBJECT_TYPE_RAYTRACING_PIPELINE, - .library_desc = path_tracer_so_library, + .library_desc = path_tracer_so_library_no_transparency, + .max_payload_size = (sizeof(float) * 6) + (sizeof(unsigned int) * 2) + (sizeof(float) * 2), + .max_attributes_size = sizeof(float) * 4, + .max_recursion_depth = 6, + .global_root_signature = root_signatures::path_tracing_global, + .local_root_signatures = {}, + }); + + REGISTER(state_objects::path_tracer_state_object_transparency, RTPipelineRegistry)( + { + .desc = D3D12_STATE_OBJECT_TYPE_RAYTRACING_PIPELINE, + .library_desc = path_tracer_so_library_transparency, .max_payload_size = (sizeof(float) * 6) + (sizeof(unsigned int) * 2) + (sizeof(float) * 2), .max_attributes_size = sizeof(float) * 4, .max_recursion_depth = 6, @@ -1310,7 +1368,7 @@ namespace wr .defines = {} }); - StateObjectDescription::LibraryDesc rt_shadow_so_library = []() + StateObjectDescription::LibraryDesc rt_shadow_so_library_no_transparency = []() { StateObjectDescription::LibraryDesc lib; lib.shader_handle = shaders::rt_shadow_lib; @@ -1321,10 +1379,36 @@ namespace wr return lib; }(); + + StateObjectDescription::LibraryDesc rt_shadow_so_library_transparency = []() + { + StateObjectDescription::LibraryDesc lib; + lib.shader_handle = shaders::rt_shadow_lib; + lib.exports.push_back(L"ShadowRaygenEntry"); + lib.exports.push_back(L"ShadowClosestHitEntry"); + lib.exports.push_back(L"ShadowMissEntry"); + lib.exports.push_back(L"ShadowAnyHitEntry"); + lib.m_hit_groups.push_back({ L"ShadowHitGroup", L"ShadowClosestHitEntry", L"ShadowAnyHitEntry" }); + + return lib; + }(); + + REGISTER(state_objects::rt_shadow_state_object, RTPipelineRegistry)( { .desc = D3D12_STATE_OBJECT_TYPE_RAYTRACING_PIPELINE, - .library_desc = rt_shadow_so_library, + .library_desc = rt_shadow_so_library_no_transparency, + .max_payload_size = (sizeof(float) * 6) + (sizeof(unsigned int) * 2) + (sizeof(float) * 3), + .max_attributes_size = sizeof(float) * 4, + .max_recursion_depth = 1, + .global_root_signature = root_signatures::rt_hybrid_global, + .local_root_signatures = {} + }); + + REGISTER(state_objects::rt_shadow_state_object_transparency, RTPipelineRegistry)( + { + .desc = D3D12_STATE_OBJECT_TYPE_RAYTRACING_PIPELINE, + .library_desc = rt_shadow_so_library_transparency, .max_payload_size = (sizeof(float) * 6) + (sizeof(unsigned int) * 2) + (sizeof(float) * 3), .max_attributes_size = sizeof(float) * 4, .max_recursion_depth = 1, @@ -1340,7 +1424,7 @@ namespace wr .defines = {} }); - StateObjectDescription::LibraryDesc rt_reflection_so_library = []() + StateObjectDescription::LibraryDesc rt_reflection_so_library_no_transparency = []() { StateObjectDescription::LibraryDesc lib; lib.shader_handle = shaders::rt_reflection_lib; @@ -1354,10 +1438,40 @@ namespace wr return lib; }(); + + StateObjectDescription::LibraryDesc rt_reflection_so_library_transparency = []() + { + StateObjectDescription::LibraryDesc lib; + lib.shader_handle = shaders::rt_reflection_lib; + lib.exports.push_back(L"ReflectionRaygenEntry"); + lib.exports.push_back(L"ReflectionHit"); + lib.exports.push_back(L"ReflectionMiss"); + lib.exports.push_back(L"ReflectionAnyHit"); + lib.exports.push_back(L"ShadowClosestHitEntry"); + lib.exports.push_back(L"ShadowMissEntry"); + lib.exports.push_back(L"ShadowAnyHitEntry"); + lib.m_hit_groups.push_back({ L"ReflectionHitGroup", L"ReflectionHit", L"ReflectionAnyHit" }); + lib.m_hit_groups.push_back({ L"ShadowHitGroup", L"ShadowClosestHitEntry", L"ShadowAnyHitEntry" }); + + + return lib; + }(); + REGISTER(state_objects::rt_reflection_state_object, RTPipelineRegistry)( { .desc = D3D12_STATE_OBJECT_TYPE_RAYTRACING_PIPELINE, - .library_desc = rt_reflection_so_library, + .library_desc = rt_reflection_so_library_no_transparency, + .max_payload_size = (sizeof(float) * 6) + (sizeof(unsigned int) * 2) + (sizeof(float) * 3), + .max_attributes_size = sizeof(float) * 4, + .max_recursion_depth = 3, + .global_root_signature = root_signatures::rt_hybrid_global, + .local_root_signatures = {} + }); + + REGISTER(state_objects::rt_reflection_state_object_transparency, RTPipelineRegistry)( + { + .desc = D3D12_STATE_OBJECT_TYPE_RAYTRACING_PIPELINE, + .library_desc = rt_reflection_so_library_transparency, .max_payload_size = (sizeof(float) * 6) + (sizeof(unsigned int) * 2) + (sizeof(float) * 3), .max_attributes_size = sizeof(float) * 4, .max_recursion_depth = 3, diff --git a/src/engine_registry.hpp b/src/engine_registry.hpp index 5529efae..083edeca 100644 --- a/src/engine_registry.hpp +++ b/src/engine_registry.hpp @@ -606,16 +606,27 @@ namespace wr CAMERA_PROPERTIES, ACCELERATION_STRUCTURE, OUTPUT, + INDICES, + VERTICES, + MATERIALS, + OFFSETS, + TEXTURES, GBUFFERS, FALLBACK_PTRS }; - constexpr std::array rt_ao = { + constexpr std::array rt_ao = { rs_layout::Entry{(int)RTAOE::CAMERA_PROPERTIES, 1, rs_layout::Type::CBV_OR_CONST}, rs_layout::Entry{(int)RTAOE::OUTPUT, 1, rs_layout::Type::UAV_RANGE}, rs_layout::Entry{(int)RTAOE::ACCELERATION_STRUCTURE, 1, rs_layout::Type::SRV}, + rs_layout::Entry{(int)RTAOE::INDICES, 1, rs_layout::Type::SRV_RANGE}, + rs_layout::Entry{(int)RTAOE::VERTICES, 1, rs_layout::Type::SRV}, + rs_layout::Entry{(int)RTAOE::MATERIALS, 1, rs_layout::Type::SRV_RANGE}, + rs_layout::Entry{(int)RTAOE::OFFSETS, 1, rs_layout::Type::SRV_RANGE}, + rs_layout::Entry{(int)RTAOE::TEXTURES, d3d12::settings::num_max_rt_textures, rs_layout::Type::SRV_RANGE}, rs_layout::Entry{(int)RTAOE::GBUFFERS, 2, rs_layout::Type::SRV_RANGE}, rs_layout::Entry{(int)RTAOE::FALLBACK_PTRS, 9, rs_layout::Type::SRV_RANGE}, + }; enum class PathTracingE @@ -930,11 +941,14 @@ namespace wr struct state_objects { WISPRENDERER_EXPORT static RegistryHandle state_object; - WISPRENDERER_EXPORT static RegistryHandle rt_ao_state_opbject; - WISPRENDERER_EXPORT static RegistryHandle path_tracing_state_object; + WISPRENDERER_EXPORT static RegistryHandle rt_ao_state_object; + WISPRENDERER_EXPORT static RegistryHandle rt_ao_state_object_transparency; WISPRENDERER_EXPORT static RegistryHandle path_tracer_state_object; + WISPRENDERER_EXPORT static RegistryHandle path_tracer_state_object_transparency; WISPRENDERER_EXPORT static RegistryHandle rt_shadow_state_object; + WISPRENDERER_EXPORT static RegistryHandle rt_shadow_state_object_transparency; WISPRENDERER_EXPORT static RegistryHandle rt_reflection_state_object; + WISPRENDERER_EXPORT static RegistryHandle rt_reflection_state_object_transparency; }; } /* wr */ diff --git a/src/imgui_graphics_settings.hpp b/src/imgui_graphics_settings.hpp index 8a0fa939..8f716cc2 100644 --- a/src/imgui_graphics_settings.hpp +++ b/src/imgui_graphics_settings.hpp @@ -30,6 +30,7 @@ namespace wr::imgui::window static bool asbuild_settings_open = true; static bool shadow_settings_open = true; static bool shadow_denoiser_settings_open = true; + static bool path_tracer_settings_open = true; void GraphicsSettings(FrameGraph* frame_graph) { @@ -40,6 +41,7 @@ namespace wr::imgui::window ImGui::DragFloat("Bias", &rtao_user_settings.m_runtime.bias, 0.01f, 0.0f, 100.f); ImGui::DragFloat("Radius", &rtao_user_settings.m_runtime.radius, 0.1f, 0.0f, 1000.f); + ImGui::DragFloat("Max Distance", &rtao_user_settings.m_runtime.max_distance, 0.1f, 0.0f, 5000.f); ImGui::DragFloat("Power", &rtao_user_settings.m_runtime.power, 0.1f, 0.0f, 10.f); ImGui::DragInt("SPP", &rtao_user_settings.m_runtime.sample_count, 1, 0, 1073741824); @@ -99,17 +101,30 @@ namespace wr::imgui::window ImGui::Begin("Acceleration Structure Settings", &asbuild_settings_open); - ImGui::Checkbox("Disable rebuilding", &as_build_user_settings.m_runtime.m_rebuild_as); + static bool rebuild_as = false; + static bool allow_transparency = false; + + ImGui::Checkbox("Disable rebuilding", &rebuild_as); + + ImGui::Checkbox("Allow transparency", &allow_transparency); + + if(ImGui::Button("Rebuild BLAS")) + { + as_build_user_settings.m_runtime.m_rebuild_bot_level = true; + as_build_user_settings.m_runtime.m_rebuild_as = rebuild_as; + as_build_user_settings.m_runtime.m_allow_transparency = allow_transparency; + + frame_graph->UpdateSettings(as_build_user_settings); + } ImGui::End(); - frame_graph->UpdateSettings(as_build_user_settings); } if (frame_graph->HasTask() && shadow_settings_open) { auto shadow_user_settings = frame_graph->GetSettings(); - ImGui::Begin("Shadow Settings", &rtao_settings_open); + ImGui::Begin("Shadow Settings", &shadow_settings_open); ImGui::DragFloat("Epsilon", &shadow_user_settings.m_runtime.m_epsilon, 0.01f, 0.0f, 15.f); ImGui::DragInt("Sample Count", &shadow_user_settings.m_runtime.m_sample_count, 1, 1, 64); @@ -136,6 +151,20 @@ namespace wr::imgui::window } + + if (frame_graph->HasTask() && path_tracer_settings_open) + { + auto pt_user_settings = frame_graph->GetSettings(); + + ImGui::Begin("Path Tracing Settings", &path_tracer_settings_open); + + ImGui::Checkbox("Allow transparency", &pt_user_settings.m_runtime.m_allow_transparency); + + ImGui::End(); + frame_graph->UpdateSettings(pt_user_settings); + + + } } }// namepace imgui::window diff --git a/src/material_pool.hpp b/src/material_pool.hpp index 52da8cba..654044d9 100644 --- a/src/material_pool.hpp +++ b/src/material_pool.hpp @@ -147,7 +147,7 @@ namespace wr float m_roughness; float m_emissive_multiplier; float m_is_double_sided; - float m_use_alpha_constant; + float m_use_alpha_masking; float albedo_scale; float normal_scale; diff --git a/src/render_tasks/d3d12_build_acceleration_structures.hpp b/src/render_tasks/d3d12_build_acceleration_structures.hpp index 5b755e40..bbf8f66e 100644 --- a/src/render_tasks/d3d12_build_acceleration_structures.hpp +++ b/src/render_tasks/d3d12_build_acceleration_structures.hpp @@ -34,6 +34,8 @@ namespace wr struct Runtime { bool m_rebuild_as = false; + bool m_allow_transparency = false; + bool m_rebuild_bot_level = false; }; Runtime m_runtime; }; @@ -66,6 +68,7 @@ namespace wr bool out_init = true; bool out_materials_require_update = true; + bool out_using_transparency = false; }; namespace internal @@ -86,7 +89,7 @@ namespace wr // Structured buffer for the materials. data.out_sb_material_handle = static_cast(n_render_system.m_raytracing_material_sb_pool->Create(sizeof(temp::RayTracingMaterial_CBData) * d3d12::settings::num_max_rt_materials, sizeof(temp::RayTracingMaterial_CBData), false)); - // Structured buffer for the materials. + // Structured buffer for the offsets. data.out_sb_offset_handle = static_cast(n_render_system.m_raytracing_offset_sb_pool->Create(sizeof(temp::RayTracingOffset_CBData) * d3d12::settings::num_max_rt_materials, sizeof(temp::RayTracingOffset_CBData), false)); // Resize the materials @@ -183,7 +186,7 @@ namespace wr d3d12::desc::GeometryDesc obj = CreateGeometryDescFromMesh(n_mesh, vb, ib); // Build Bottom level BVH - auto blas = d3d12::CreateBottomLevelAccelerationStructures(device, cmd_list, out_heap, { obj }); + auto blas = d3d12::CreateBottomLevelAccelerationStructures(device, cmd_list, out_heap, { obj }, data.out_using_transparency); d3d12::UAVBarrierAS(cmd_list, blas, frame_idx); d3d12::SetName(blas, L"Bottom Level Acceleration Structure"); @@ -243,7 +246,7 @@ namespace wr d3d12::desc::GeometryDesc obj = CreateGeometryDescFromMesh(n_mesh, vb, ib); // Build Bottom level BVH - auto blas = d3d12::CreateBottomLevelAccelerationStructures(device, cmd_list, out_heap, { obj }); + auto blas = d3d12::CreateBottomLevelAccelerationStructures(device, cmd_list, out_heap, { obj }, data.out_using_transparency); d3d12::UAVBarrierAS(cmd_list, blas, frame_idx); d3d12::SetName(blas, L"Bottom Level Acceleration Structure"); @@ -470,14 +473,37 @@ namespace wr auto frame_idx = n_render_system.GetFrameIdx(); data.out_materials_require_update = false; + data.out_using_transparency = settings.m_runtime.m_allow_transparency; data.current_frame_index = n_render_system.GetFrameIdx(); d3d12::DescriptorHeap* out_heap = cmd_list->m_rt_descriptor_heap->GetHeap(); + if (settings.m_runtime.m_rebuild_bot_level) + { + data.out_init = true; + settings.m_runtime.m_rebuild_bot_level = false; + + fg.UpdateSettings(settings); + } + // Initialize requirements if (data.out_init) { + if (data.current_frame_index != data.previous_frame_index) + { + for (int i = 0; i < data.old_blasses[data.current_frame_index].size(); ++i) + { + d3d12::DestroyAccelerationStructure(data.old_blasses[data.current_frame_index][i]); + } + data.old_blasses[data.current_frame_index].clear(); + + d3d12::DestroyAccelerationStructure(data.old_tlas[data.current_frame_index]); + + data.old_tlas[data.current_frame_index] = {}; + } + + std::vector> model_pools = n_render_system.m_model_pools; // Transition all model pools for accel structure creation for (auto& pool : model_pools) diff --git a/src/render_tasks/d3d12_path_tracer.hpp b/src/render_tasks/d3d12_path_tracer.hpp index 992e73ce..bce89c46 100644 --- a/src/render_tasks/d3d12_path_tracer.hpp +++ b/src/render_tasks/d3d12_path_tracer.hpp @@ -33,6 +33,16 @@ namespace wr { + struct PathTracerSettings + { + struct Runtime + { + bool m_allow_transparency = false; + }; + Runtime m_runtime; + }; + + //TODO, this struct is unpadded, manual padding might be usefull. struct PathTracerData { @@ -162,6 +172,22 @@ namespace wr data.out_gbuffer_depth_alloc = std::move(as_build_data.out_allocator->Allocate()); data.tlas_requires_init = true; + + + // Camera constant buffer + data.out_cb_camera_handle = static_cast(n_render_system.m_raytracing_cb_pool->Create(sizeof(temp::RTHybridCamera_CBData))); + + // Pipeline State Object + auto& rt_registry = RTPipelineRegistry::Get(); + data.out_state_object = static_cast(rt_registry.Find(as_build_data.out_using_transparency + ? state_objects::path_tracer_state_object_transparency + : state_objects::path_tracer_state_object)); + + // Create Shader Tables + for (int frame_idx = 0; frame_idx < d3d12::settings::num_back_buffers; ++frame_idx) + { + CreateShaderTables(device, data, frame_idx); + } } // Versioning @@ -186,21 +212,6 @@ namespace wr d3d12::CreateSRVFromDSV(deferred_main_rt, depth_handle); } - if (!resize) - { - // Camera constant buffer - data.out_cb_camera_handle = static_cast(n_render_system.m_raytracing_cb_pool->Create(sizeof(temp::RTHybridCamera_CBData))); - - // Pipeline State Object - auto& rt_registry = RTPipelineRegistry::Get(); - data.out_state_object = static_cast(rt_registry.Find(state_objects::path_tracer_state_object)); - - // Create Shader Tables - CreateShaderTables(device, data, 0); - CreateShaderTables(device, data, 1); - CreateShaderTables(device, data, 2); - } - } inline void ExecutePathTracerTask(RenderSystem& render_system, FrameGraph& fg, SceneGraph& scene_graph, RenderTaskHandle& handle) @@ -223,6 +234,23 @@ namespace wr auto& data = fg.GetData(handle); auto& as_build_data = fg.GetPredecessorData(); auto frame_idx = n_render_system.GetFrameIdx(); + auto settings = fg.GetSettings(handle); + + // Pipeline State Object + auto& rt_registry = RTPipelineRegistry::Get(); + + if (settings.m_runtime.m_allow_transparency) + { + // Pipeline State Object + auto& rt_registry = RTPipelineRegistry::Get(); + data.out_state_object = static_cast(rt_registry.Find(as_build_data.out_using_transparency + ? state_objects::path_tracer_state_object_transparency + : state_objects::path_tracer_state_object)); + } + else + { + data.out_state_object = static_cast(rt_registry.Find(state_objects::path_tracer_state_object)); + } // Rebuild acceleratrion structure a 2e time for fallback if (d3d12::GetRaytracingType(device) == RaytracingType::FALLBACK) @@ -471,7 +499,8 @@ namespace wr desc.m_type = RenderTaskType::COMPUTE; desc.m_allow_multithreading = true; - fg.AddTask(desc, L"Path Traced Global Illumination", FG_DEPS()); + fg.AddTask(desc, L"Path Traced Global Illumination", FG_DEPS()); + fg.UpdateSettings(PathTracerSettings()); } } /* wr */ diff --git a/src/render_tasks/d3d12_rt_hybrid_helpers.hpp b/src/render_tasks/d3d12_rt_hybrid_helpers.hpp index be1918d2..49e9af3e 100644 --- a/src/render_tasks/d3d12_rt_hybrid_helpers.hpp +++ b/src/render_tasks/d3d12_rt_hybrid_helpers.hpp @@ -44,7 +44,6 @@ namespace wr std::array out_miss_shader_table = { nullptr, nullptr, nullptr }; std::array out_hitgroup_shader_table = { nullptr, nullptr, nullptr }; - // Pipeline objects d3d12::StateObject* out_state_object = nullptr; d3d12::RootSignature* out_root_signature = nullptr; @@ -97,6 +96,7 @@ namespace wr } // Set up Miss Shader Table + if (miss_entries.size() > 0) { // Create Record(s) and Table(s) std::uint32_t shader_record_count = miss_entries.size(); @@ -113,6 +113,7 @@ namespace wr } // Set up Hit Group Shader Table + if (hit_groups.size() > 0) { // Create Record(s) std::uint32_t shader_record_count = hit_groups.size(); diff --git a/src/render_tasks/d3d12_rt_reflection_task.hpp b/src/render_tasks/d3d12_rt_reflection_task.hpp index 3b1fb382..a170a8ec 100644 --- a/src/render_tasks/d3d12_rt_reflection_task.hpp +++ b/src/render_tasks/d3d12_rt_reflection_task.hpp @@ -31,9 +31,8 @@ namespace wr { - struct RTReflectionData + struct RTReflectionData : RTHybrid_BaseData { - RTHybrid_BaseData base_data; }; namespace internal @@ -54,40 +53,40 @@ namespace wr // Get AS build data auto& as_build_data = fg.GetPredecessorData(); - data.base_data.out_output_alloc = std::move(as_build_data.out_allocator->Allocate(3)); - data.base_data.out_gbuffer_albedo_alloc = std::move(as_build_data.out_allocator->Allocate()); - data.base_data.out_gbuffer_normal_alloc = std::move(as_build_data.out_allocator->Allocate()); - data.base_data.out_gbuffer_depth_alloc = std::move(as_build_data.out_allocator->Allocate()); + data.out_output_alloc = std::move(as_build_data.out_allocator->Allocate(3)); + data.out_gbuffer_albedo_alloc = std::move(as_build_data.out_allocator->Allocate()); + data.out_gbuffer_normal_alloc = std::move(as_build_data.out_allocator->Allocate()); + data.out_gbuffer_depth_alloc = std::move(as_build_data.out_allocator->Allocate()); - data.base_data.tlas_requires_init = true; - } + data.tlas_requires_init = true; - CreateUAVsAndSRVs(fg, data.base_data, n_render_target); - if (!resize) - { // Camera constant buffer - data.base_data.out_cb_camera_handle = static_cast(n_render_system.m_raytracing_cb_pool->Create(sizeof(temp::RTHybridCamera_CBData))); + data.out_cb_camera_handle = static_cast(n_render_system.m_raytracing_cb_pool->Create(sizeof(temp::RTHybridCamera_CBData))); // Pipeline State Object auto& rt_registry = RTPipelineRegistry::Get(); - data.base_data.out_state_object = static_cast(rt_registry.Find(state_objects::rt_reflection_state_object)); + data.out_state_object = static_cast(rt_registry.Find(as_build_data.out_using_transparency + ? state_objects::rt_reflection_state_object_transparency + : state_objects::rt_reflection_state_object)); // Root Signature auto& rs_registry = RootSignatureRegistry::Get(); - data.base_data.out_root_signature = static_cast(rs_registry.Find(root_signatures::rt_hybrid_global)); + data.out_root_signature = static_cast(rs_registry.Find(root_signatures::rt_hybrid_global)); } + CreateUAVsAndSRVs(fg, data, n_render_target); + // Create Shader Tables for (int i = 0; i < d3d12::settings::num_back_buffers; ++i) { - CreateShaderTables(device, data.base_data, "ReflectionRaygenEntry", + CreateShaderTables(device, data, "ReflectionRaygenEntry", { "ReflectionMiss", "ShadowMissEntry" }, { "ReflectionHitGroup", "ShadowHitGroup" }, i); } // Setup frame index - data.base_data.frame_idx = 0; + data.frame_idx = 0; } inline void ExecuteRTReflectionTask(RenderSystem & render_system, FrameGraph & fg, SceneGraph & scene_graph, RenderTaskHandle & handle) @@ -108,20 +107,26 @@ namespace wr // Rebuild acceleratrion structure a 2e time for fallback if (d3d12::GetRaytracingType(device) == RaytracingType::FALLBACK) { - d3d12::CreateOrUpdateTLAS(device, cmd_list, data.base_data.tlas_requires_init, data.base_data.out_tlas, as_build_data.out_blas_list, frame_idx); + d3d12::CreateOrUpdateTLAS(device, cmd_list, data.tlas_requires_init, data.out_tlas, as_build_data.out_blas_list, frame_idx); d3d12::UAVBarrierAS(cmd_list, as_build_data.out_tlas, frame_idx); } if (n_render_system.m_render_window.has_value()) { - d3d12::BindRaytracingPipeline(cmd_list, data.base_data.out_state_object, d3d12::GetRaytracingType(device) == RaytracingType::FALLBACK); + auto& rt_registry = RTPipelineRegistry::Get(); + data.out_state_object = static_cast(rt_registry.Find(as_build_data.out_using_transparency + ? state_objects::rt_reflection_state_object_transparency + : state_objects::rt_reflection_state_object)); + + + d3d12::BindRaytracingPipeline(cmd_list, data.out_state_object, d3d12::GetRaytracingType(device) == RaytracingType::FALLBACK); // Bind output, indices and materials, offsets, etc - auto out_uav_handle = data.base_data.out_output_alloc.GetDescriptorHandle(0); + auto out_uav_handle = data.out_output_alloc.GetDescriptorHandle(0); d3d12::SetRTShaderUAV(cmd_list, 0, COMPILATION_EVAL(rs_layout::GetHeapLoc(params::rt_hybrid, params::RTHybridE::OUTPUT)), out_uav_handle); - out_uav_handle = data.base_data.out_output_alloc.GetDescriptorHandle(1); + out_uav_handle = data.out_output_alloc.GetDescriptorHandle(1); d3d12::SetRTShaderUAV(cmd_list, 0, COMPILATION_EVAL(rs_layout::GetHeapLoc(params::rt_hybrid, params::RTHybridE::OUTPUT)) + 1, out_uav_handle); - out_uav_handle = data.base_data.out_output_alloc.GetDescriptorHandle(2); + out_uav_handle = data.out_output_alloc.GetDescriptorHandle(2); d3d12::SetRTShaderUAV(cmd_list, 0, COMPILATION_EVAL(rs_layout::GetHeapLoc(params::rt_hybrid, params::RTHybridE::OUTPUT)) + 2, out_uav_handle); auto out_scene_ib_handle = as_build_data.out_scene_ib_alloc.GetDescriptorHandle(); @@ -133,13 +138,13 @@ namespace wr auto out_scene_offset_handle = as_build_data.out_scene_offset_alloc.GetDescriptorHandle(); d3d12::SetRTShaderSRV(cmd_list, 0, COMPILATION_EVAL(rs_layout::GetHeapLoc(params::rt_hybrid, params::RTHybridE::OFFSETS)), out_scene_offset_handle); - auto out_albedo_gbuffer_handle = data.base_data.out_gbuffer_albedo_alloc.GetDescriptorHandle(); + auto out_albedo_gbuffer_handle = data.out_gbuffer_albedo_alloc.GetDescriptorHandle(); d3d12::SetRTShaderSRV(cmd_list, 0, COMPILATION_EVAL(rs_layout::GetHeapLoc(params::rt_hybrid, params::RTHybridE::GBUFFERS)) + 0, out_albedo_gbuffer_handle); - auto out_normal_gbuffer_handle = data.base_data.out_gbuffer_normal_alloc.GetDescriptorHandle(); + auto out_normal_gbuffer_handle = data.out_gbuffer_normal_alloc.GetDescriptorHandle(); d3d12::SetRTShaderSRV(cmd_list, 0, COMPILATION_EVAL(rs_layout::GetHeapLoc(params::rt_hybrid, params::RTHybridE::GBUFFERS)) + 1, out_normal_gbuffer_handle); - auto out_scene_depth_handle = data.base_data.out_gbuffer_depth_alloc.GetDescriptorHandle(); + auto out_scene_depth_handle = data.out_gbuffer_depth_alloc.GetDescriptorHandle(); d3d12::SetRTShaderSRV(cmd_list, 0, COMPILATION_EVAL(rs_layout::GetHeapLoc(params::rt_hybrid, params::RTHybridE::GBUFFERS)) + 2, out_scene_depth_handle); /* @@ -216,8 +221,8 @@ namespace wr cam_data.m_inverse_projection = DirectX::XMMatrixInverse(nullptr, camera->m_projection); cam_data.m_inv_vp = DirectX::XMMatrixInverse(nullptr, camera->m_view * camera->m_projection); cam_data.m_intensity = n_render_system.temp_intensity; - cam_data.m_frame_idx = static_cast(++data.base_data.frame_idx); - n_render_system.m_camera_pool->Update(data.base_data.out_cb_camera_handle, sizeof(temp::RTHybridCamera_CBData), 0, frame_idx, (std::uint8_t*) & cam_data); // FIXME: Uhh wrong pool? + cam_data.m_frame_idx = static_cast(++data.frame_idx); + n_render_system.m_camera_pool->Update(data.out_cb_camera_handle, sizeof(temp::RTHybridCamera_CBData), 0, frame_idx, (std::uint8_t*) & cam_data); // FIXME: Uhh wrong pool? // Make sure the convolution pass wrote to the skybox. fg.WaitForPredecessorTask(); @@ -242,11 +247,11 @@ namespace wr d3d12::SetRTShaderSRV(cmd_list, 0, COMPILATION_EVAL(rs_layout::GetHeapLoc(params::rt_hybrid, params::RTHybridE::BRDF_LUT)), brdf_lut_text); // Transition depth to NON_PIXEL_RESOURCE - d3d12::TransitionDepth(cmd_list, data.base_data.out_deferred_main_rt, ResourceState::DEPTH_WRITE, ResourceState::NON_PIXEL_SHADER_RESOURCE); + d3d12::TransitionDepth(cmd_list, data.out_deferred_main_rt, ResourceState::DEPTH_WRITE, ResourceState::NON_PIXEL_SHADER_RESOURCE); d3d12::BindDescriptorHeap(cmd_list, cmd_list->m_rt_descriptor_heap.get()->GetHeap(), DescriptorHeapType::DESC_HEAP_TYPE_CBV_SRV_UAV, frame_idx, d3d12::GetRaytracingType(device) == RaytracingType::FALLBACK); d3d12::BindDescriptorHeaps(cmd_list, d3d12::GetRaytracingType(device) == RaytracingType::FALLBACK); - d3d12::BindComputeConstantBuffer(cmd_list, data.base_data.out_cb_camera_handle->m_native, 2, frame_idx); + d3d12::BindComputeConstantBuffer(cmd_list, data.out_cb_camera_handle->m_native, 2, frame_idx); if (d3d12::GetRaytracingType(device) == RaytracingType::NATIVE) { @@ -263,23 +268,23 @@ namespace wr d3d12::BindComputeShaderResourceView(cmd_list, as_build_data.out_scene_vb->m_buffer, 3); //#ifdef _DEBUG - CreateShaderTables(device, data.base_data, "ReflectionRaygenEntry", + CreateShaderTables(device, data, "ReflectionRaygenEntry", { "ReflectionMiss", "ShadowMissEntry" }, { "ReflectionHitGroup", "ShadowHitGroup" }, frame_idx); //#endif // Dispatch hybrid ray tracing rays d3d12::DispatchRays(cmd_list, - data.base_data.out_hitgroup_shader_table[frame_idx], - data.base_data.out_miss_shader_table[frame_idx], - data.base_data.out_raygen_shader_table[frame_idx], + data.out_hitgroup_shader_table[frame_idx], + data.out_miss_shader_table[frame_idx], + data.out_raygen_shader_table[frame_idx], static_cast(std::ceil(d3d12::GetRenderTargetWidth(render_target))), static_cast(std::ceil(d3d12::GetRenderTargetHeight(render_target))), 1, frame_idx); // Transition depth back to DEPTH_WRITE - d3d12::TransitionDepth(cmd_list, data.base_data.out_deferred_main_rt, ResourceState::NON_PIXEL_SHADER_RESOURCE, ResourceState::DEPTH_WRITE); + d3d12::TransitionDepth(cmd_list, data.out_deferred_main_rt, ResourceState::NON_PIXEL_SHADER_RESOURCE, ResourceState::DEPTH_WRITE); } } @@ -290,10 +295,10 @@ namespace wr if (!resize) { // Small hack to force the allocations to go out of scope, which will tell the allocator to free them - std::move(data.base_data.out_output_alloc); - std::move(data.base_data.out_gbuffer_albedo_alloc); - std::move(data.base_data.out_gbuffer_normal_alloc); - std::move(data.base_data.out_gbuffer_depth_alloc); + std::move(data.out_output_alloc); + std::move(data.out_gbuffer_albedo_alloc); + std::move(data.out_gbuffer_normal_alloc); + std::move(data.out_gbuffer_depth_alloc); } } diff --git a/src/render_tasks/d3d12_rt_shadow_task.hpp b/src/render_tasks/d3d12_rt_shadow_task.hpp index 6ae5abf8..1cf9e926 100644 --- a/src/render_tasks/d3d12_rt_shadow_task.hpp +++ b/src/render_tasks/d3d12_rt_shadow_task.hpp @@ -43,9 +43,8 @@ namespace wr Runtime m_runtime; }; - struct RTShadowData + struct RTShadowData : RTHybrid_BaseData { - RTHybrid_BaseData base_data; }; namespace internal @@ -66,41 +65,40 @@ namespace wr // Get AS build data auto& as_build_data = fg.GetPredecessorData(); - data.base_data.out_output_alloc = std::move(as_build_data.out_allocator->Allocate(3)); - data.base_data.out_gbuffer_albedo_alloc = std::move(as_build_data.out_allocator->Allocate()); - data.base_data.out_gbuffer_normal_alloc = std::move(as_build_data.out_allocator->Allocate()); - data.base_data.out_gbuffer_depth_alloc = std::move(as_build_data.out_allocator->Allocate()); + data.out_output_alloc = std::move(as_build_data.out_allocator->Allocate(3)); + data.out_gbuffer_albedo_alloc = std::move(as_build_data.out_allocator->Allocate()); + data.out_gbuffer_normal_alloc = std::move(as_build_data.out_allocator->Allocate()); + data.out_gbuffer_depth_alloc = std::move(as_build_data.out_allocator->Allocate()); - data.base_data.tlas_requires_init = true; - } - - // Versioning - CreateUAVsAndSRVs(fg, data.base_data, n_render_target); + data.tlas_requires_init = true; - if (!resize) - { // Camera constant buffer - data.base_data.out_cb_camera_handle = static_cast(n_render_system.m_raytracing_cb_pool->Create(sizeof(temp::RTHybridCamera_CBData))); + data.out_cb_camera_handle = static_cast(n_render_system.m_raytracing_cb_pool->Create(sizeof(temp::RTHybridCamera_CBData))); // Pipeline State Object auto& rt_registry = RTPipelineRegistry::Get(); - data.base_data.out_state_object = static_cast(rt_registry.Find(state_objects::rt_shadow_state_object)); + data.out_state_object = static_cast(rt_registry.Find(as_build_data.out_using_transparency + ? state_objects::rt_shadow_state_object_transparency + : state_objects::rt_shadow_state_object)); // Root Signature auto& rs_registry = RootSignatureRegistry::Get(); - data.base_data.out_root_signature = static_cast(rs_registry.Find(root_signatures::rt_hybrid_global)); + data.out_root_signature = static_cast(rs_registry.Find(root_signatures::rt_hybrid_global)); } + // Versioning + CreateUAVsAndSRVs(fg, data, n_render_target); + // Create Shader Tables for (int i = 0; i < d3d12::settings::num_back_buffers; ++i) { - CreateShaderTables(device, data.base_data, "ShadowRaygenEntry", + CreateShaderTables(device, data, "ShadowRaygenEntry", { "ShadowMissEntry" }, { "ShadowHitGroup" }, i); } // Setup frame index - data.base_data.frame_idx = 0; + data.frame_idx = 0; } inline void ExecuteRTShadowTask(RenderSystem & render_system, FrameGraph & fg, SceneGraph & scene_graph, RenderTaskHandle & handle) @@ -123,20 +121,25 @@ namespace wr // Rebuild acceleratrion structure a 2e time for fallback if (d3d12::GetRaytracingType(device) == RaytracingType::FALLBACK) { - d3d12::CreateOrUpdateTLAS(device, cmd_list, data.base_data.tlas_requires_init, data.base_data.out_tlas, as_build_data.out_blas_list, frame_idx); + d3d12::CreateOrUpdateTLAS(device, cmd_list, data.tlas_requires_init, data.out_tlas, as_build_data.out_blas_list, frame_idx); d3d12::UAVBarrierAS(cmd_list, as_build_data.out_tlas, frame_idx); } if (n_render_system.m_render_window.has_value()) { - d3d12::BindRaytracingPipeline(cmd_list, data.base_data.out_state_object, d3d12::GetRaytracingType(device) == RaytracingType::FALLBACK); + auto& rt_registry = RTPipelineRegistry::Get(); + data.out_state_object = static_cast(rt_registry.Find(as_build_data.out_using_transparency + ? state_objects::rt_shadow_state_object_transparency + : state_objects::rt_shadow_state_object)); + + d3d12::BindRaytracingPipeline(cmd_list, data.out_state_object, d3d12::GetRaytracingType(device) == RaytracingType::FALLBACK); // Bind output, indices and materials, offsets, etc - auto out_uav_handle = data.base_data.out_output_alloc.GetDescriptorHandle(); + auto out_uav_handle = data.out_output_alloc.GetDescriptorHandle(); d3d12::SetRTShaderUAV(cmd_list, 0, COMPILATION_EVAL(rs_layout::GetHeapLoc(params::rt_hybrid, params::RTHybridE::OUTPUT)), out_uav_handle); - out_uav_handle = data.base_data.out_output_alloc.GetDescriptorHandle(1); + out_uav_handle = data.out_output_alloc.GetDescriptorHandle(1); d3d12::SetRTShaderUAV(cmd_list, 0, COMPILATION_EVAL(rs_layout::GetHeapLoc(params::rt_hybrid, params::RTHybridE::OUTPUT)) + 1, out_uav_handle); - out_uav_handle = data.base_data.out_output_alloc.GetDescriptorHandle(2); + out_uav_handle = data.out_output_alloc.GetDescriptorHandle(2); d3d12::SetRTShaderUAV(cmd_list, 0, COMPILATION_EVAL(rs_layout::GetHeapLoc(params::rt_hybrid, params::RTHybridE::OUTPUT)) + 2, out_uav_handle); auto out_scene_ib_handle = as_build_data.out_scene_ib_alloc.GetDescriptorHandle(); @@ -148,13 +151,13 @@ namespace wr auto out_scene_offset_handle = as_build_data.out_scene_offset_alloc.GetDescriptorHandle(); d3d12::SetRTShaderSRV(cmd_list, 0, COMPILATION_EVAL(rs_layout::GetHeapLoc(params::rt_hybrid, params::RTHybridE::OFFSETS)), out_scene_offset_handle); - auto out_albedo_gbuffer_handle = data.base_data.out_gbuffer_albedo_alloc.GetDescriptorHandle(); + auto out_albedo_gbuffer_handle = data.out_gbuffer_albedo_alloc.GetDescriptorHandle(); d3d12::SetRTShaderSRV(cmd_list, 0, COMPILATION_EVAL(rs_layout::GetHeapLoc(params::rt_hybrid, params::RTHybridE::GBUFFERS)) + 0, out_albedo_gbuffer_handle); - auto out_normal_gbuffer_handle = data.base_data.out_gbuffer_normal_alloc.GetDescriptorHandle(); + auto out_normal_gbuffer_handle = data.out_gbuffer_normal_alloc.GetDescriptorHandle(); d3d12::SetRTShaderSRV(cmd_list, 0, COMPILATION_EVAL(rs_layout::GetHeapLoc(params::rt_hybrid, params::RTHybridE::GBUFFERS)) + 1, out_normal_gbuffer_handle); - auto out_scene_depth_handle = data.base_data.out_gbuffer_depth_alloc.GetDescriptorHandle(); + auto out_scene_depth_handle = data.out_gbuffer_depth_alloc.GetDescriptorHandle(); d3d12::SetRTShaderSRV(cmd_list, 0, COMPILATION_EVAL(rs_layout::GetHeapLoc(params::rt_hybrid, params::RTHybridE::GBUFFERS)) + 2, out_scene_depth_handle); /* @@ -231,10 +234,10 @@ namespace wr cam_data.m_inverse_projection = DirectX::XMMatrixInverse(nullptr, camera->m_projection); cam_data.m_inv_vp = DirectX::XMMatrixInverse(nullptr, camera->m_view * camera->m_projection); cam_data.m_intensity = n_render_system.temp_intensity; - cam_data.m_frame_idx = static_cast(++data.base_data.frame_idx); + cam_data.m_frame_idx = static_cast(++data.frame_idx); cam_data.m_epsilon = settings.m_runtime.m_epsilon; cam_data.m_sample_count = settings.m_runtime.m_sample_count; - n_render_system.m_camera_pool->Update(data.base_data.out_cb_camera_handle, sizeof(temp::RTHybridCamera_CBData), 0, frame_idx, (std::uint8_t*) & cam_data); // FIXME: Uhh wrong pool? + n_render_system.m_camera_pool->Update(data.out_cb_camera_handle, sizeof(temp::RTHybridCamera_CBData), 0, frame_idx, (std::uint8_t*) & cam_data); // FIXME: Uhh wrong pool? // Make sure the convolution pass wrote to the skybox. fg.WaitForPredecessorTask(); @@ -259,11 +262,11 @@ namespace wr d3d12::SetRTShaderSRV(cmd_list, 0, COMPILATION_EVAL(rs_layout::GetHeapLoc(params::rt_hybrid, params::RTHybridE::BRDF_LUT)), brdf_lut_text); // Transition depth to NON_PIXEL_RESOURCE - d3d12::TransitionDepth(cmd_list, data.base_data.out_deferred_main_rt, ResourceState::DEPTH_WRITE, ResourceState::NON_PIXEL_SHADER_RESOURCE); + d3d12::TransitionDepth(cmd_list, data.out_deferred_main_rt, ResourceState::DEPTH_WRITE, ResourceState::NON_PIXEL_SHADER_RESOURCE); d3d12::BindDescriptorHeap(cmd_list, cmd_list->m_rt_descriptor_heap.get()->GetHeap(), DescriptorHeapType::DESC_HEAP_TYPE_CBV_SRV_UAV, frame_idx, d3d12::GetRaytracingType(device) == RaytracingType::FALLBACK); d3d12::BindDescriptorHeaps(cmd_list, d3d12::GetRaytracingType(device) == RaytracingType::FALLBACK); - d3d12::BindComputeConstantBuffer(cmd_list, data.base_data.out_cb_camera_handle->m_native, 2, frame_idx); + d3d12::BindComputeConstantBuffer(cmd_list, data.out_cb_camera_handle->m_native, 2, frame_idx); if (d3d12::GetRaytracingType(device) == RaytracingType::NATIVE) { @@ -280,23 +283,23 @@ namespace wr d3d12::BindComputeShaderResourceView(cmd_list, as_build_data.out_scene_vb->m_buffer, 3); //#ifdef _DEBUG - CreateShaderTables(device, data.base_data, "ShadowRaygenEntry", + CreateShaderTables(device, data, "ShadowRaygenEntry", { "ShadowMissEntry" }, { "ShadowHitGroup" }, frame_idx); //#endif // Dispatch hybrid ray tracing rays d3d12::DispatchRays(cmd_list, - data.base_data.out_hitgroup_shader_table[frame_idx], - data.base_data.out_miss_shader_table[frame_idx], - data.base_data.out_raygen_shader_table[frame_idx], + data.out_hitgroup_shader_table[frame_idx], + data.out_miss_shader_table[frame_idx], + data.out_raygen_shader_table[frame_idx], static_cast(std::ceil(d3d12::GetRenderTargetWidth(render_target))), static_cast(std::ceil(d3d12::GetRenderTargetHeight(render_target))), 1, frame_idx); // Transition depth back to DEPTH_WRITE - d3d12::TransitionDepth(cmd_list, data.base_data.out_deferred_main_rt, ResourceState::NON_PIXEL_SHADER_RESOURCE, ResourceState::DEPTH_WRITE); + d3d12::TransitionDepth(cmd_list, data.out_deferred_main_rt, ResourceState::NON_PIXEL_SHADER_RESOURCE, ResourceState::DEPTH_WRITE); } } @@ -307,10 +310,10 @@ namespace wr if (!resize) { // Small hack to force the allocations to go out of scope, which will tell the allocator to free them - std::move(data.base_data.out_output_alloc); - std::move(data.base_data.out_gbuffer_albedo_alloc); - std::move(data.base_data.out_gbuffer_normal_alloc); - std::move(data.base_data.out_gbuffer_depth_alloc); + std::move(data.out_output_alloc); + std::move(data.out_gbuffer_albedo_alloc); + std::move(data.out_gbuffer_normal_alloc); + std::move(data.out_gbuffer_depth_alloc); } } diff --git a/src/render_tasks/d3d12_rtao_task.hpp b/src/render_tasks/d3d12_rtao_task.hpp index a38656f4..4a19503d 100644 --- a/src/render_tasks/d3d12_rtao_task.hpp +++ b/src/render_tasks/d3d12_rtao_task.hpp @@ -27,6 +27,7 @@ #include "../render_tasks/d3d12_deferred_main.hpp" #include "../render_tasks/d3d12_build_acceleration_structures.hpp" +#include "../render_tasks/d3d12_rt_hybrid_helpers.hpp" namespace wr { @@ -44,77 +45,12 @@ namespace wr Runtime m_runtime; }; - struct RTAOData + struct RTAOData : RTHybrid_BaseData { - - d3d12::AccelerationStructure out_tlas = {}; - - // Shader tables - std::array in_raygen_shader_table = { nullptr, nullptr, nullptr }; - std::array in_miss_shader_table = { nullptr, nullptr, nullptr }; - std::array in_hitgroup_shader_table = { nullptr, nullptr, nullptr }; - - // Pipeline objects - d3d12::StateObject* in_state_object; - d3d12::RootSignature* in_root_signature; - - D3D12ConstantBufferHandle* out_cb_handle; - d3d12::RenderTarget* in_deferred_main_rt; - - DescriptorAllocation out_uav_from_rtv; - DescriptorAllocation in_gbuffers; - DescriptorAllocation in_depthbuffer; - - bool tlas_requires_init = false; }; namespace internal { - inline void CreateShaderTables(d3d12::Device* device, RTAOData& data, int frame_idx) - { - // Delete existing shader table - if (data.in_miss_shader_table[frame_idx]) - { - d3d12::Destroy(data.in_miss_shader_table[frame_idx]); - } - if (data.in_hitgroup_shader_table[frame_idx]) - { - d3d12::Destroy(data.in_hitgroup_shader_table[frame_idx]); - } - if (data.in_raygen_shader_table[frame_idx]) - { - d3d12::Destroy(data.in_raygen_shader_table[frame_idx]); - } - - // Set up Raygen Shader Table - { - // Create Record(s) - UINT shader_record_count = 1; - auto shader_identifier_size = d3d12::GetShaderIdentifierSize(device); - auto shader_identifier = d3d12::GetShaderIdentifier(device, data.in_state_object, "AORaygenEntry"); - - auto shader_record = d3d12::CreateShaderRecord(shader_identifier, shader_identifier_size); - - // Create Table - data.in_raygen_shader_table[frame_idx] = d3d12::CreateShaderTable(device, shader_record_count, shader_identifier_size); - d3d12::AddShaderRecord(data.in_raygen_shader_table[frame_idx], shader_record); - } - - // Set up Miss Shader Table - { - // Create Record(s) - UINT shader_record_count = 1; - auto shader_identifier_size = d3d12::GetShaderIdentifierSize(device); - - auto miss_identifier = d3d12::GetShaderIdentifier(device, data.in_state_object, "MissEntry"); - auto miss_record = d3d12::CreateShaderRecord(miss_identifier, shader_identifier_size); - - // Create Table(s) - data.in_miss_shader_table[frame_idx] = d3d12::CreateShaderTable(device, shader_record_count, shader_identifier_size); - d3d12::AddShaderRecord(data.in_miss_shader_table[frame_idx], miss_record); - } - } - inline void SetupAOTask(RenderSystem& render_system, FrameGraph& fg, RenderTaskHandle& handle, bool resize) { // Initialize variables @@ -128,46 +64,57 @@ namespace wr { auto& as_build_data = fg.GetPredecessorData(); - data.out_uav_from_rtv = std::move(as_build_data.out_allocator->Allocate(1)); - data.in_gbuffers = std::move(as_build_data.out_allocator->Allocate(1)); - data.in_depthbuffer = std::move(as_build_data.out_allocator->Allocate(1)); + data.out_output_alloc = std::move(as_build_data.out_allocator->Allocate(1)); + data.out_gbuffer_normal_alloc = std::move(as_build_data.out_allocator->Allocate(1)); + data.out_gbuffer_depth_alloc = std::move(as_build_data.out_allocator->Allocate(1)); + + // Camera constant buffer + data.out_cb_camera_handle = static_cast(n_render_system.m_raytracing_cb_pool->Create(sizeof(temp::RTAO_CBData))); + + // Pipeline State Object + auto& rt_registry = RTPipelineRegistry::Get(); + data.out_state_object = static_cast(rt_registry.Find(as_build_data.out_using_transparency + ? state_objects::rt_ao_state_object_transparency + : state_objects::rt_ao_state_object)); + + // Root Signature + auto& rs_registry = RootSignatureRegistry::Get(); + data.out_root_signature = static_cast(rs_registry.Find(root_signatures::rt_ao_global)); + + if (as_build_data.out_using_transparency) + { + // Create Shader Tables + for (int frame_idx = 0; frame_idx < d3d12::settings::num_back_buffers; ++frame_idx) + { + CreateShaderTables(device, data, "AORaygenEntry_Transparency", { "AOMissEntry" }, { "AOHitGroup" }, frame_idx); + } + } + else + { + // Create Shader Tables + for (int frame_idx = 0; frame_idx < d3d12::settings::num_back_buffers; ++frame_idx) + { + CreateShaderTables(device, data, "AORaygenEntry", { "AOMissEntry" }, { }, frame_idx); + } + } } // Versioning for (int frame_idx = 0; frame_idx < 1; ++frame_idx) { // Bind output texture - d3d12::DescHeapCPUHandle rtv_handle = data.out_uav_from_rtv.GetDescriptorHandle(); + d3d12::DescHeapCPUHandle rtv_handle = data.out_output_alloc.GetDescriptorHandle(); d3d12::CreateUAVFromSpecificRTV(n_render_target, rtv_handle, 0, n_render_target->m_create_info.m_rtv_formats[0]); // Bind g-buffers - d3d12::DescHeapCPUHandle normal_gbuffer_handle = data.in_gbuffers.GetDescriptorHandle(0); - d3d12::DescHeapCPUHandle depth_buffer_handle = data.in_depthbuffer.GetDescriptorHandle(0); + d3d12::DescHeapCPUHandle normal_gbuffer_handle = data.out_gbuffer_normal_alloc.GetDescriptorHandle(0); + d3d12::DescHeapCPUHandle depth_buffer_handle = data.out_gbuffer_depth_alloc.GetDescriptorHandle(0); - auto deferred_main_rt = data.in_deferred_main_rt = static_cast(fg.GetPredecessorRenderTarget()); + auto deferred_main_rt = data.out_deferred_main_rt = static_cast(fg.GetPredecessorRenderTarget()); d3d12::CreateSRVFromSpecificRTV(deferred_main_rt, normal_gbuffer_handle, 1, deferred_main_rt->m_create_info.m_rtv_formats.data()[1]); d3d12::CreateSRVFromDSV(deferred_main_rt, depth_buffer_handle); } - - if (!resize) - { - // Camera constant buffer - data.out_cb_handle = static_cast(n_render_system.m_raytracing_cb_pool->Create(sizeof(temp::RTAO_CBData))); - - // Pipeline State Object - auto& rt_registry = RTPipelineRegistry::Get(); - data.in_state_object = static_cast(rt_registry.Find(state_objects::rt_ao_state_opbject)); - - // Root Signature - auto& rs_registry = RootSignatureRegistry::Get(); - data.in_root_signature = static_cast(rs_registry.Find(root_signatures::rt_ao_global)); - - // Create Shader Tables - CreateShaderTables(device, data, 0); - CreateShaderTables(device, data, 1); - CreateShaderTables(device, data, 2); - } } inline void ExecuteAOTask(RenderSystem & render_system, FrameGraph & fg, SceneGraph & scene_graph, RenderTaskHandle & handle) @@ -187,18 +134,76 @@ namespace wr if (n_render_system.m_render_window.has_value()) { + auto& rt_registry = RTPipelineRegistry::Get(); + data.out_state_object = static_cast(rt_registry.Find(as_build_data.out_using_transparency + ? state_objects::rt_ao_state_object_transparency + : state_objects::rt_ao_state_object)); - d3d12::BindRaytracingPipeline(cmd_list, data.in_state_object, false); + d3d12::BindRaytracingPipeline(cmd_list, data.out_state_object, false); // Bind output, indices and materials, offsets, etc - auto out_uav_handle = data.out_uav_from_rtv.GetDescriptorHandle(); + auto out_uav_handle = data.out_output_alloc.GetDescriptorHandle(); d3d12::SetRTShaderUAV(cmd_list, 0, COMPILATION_EVAL(rs_layout::GetHeapLoc(params::rt_ao, params::RTAOE::OUTPUT)), out_uav_handle); - auto in_scene_normal_gbuffer_handle = data.in_gbuffers.GetDescriptorHandle(0); - d3d12::SetRTShaderSRV(cmd_list, 0, COMPILATION_EVAL(rs_layout::GetHeapLoc(params::rt_ao, params::RTAOE::GBUFFERS)) + 0, in_scene_normal_gbuffer_handle); - - auto in_scene_depth_handle = data.in_depthbuffer.GetDescriptorHandle(); - d3d12::SetRTShaderSRV(cmd_list, 0, COMPILATION_EVAL(rs_layout::GetHeapLoc(params::rt_ao, params::RTAOE::GBUFFERS)) + 1, in_scene_depth_handle); + auto out_scene_ib_handle = as_build_data.out_scene_ib_alloc.GetDescriptorHandle(); + d3d12::SetRTShaderSRV(cmd_list, 0, COMPILATION_EVAL(rs_layout::GetHeapLoc(params::rt_ao, params::RTAOE::INDICES)), out_scene_ib_handle); + + auto out_scene_mat_handle = as_build_data.out_scene_mat_alloc.GetDescriptorHandle(); + d3d12::SetRTShaderSRV(cmd_list, 0, COMPILATION_EVAL(rs_layout::GetHeapLoc(params::rt_ao, params::RTAOE::MATERIALS)), out_scene_mat_handle); + + auto out_scene_offset_handle = as_build_data.out_scene_offset_alloc.GetDescriptorHandle(); + d3d12::SetRTShaderSRV(cmd_list, 0, COMPILATION_EVAL(rs_layout::GetHeapLoc(params::rt_ao, params::RTAOE::OFFSETS)), out_scene_offset_handle); + + auto out_normal_gbuffer_handle = data.out_gbuffer_normal_alloc.GetDescriptorHandle(0); + d3d12::SetRTShaderSRV(cmd_list, 0, COMPILATION_EVAL(rs_layout::GetHeapLoc(params::rt_ao, params::RTAOE::GBUFFERS)) + 0, out_normal_gbuffer_handle); + + auto out_scene_depth_handle = data.out_gbuffer_depth_alloc.GetDescriptorHandle(); + d3d12::SetRTShaderSRV(cmd_list, 0, COMPILATION_EVAL(rs_layout::GetHeapLoc(params::rt_ao, params::RTAOE::GBUFFERS)) + 1, out_scene_depth_handle); + + + /* + To keep the CopyDescriptors function happy, we need to fill the descriptor table with valid descriptors + We fill the table with a single descriptor, then overwrite some spots with the he correct textures + If a spot is unused, then a default descriptor will be still bound, but not used in the shaders. + Since the renderer creates a texture pool that can be used by the render tasks, and + the texture pool also has default textures for albedo/roughness/etc... one of those textures is a good + candidate for this. + */ + { + auto texture_handle = n_render_system.GetDefaultAlbedo(); + auto* texture_resource = static_cast(texture_handle.m_pool->GetTextureResource(texture_handle)); + + size_t num_textures_in_heap = COMPILATION_EVAL(rs_layout::GetSize(params::rt_ao, params::RTAOE::TEXTURES)); + unsigned int heap_loc_start = COMPILATION_EVAL(rs_layout::GetHeapLoc(params::rt_ao, params::RTAOE::TEXTURES)); + + for (size_t i = 0; i < num_textures_in_heap; ++i) + { + d3d12::SetRTShaderSRV(cmd_list, 0, static_cast(heap_loc_start + i), texture_resource); + } + } + + // Fill descriptor heap with textures used by the scene + for (auto material_handle : as_build_data.out_material_handles) + { + auto* material_internal = material_handle.m_pool->GetMaterial(material_handle); + + auto set_srv = [&data, material_internal, cmd_list](auto texture_handle) + { + auto* texture_internal = static_cast(texture_handle.m_pool->GetTextureResource(texture_handle)); + + d3d12::SetRTShaderSRV(cmd_list, 0, COMPILATION_EVAL(rs_layout::GetHeapLoc(params::rt_ao, params::RTAOE::TEXTURES)) + static_cast(texture_handle.m_id), texture_internal); + }; + + std::array(TextureType::COUNT)> types = { TextureType::ALBEDO, TextureType::NORMAL, + TextureType::ROUGHNESS, TextureType::METALLIC, + TextureType::EMISSIVE, TextureType::AO }; + + for (auto t : types) + { + if (material_internal->HasTexture(t)) + set_srv(material_internal->GetTexture(t)); + } + } // Update offset data n_render_system.m_raytracing_offset_sb_pool->Update(as_build_data.out_sb_offset_handle, (void*)as_build_data.out_offsets.data(), sizeof(temp::RayTracingOffset_CBData) * as_build_data.out_offsets.size(), 0); @@ -221,36 +226,43 @@ namespace wr cb_data.m_frame_idx = frame_idx; cb_data.m_sample_count = static_cast(settings.m_runtime.sample_count); - n_render_system.m_camera_pool->Update(data.out_cb_handle, sizeof(temp::RTAO_CBData), 0, frame_idx, (std::uint8_t*)& cb_data); // FIXME: Uhh wrong pool? + n_render_system.m_camera_pool->Update(data.out_cb_camera_handle, sizeof(temp::RTAO_CBData), 0, frame_idx, (std::uint8_t*)& cb_data); // FIXME: Uhh wrong pool? // Transition depth to NON_PIXEL_RESOURCE - d3d12::TransitionDepth(cmd_list, data.in_deferred_main_rt, ResourceState::DEPTH_WRITE, ResourceState::NON_PIXEL_SHADER_RESOURCE); + d3d12::TransitionDepth(cmd_list, data.out_deferred_main_rt, ResourceState::DEPTH_WRITE, ResourceState::NON_PIXEL_SHADER_RESOURCE); d3d12::BindDescriptorHeap(cmd_list, cmd_list->m_rt_descriptor_heap.get()->GetHeap(), DescriptorHeapType::DESC_HEAP_TYPE_CBV_SRV_UAV, frame_idx, false); d3d12::BindDescriptorHeaps(cmd_list, false); - d3d12::BindComputeConstantBuffer(cmd_list, data.out_cb_handle->m_native, 2, frame_idx); + d3d12::BindComputeConstantBuffer(cmd_list, data.out_cb_camera_handle->m_native, 2, frame_idx); if (!as_build_data.out_blas_list.empty()) { d3d12::BindComputeShaderResourceView(cmd_list, as_build_data.out_tlas.m_natives[frame_idx], 1); } -#ifdef _DEBUG - CreateShaderTables(device, data, frame_idx); -#endif // _DEBUG + d3d12::BindComputeShaderResourceView(cmd_list, as_build_data.out_scene_vb->m_buffer, 3); + + if (as_build_data.out_using_transparency) + { + CreateShaderTables(device, data, "AORaygenEntry_Transparency", { "AOMissEntry" }, { "AOHitGroup" }, frame_idx); + } + else + { + CreateShaderTables(device, data, "AORaygenEntry", { "AOMissEntry" }, { }, frame_idx); + } // Dispatch hybrid ray tracing rays d3d12::DispatchRays(cmd_list, - data.in_hitgroup_shader_table[frame_idx], - data.in_miss_shader_table[frame_idx], - data.in_raygen_shader_table[frame_idx], + data.out_hitgroup_shader_table[frame_idx], + data.out_miss_shader_table[frame_idx], + data.out_raygen_shader_table[frame_idx], static_cast(std::ceil(d3d12::GetRenderTargetWidth(render_target))), static_cast(std::ceil(d3d12::GetRenderTargetHeight(render_target))), 1, frame_idx); // Transition depth back to DEPTH_WRITE - d3d12::TransitionDepth(cmd_list, data.in_deferred_main_rt, ResourceState::NON_PIXEL_SHADER_RESOURCE, ResourceState::DEPTH_WRITE); + d3d12::TransitionDepth(cmd_list, data.out_deferred_main_rt, ResourceState::NON_PIXEL_SHADER_RESOURCE, ResourceState::DEPTH_WRITE); } } @@ -261,9 +273,9 @@ namespace wr if (!resize) { // Small hack to force the allocations to go out of scope, which will tell the allocator to free them - DescriptorAllocation temp1 = std::move(data.out_uav_from_rtv); - DescriptorAllocation temp2 = std::move(data.in_gbuffers); - DescriptorAllocation temp3 = std::move(data.in_depthbuffer); + DescriptorAllocation temp1 = std::move(data.out_output_alloc); + DescriptorAllocation temp2 = std::move(data.out_gbuffer_normal_alloc); + DescriptorAllocation temp3 = std::move(data.out_gbuffer_depth_alloc); } } } diff --git a/src/rt_pipeline_registry.hpp b/src/rt_pipeline_registry.hpp index a27af660..8224a5e8 100644 --- a/src/rt_pipeline_registry.hpp +++ b/src/rt_pipeline_registry.hpp @@ -23,6 +23,7 @@ #include "vertex.hpp" #include "d3d12/d3dx12.hpp" #include "d3d12/d3d12_enums.hpp" +#include "d3d12/d3d12_structs.hpp" #include "util/named_type.hpp" namespace wr @@ -36,7 +37,7 @@ namespace wr { RegistryHandle shader_handle; std::vector exports; - std::vector> m_hit_groups; // first = hit group | second = entry + std::vector m_hit_groups; }; CD3DX12_STATE_OBJECT_DESC desc; diff --git a/tests/demo/scene_viknell.cpp b/tests/demo/scene_viknell.cpp index 63606f42..1df881c5 100644 --- a/tests/demo/scene_viknell.cpp +++ b/tests/demo/scene_viknell.cpp @@ -47,8 +47,8 @@ void ViknellScene::LoadResources() // Materials m_mirror_material = m_material_pool->Create(m_texture_pool.get()); wr::Material* mirror_internal = m_material_pool->GetMaterial(m_mirror_material); - mirror_internal->SetConstant(0); - mirror_internal->SetConstant(1); + mirror_internal->SetConstant(0.0f); + mirror_internal->SetConstant(1.0f); mirror_internal->SetConstant({ 1, 1, 1 }); m_bamboo_material = m_material_pool->Create(m_texture_pool.get());