Skip to content

Commit 0c62911

Browse files
committed
Improved BVH building performance
Improved Binary BVH builder by ~15% Improved CWBVH builder by ~20% Improved light BVH builder by ~40% Improved misc BVH conversion perf Reduced peak memory use of CWBVH Improved quality of sky adding to radcache Small fix to restir under very specific conditions with mesh normals Small performance improvement to BVH refitting Updated ReadMe
1 parent 20c87ac commit 0c62911

File tree

13 files changed

+365
-274
lines changed

13 files changed

+365
-274
lines changed

README.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
<li>Convolution Bloom(Not mine)</li>
4242
<li>Vulkan and Metal support(Your mileage may vary)</li>
4343
<li>Mesh slicing using SDFs(Does not modify meshes, for rendering cuts only, like cross-sections)</li>
44-
<li>EON and vMF diffuse models</li>
45-
<li>Chromatic Aberation, Contrast/Saturation, Colored Vignette</li>
44+
<li>Lambert or EON diffuse models</li>
45+
<li>Chromatic Aberation, Saturation, Colored Vignette</li>
4646
<li>Full Multiscatter Fog(Not realtime)</li>
4747
<li>Orthographic Camera</li>
4848
</ul>
@@ -106,7 +106,7 @@ for bringing bindless textures to unity!
106106
<li>The green/red rectangle shows when the acceleration structure is done building, and thus ready to render, red means that its not done, and green means its done building, a ding will sound when it completes if it takes longer than 15 seconds(Turn on Truetrace Settings -> Functionality Settings</li>
107107
<li>Objects can be added and removed at will simply by toggling the associated GameObject with a ParentObject script on/off in the hierarchy(clicking on parent objects with complex objects for children will lag), but they will take time to appear as the acceleration structure needs to be rebuilt for them</li>
108108
<li>Emissive meshes need to be have a non-zero emissive value when they are built or rebuilt to work with NEE, but after that can have their emissiveness changed at will</li>
109-
<li>To set up PBR with the DEFAULT material, all textures go into their proper names, but Roughness goes into the Occlusion texture(This can be changed in the MaterialPairing menu)</li>
109+
<li>To set up PBR with the DEFAULT BIRP material, all textures go into their proper names, but Roughness goes into the Occlusion texture(This can be changed in the MaterialPairing menu)</li>
110110
<li>If you are using blendshapes to change geometry of a skinned mesh, you may need to go to the import settings of it(in the inspector), turn off Legacy Blendshape Normals, and make sure all normals are imported, not calculated, otherwise the normals for blendshapes might be wrong</li>
111111
<li>If you use HDRIs, or CubeMaps for the skybox, you need to format as the texture to a Texture2D in the inspector of the image, unity will convert it automatically, then put it in the slot in "Scene Settings" in the TrueTrace settings menu</li>
112112
</ul>
@@ -125,23 +125,28 @@ for bringing bindless textures to unity!
125125

126126
## Linking Shader Textures to TrueTrace
127127
<ul>
128+
<li>You only need to do this once per SHADER, not once per material. Unconfigured shaders will just appear white in truetrace</li>
128129
<li>In the PathTracingSettings, click the tab called "Material Pair Options"</li>
129130
<li>Drag any material that has the shader you want to pair into the material slot that appears</li>
130-
<li>From here, you will see 4 buttons, click those to add the input type and connect it to the output tab. Do this with the default material for an example</li>
131+
<li>From here, you will see 3 buttons, click those to add the input type and connect it to the output tab. Do this with the any material using the default shader for an example</li>
131132
<li>Once this is done, click "Apply Material Links" and rebuild the BVH in the "Main Options" tab to update the objects in the scene</li>
132133
</ul>
133134

134135
## Functionality Settings Contents
135136
<ul>
137+
<li>NOTE FIRST: MOST OF THESE IN THIS TABLE NOW HAVE TOOLTIPS THAT APPEAR IF YOU HOVER OVER THEM!</li>
136138
<li>Enable RT Cores - (DX12 Only, REQUIRES UNITY 2023 OR HIGHER)Enables Hardware RT for cards that support it.</li>
137-
<li>Disable Bindless Textures - DX12 Only, Disables bindless texturing, and uses the atlas fallback(Limits resolution).</li>
139+
<li>Disable Bindless Textures - DX11(/vulkan/metal) compatability, Disables bindless texturing, and uses the atlas fallback(Limits resolution).</li>
138140
<li>Use Old Light BVH Instead of Gaussian Tree - Disables the Gaussian Tree for higher performance but worse light sampling on metallics.</li>
139-
<li>Use DX11 - Disables DX12 only toggles, but allows truetrace to run in DX11.</li>
141+
<li>Use DX11 - Disables DX12 only toggles, but allows truetrace to run in DX11(/vulkan/metal).</li>
140142
<li>Enable OIDN - (DX12 Only) Adds the OIDN denoiser to the Denoiser list in "Main Options"</li>
141143
<li>FULLY Disable Radiance Cache - Will free the memory usually used by the Radiance Cache</li>
142144
<li>Remove Rasterization Requirement - Truetrace stops using rasterization for anything(other than upscaling with TAAU), so you can turn off rasterization rendering in your cameras for extra performance</li>
143145
<li>Enable Emissive Texture Aware Light BVH - Allows for smarter/better sampling of emissive meshes by considering their emissive masks/textures; Can use lots of RAM.</li>
144-
<li>Use Light BVH - Toggles the use of EITHER the Light BVH or Gaussian Tree on/off; uses the RIS count of NEE if off. Turn off for maximum speed.</li>
146+
<li>Enable Verbose Logging - Truetrace will yell more information into the console.</li>
147+
<li>Fade Mapping - Not super compatable with realtime denoisers, but allows for surfaces with variable transparency, based on alpha texture.</li>
148+
<li>Stained Glass - Whether or not to color shadow rays that pass through colored glass, dictated by material parameters: Thin, Albedo, Scatter Distance.</li>
149+
<li>Use Light BVH - Toggles the use of EITHER the Light BVH or Gaussian Tree on/off; uses the RIS count of NEE if off. Turn off for maximum speed, but poor emissive mesh sampling quality.</li>
145150
<li>Quick Radcache Toggle - Toggles the radcache on/off. Useful for comparing to ground truth pathtracing.</li>
146151
</ul>
147152

@@ -168,8 +173,7 @@ TrueTrace Options Description -
168173
<li>Use ReSTIR GI - Enables ReSTIR GI which is usually much higher quality(Works with Recur and SVGF denoisers)</li>
169174
<ul>
170175
<li>Do Sample Connection Validation - Confirms that two samples are mutually visable and throws it away if they are not</li>
171-
<li>Update Rate - How many pixels per frame get re-traced to ensure they are still valid paths(7 or 33 is a good number to aim for here at 1080p)</li>]
172-
<li>Enable Temporal - Enables the Temporal pass of ReSTIR GI(allows samples to travel across time</li>
176+
<li>Enable Temporal - Enables the Temporal pass of ReSTIR GI(allows samples to travel across time, current useless)</li>
173177
<li>Temporal M Cap - How long a sample may live for, lower means lighting updates faster(until 0 which is the opposite) but more noise(recommended either 0 or around 12, but can be played with)</li>
174178
<li>Enable Spatial - Enables the Spatial pass of ReSTIR GI(Allows pixels to choose to use the neighboring pixels sample instead)</li>
175179
</ul>
@@ -181,7 +185,7 @@ TrueTrace Options Description -
181185
<li>Anti-Firefly Frame Interval - Anti-Firefly will run once every X frames, this is X</li>
182186
</ul>
183187
<li>RR Ignores Primary Hit - Allows for an extra bounce basically, makes it so that dark objects arent noisier, but at the cost of performance</li>
184-
<li>Atmospheric Scatter Samples - Lower this to 1 if you keep crashing on entering play mode(controls how many atmospheric samples are precomputed)</li>
188+
<li>Atmospheric Scatter Samples - controls how many multiscatter atmospheric samples are precomputed</li>
185189
<li>Current Samples - Shows how many samples have currently been accumulated</li>
186190
<li>Enable Tonemapping - Turns on tonemapping, and allows you to select a specific tonemapper</li>
187191
<li>Use Sharpness Filter - Contrast Adaptive Sharpening</li>
@@ -234,12 +238,10 @@ TrueTrace Options Description -
234238
<li>Github Sponsors:</li>
235239
<ul>
236240
<li>Jhin: $5</li>
237-
<li>Kevin: $5</li>
238241
<li>Omid: $2</li>
239242
</ul>
240243
<li>Kofi:</li>
241244
<ul>
242-
<li>JiRo: $20</li>
243245
</ul>
244246
</ul>
245247
</ul>

TrueTrace.unitypackage

-7.84 KB
Binary file not shown.

TrueTrace/DemoScene.asset

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ MonoBehaviour:
1919
UseRussianRoulette: 1
2020
UseNEE: 1
2121
DoTLASUpdates: 1
22-
Accumulate: 0
22+
Accumulate: 1
2323
PPBloom: 0
2424
BloomStrength: 0.5
2525
PPDoF: 0
@@ -28,7 +28,7 @@ MonoBehaviour:
2828
DoFFocal: 5.2216897
2929
PPExposure: 0
3030
ExposureAuto: 0
31-
PPToneMap: 0
31+
PPToneMap: 1
3232
PPTAA: 0
3333
RenderScale: 1
3434
DenoiserMethod: 0

TrueTrace/DemoScene.unity

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ RenderSettings:
3838
m_ReflectionIntensity: 1
3939
m_CustomReflection: {fileID: 0}
4040
m_Sun: {fileID: 0}
41-
m_IndirectSpecularColor: {r: 0.1774876, g: 0.2222052, b: 0.30441606, a: 1}
41+
m_IndirectSpecularColor: {r: 0.17605689, g: 0.22033103, b: 0.302659, a: 1}
4242
m_UseRadianceAmbientProbe: 0
4343
--- !u!157 &3
4444
LightmapSettings:
@@ -12485,9 +12485,9 @@ MonoBehaviour:
1248512485
b:
1248612486
BBMax: {x: 0.5, y: 0.5, z: 0.5}
1248712487
BBMin: {x: -0.5, y: -0.5, z: -0.5}
12488-
w: {x: -0.263612, y: 0.9558199, z: 0.13006341}
12488+
w: {x: -0.7714121, y: 0.39507377, z: 0.49883944}
1248912489
phi: 378.83908
12490-
cosTheta_o: -0.9960918
12490+
cosTheta_o: -0.9970375
1249112491
cosTheta_e: 0.0000012675908
1249212492
LightCount: 768
1249312493
Pad1: 0
@@ -12613,7 +12613,7 @@ MonoBehaviour:
1261312613
LightBLASRefitKernel: 7
1261412614
CompactedMeshData: 0
1261512615
InstanceReferences: 0
12616-
NeedsToUpdate: 1
12616+
NeedsToUpdate: 0
1261712617
FailureCount: 0
1261812618
TotalTriangles: 0
1261912619
IsSkinnedGroup: 0
@@ -15117,12 +15117,12 @@ MonoBehaviour:
1511715117
UseKelvin: 0
1511815118
IsMainSun: 1
1511915119
KelvinTemperature: 1000
15120-
Intensity: 32
15120+
Intensity: 122
1512115121
Col: {x: 1, y: 1, z: 1}
1512215122
SpotAngle: 30
1512315123
HasInitialized: 1
1512415124
IESProfile: {fileID: 0}
15125-
NeedsToUpdate: 0
15125+
NeedsToUpdate: 1
1512615126
--- !u!108 &610660759
1512715127
Light:
1512815128
m_ObjectHideFlags: 0
@@ -15135,7 +15135,7 @@ Light:
1513515135
m_Type: 1
1513615136
m_Shape: 0
1513715137
m_Color: {r: 1, g: 1, b: 1, a: 1}
15138-
m_Intensity: 32
15138+
m_Intensity: 122
1513915139
m_Range: 10
1514015140
m_SpotAngle: 30
1514115141
m_InnerSpotAngle: 21.80208
@@ -15192,14 +15192,14 @@ Transform:
1519215192
m_PrefabInstance: {fileID: 0}
1519315193
m_PrefabAsset: {fileID: 0}
1519415194
m_GameObject: {fileID: 610660757}
15195-
m_LocalRotation: {x: 0.45743093, y: 0.38903746, z: -0.20943484, w: 0.77171487}
15195+
m_LocalRotation: {x: 0.49363983, y: 0.3759464, z: -0.22951967, w: 0.7498698}
1519615196
m_LocalPosition: {x: -1.4816499, y: 5.724826, z: -1.1294421}
1519715197
m_LocalScale: {x: 1, y: 1, z: 1}
1519815198
m_ConstrainProportionsScale: 0
1519915199
m_Children: []
1520015200
m_Father: {fileID: 0}
1520115201
m_RootOrder: 1
15202-
m_LocalEulerAnglesHint: {x: 60.339, y: 55.708, z: 3.785}
15202+
m_LocalEulerAnglesHint: {x: 65.91, y: 55.708, z: 3.785}
1520315203
--- !u!4 &611049998 stripped
1520415204
Transform:
1520515205
m_CorrespondingSourceObject: {fileID: -4090820614514019212, guid: 16500a523b718314091d7e9b83146c62,
@@ -23769,7 +23769,7 @@ MonoBehaviour:
2376923769
MatType: 0
2377023770
TransmittanceColor: {x: 0, y: 0, z: 0}
2377123771
IOR: 1
23772-
Metallic: 0.35899997
23772+
Metallic: 0
2377323773
Sheen: 0
2377423774
SheenTint: 0
2377523775
SpecularTint: 0
@@ -53992,7 +53992,7 @@ MonoBehaviour:
5399253992
LightBLASRefitKernel: 7
5399353993
CompactedMeshData: 0
5399453994
InstanceReferences: 0
53995-
NeedsToUpdate: 1
53995+
NeedsToUpdate: 0
5399653996
FailureCount: 0
5399753997
TotalTriangles: 0
5399853998
IsSkinnedGroup: 0
@@ -60473,7 +60473,7 @@ MonoBehaviour:
6047360473
LightBLASRefitKernel: 7
6047460474
CompactedMeshData: 3
6047560475
InstanceReferences: 0
60476-
NeedsToUpdate: 1
60476+
NeedsToUpdate: 0
6047760477
FailureCount: 0
6047860478
TotalTriangles: 0
6047960479
IsSkinnedGroup: 0

TrueTrace/Resources/Builders/BVH2Builder.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ unsafe public class BVH2Builder {
1919
public float* SAH;
2020
public AABB* Primitives;
2121

22-
// public BVHNodeVerbose[] VerboseNodes;
23-
24-
2522
public NativeArray<BVHNode2Data> BVH2NodesArray;
2623
public NativeArray<int> DimensionedIndicesArray;
2724
public NativeArray<int> tempArray;
@@ -54,20 +51,32 @@ void partition_sah(int first_index, int index_count) {
5451
split.aabb_right.init();
5552

5653
int Offset;
54+
float left_cost;
55+
float cost;
56+
int first_right;
57+
int i;
5758
for(int dimension = 0; dimension < 3; dimension++) {
5859
aabb_right.init();
5960
Offset = PrimCount * dimension + first_index;
60-
for(int i = 1; i < index_count; i++) {
61+
first_right = index_count;
62+
for(i = 1; i < index_count; i++) {
6163
aabb_right.Extend(ref Primitives[DimensionedIndices[Offset + i - 1]]);
62-
6364
SAH[i] = surface_area(ref aabb_right) * (float)i;
65+
if(SAH[i] > split.cost) {
66+
first_right = i + 1;
67+
break;
68+
}
6469
}
6570
aabb_right.init();
71+
for(i = index_count - 1; i >= first_right; i--)
72+
aabb_right.Extend(ref Primitives[DimensionedIndices[Offset + i]]);
6673

67-
for(int i = index_count - 1; i > 0; i--) {
74+
for(i = first_right - 1; i > 0; i--) {
6875
aabb_right.Extend(ref Primitives[DimensionedIndices[Offset + i]]);
6976

70-
float cost = SAH[i] + surface_area(ref aabb_right) * (float)(index_count - i);
77+
left_cost = surface_area(ref aabb_right) * (float)(index_count - i);
78+
if(left_cost >= split.cost) break;
79+
cost = SAH[i] + left_cost;
7180

7281
if(cost <= split.cost) {
7382
split.cost = cost;
@@ -78,7 +87,7 @@ void partition_sah(int first_index, int index_count) {
7887
}
7988
}
8089
Offset = split.dimension * PrimCount;
81-
for(int i = first_index; i < split.index; i++) split.aabb_left.Extend(ref Primitives[DimensionedIndices[Offset + i]]);
90+
for(i = first_index; i < split.index; i++) split.aabb_left.Extend(ref Primitives[DimensionedIndices[Offset + i]]);
8291
}
8392
void BuildRecursive(int nodesi, ref int node_index, int first_index, int index_count) {
8493
if(index_count == 1) {

0 commit comments

Comments
 (0)