Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Feature rt transparency #383

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
186bace
[CHANGE] Adding transparency. Committing because I need to merge mast…
LaisoEmilio Jun 7, 2019
955b3c5
[CHANGE] Refactored AO shader a bit, adding RAY_FLAG_FORCE_OPAQUE fix…
LaisoEmilio Jun 7, 2019
bc2154e
[CHANGE] Prototyped ray layers
LaisoEmilio Jun 12, 2019
19e240e
[CHANGE] Pushing to switch branch
LaisoEmilio Jun 13, 2019
5a3ddf0
Merge remote-tracking branch 'origin/master' into feature_rt_transpar…
LaisoEmilio Jun 13, 2019
a20c8c1
Merge remote-tracking branch 'origin/master' into feature_rt_transpar…
LaisoEmilio Jun 14, 2019
2675503
[CHANGE] Added transparency to hybrid path tracer
LaisoEmilio Jun 14, 2019
7673050
[CHANGES]
LaisoEmilio Jun 15, 2019
d3644d1
Merged with master and added transparency to Ambient Occlusion
LaisoEmilio Jun 17, 2019
5e5af30
[CHANGE] Shadows were bugged in full raytracing
LaisoEmilio Jun 18, 2019
9fccc9b
[CHANGE] Acted on some of the feedback from Pull Request
LaisoEmilio Jun 18, 2019
c6f6497
[CHANGE] Reverted left out debug code
LaisoEmilio Jun 19, 2019
a61279a
[CHANGE]
LaisoEmilio Jun 20, 2019
cc1682b
Merge remote-tracking branch 'origin/master' into feature_rt_transpar…
LaisoEmilio Jun 20, 2019
fad5a33
[CHANGE] Re-named function as requested in the PR
LaisoEmilio Jun 20, 2019
479c5af
Merge remote-tracking branch 'origin/master' into feature_rt_transpar…
LaisoEmilio Jun 20, 2019
6c7f2fc
Merge branch 'master' into feature_rt_transparency
LaisoEmilio Jun 22, 2019
1090d5e
[CHANGE] Merged with master. Also, ifdef DEBUG in ambient occlusion t…
LaisoEmilio Jun 22, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 46 additions & 32 deletions imgui.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Size=228,150
Collapsed=1

[Window][Theme]
Pos=1032,376
Size=248,201
Pos=1032,222
Size=248,219
Collapsed=0
DockId=0x00000009,0

Expand Down Expand Up @@ -46,14 +46,14 @@ Size=169,259
Collapsed=0

[Window][DirectX 12 Settings]
Pos=1032,376
Size=248,201
Pos=1032,222
Size=248,219
Collapsed=0
DockId=0x00000009,2

[Window][Hardware Info]
Pos=1032,376
Size=248,201
Pos=1032,222
Size=248,219
Collapsed=0
DockId=0x00000009,1

Expand Down Expand Up @@ -86,7 +86,7 @@ DockId=0x00000007,1

[Window][Inspector]
Pos=1032,21
Size=248,353
Size=248,199
Collapsed=0
DockId=0x00000006,0

Expand All @@ -112,51 +112,65 @@ Size=303,134
Collapsed=0

[Window][RTAO Settings]
Pos=1032,579
Size=248,141
Pos=1032,443
Size=248,121
Collapsed=0
DockId=0x0000000A,0
DockId=0x0000000B,0

[Window][HBAO+ Settings]
Pos=1032,579
Size=248,141
Pos=1032,443
Size=248,277
Collapsed=0
DockId=0x0000000A,0
DockId=0x0000000B,0

[Window][NVIDIA Ansel Settings]
Pos=1032,376
Size=248,201
Pos=1032,222
Size=248,219
Collapsed=0
DockId=0x00000009,3

[Window][Acceleration Structure Settings]
Pos=1032,579
Size=248,141
Pos=1032,566
Size=248,154
Collapsed=0
DockId=0x0000000A,1
DockId=0x0000000C,0

[Window][Shadow Settings]
Pos=1032,579
Size=248,141
Pos=1032,443
Size=248,121
Collapsed=0
DockId=0x0000000A,2
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,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
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

63 changes: 61 additions & 2 deletions resources/shaders/dxr_ambient_occlusion.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ typedef BuiltInTriangleIntersectionAttributes Attributes;
struct AOHitInfo
{
float is_hit;
float thisvariablesomehowmakeshybridrenderingwork_killme;
float padding;
LaisoEmilio marked this conversation as resolved.
Show resolved Hide resolved
};

cbuffer CBData : register(b0)
Expand Down Expand Up @@ -83,8 +83,68 @@ bool TraceAORay(uint idx, float3 origin, float3 direction, float far, unsigned i
return payload.is_hit;
}

bool TraceAORay_Optimized(uint idx, float3 origin, float3 direction, float far, unsigned int depth)
LaisoEmilio marked this conversation as resolved.
Show resolved Hide resolved
{
// 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_ACCEPT_FIRST_HIT_AND_END_SEARCH | RAY_FLAG_SKIP_CLOSEST_HIT_SHADER,
~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;
}

[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_Optimized(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);
Expand Down Expand Up @@ -116,7 +176,6 @@ void AORaygenEntry()
{
output[DispatchRaysIndex().xy].x = 1.f;
}

}

[shader("closesthit")]
Expand Down
17 changes: 3 additions & 14 deletions resources/shaders/dxr_raytracing.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ SamplerState point_sampler : register(s1);
typedef BuiltInTriangleIntersectionAttributes Attributes;

#include "dxr_pathtracer_functions.hlsl"
#include "dxr_shadow_entries.hlsl"

cbuffer CameraProperties : register(b0)
{
Expand Down Expand Up @@ -231,21 +232,9 @@ void ClosestHitEntry(inout FullRTHitInfo payload, in Attributes attr)
}

nextRand(payload.seed);
//payload.color = ggxIndirect(hit_pos, fN, N, V, albedo, metal, roughness, ao, payload.seed, payload.depth + 1);
payload.color = ggxDirect(hit_pos, fN, N, V, albedo, metal, roughness, payload.seed, payload.depth + 1);
payload.color = ggxIndirect(hit_pos, fN, N, V, albedo, metal, roughness, ao, payload.seed, payload.depth + 1);
payload.color += ggxDirect(hit_pos, fN, N, V, albedo, metal, roughness, payload.seed, payload.depth + 1);
payload.color += emissive;
}

[shader("closesthit")]
void ShadowClosestHitEntry(inout ShadowHitInfo hit, Attributes bary)
{
hit.ray_power = 0.1f;
}

[shader("miss")]
void ShadowMissEntry(inout ShadowHitInfo hit : SV_RayPayload)
{
hit.ray_power = 1.0f;
}

#endif //__DXR_RAYTRACING_HLSL__
10 changes: 1 addition & 9 deletions resources/shaders/dxr_shadow_entries.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
[shader("closesthit")]
void ShadowClosestHitEntry(inout ShadowHitInfo hit, Attributes bary)
{
hit.ray_power = 0.1f;
hit.is_hit = true;
}

Expand Down Expand Up @@ -86,16 +85,9 @@ void ShadowAnyHitEntry(inout ShadowHitInfo hit, Attributes attr)
{
IgnoreHit();
}

hit.ray_power -= (1.0f / 3.0f);

if (hit.ray_power <= 0.02f)
{
AcceptHitAndEndSearch();
}
else
{
IgnoreHit();
AcceptHitAndEndSearch();
}
}
else
Expand Down
14 changes: 7 additions & 7 deletions resources/shaders/dxr_shadow_functions.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "dxr_global.hlsl"
#include "dxr_structs.hlsl"

float TraceShadowRay(float3 origin, float3 direction, float far, uint calling_pass, unsigned int depth)
bool TraceShadowRay(float3 origin, float3 direction, float far, uint calling_pass, unsigned int depth)
{
if (depth >= MAX_RECURSION)
{
Expand All @@ -33,7 +33,7 @@ float TraceShadowRay(float3 origin, float3 direction, float far, uint calling_pa
ray.TMin = 0;
ray.TMax = far;

ShadowHitInfo payload = { false, 1.0f };
ShadowHitInfo payload = { false, 0.0f };

uint ray_contr_idx = 1;
uint miss_idx = 1;
Expand All @@ -55,7 +55,7 @@ float TraceShadowRay(float3 origin, float3 direction, float far, uint calling_pa
ray,
payload);

return payload.ray_power;
return payload.is_hit;
}

// Get shadow factor
Expand All @@ -70,18 +70,18 @@ float GetShadowFactor(float3 wpos, float3 light_dir, float light_size, float t_m
float3 dir = perturbDirectionVector(rand_seed, light_dir, light_size);
float3 ray_direction = normalize(dir);

float shadow = TraceShadowRay(wpos, ray_direction, t_max, calling_pass, depth);
bool shadow = TraceShadowRay(wpos, ray_direction, t_max, calling_pass, depth);

shadow_factor += shadow;
shadow_factor += lerp(1.0, 0.0, shadow);
}

shadow_factor /= float(sample_count);

#else //SOFT_SHADOWS

float shadow = TraceShadowRay(wpos, light_dir, t_max, calling_pass, depth);
bool shadow = TraceShadowRay(wpos, light_dir, t_max, calling_pass, depth);

shadow_factor = shadow;
shadow_factor = !shadow;

#endif //SOFT_SHADOWS

Expand Down
2 changes: 1 addition & 1 deletion resources/shaders/dxr_structs.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct ReflectionHitInfo
struct ShadowHitInfo
{
float is_hit;
float ray_power;
float padding;
};

struct PathTracingHitInfo
Expand Down
2 changes: 1 addition & 1 deletion src/d3d12/d3d12_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,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 */
3 changes: 2 additions & 1 deletion src/d3d12/d3d12_shader_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Loading