Skip to content

Commit 162b3b3

Browse files
committed
Emergency Hotfix
Emergency hotfix because I uploaded the wrong file Small modification to restir GI temporal to use plane distance
1 parent e0aa9e0 commit 162b3b3

File tree

6 files changed

+97
-4
lines changed

6 files changed

+97
-4
lines changed

TrueTrace.unitypackage

67 MB
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: 1
22+
Accumulate: 0
2323
PPBloom: 0
2424
BloomStrength: 0.805
2525
PPDoF: 0
@@ -36,7 +36,7 @@ MonoBehaviour:
3636
ReSTIRGIUpdateRate: 7
3737
UseReSTIRGITemporal: 1
3838
UseReSTIRGISpatial: 1
39-
UseReSTIRGI: 0
39+
UseReSTIRGI: 1
4040
ReSTIRGISpatialCount: 24
4141
ReSTIRGISpatialRadius: 50
4242
ReSTIRGITemporalMCap: 32

TrueTrace/Resources/MainCompute/CommonData.cginc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
float4x4 CamToWorld;
77
float4x4 CamInvProj;
8+
float4x4 CamToWorldPrev;
9+
float4x4 CamInvProjPrev;
810

911
float4x4 ViewMatrix;
1012
int MaxBounce;
@@ -556,6 +558,19 @@ inline SmallerRay CreateCameraRay(float2 uv) {
556558
return CreateRay(origin, direction);
557559
}
558560

561+
inline SmallerRay CreateCameraRayPrev(float2 uv) {
562+
// Transform the camera origin to world space
563+
float3 origin = mul(CamToWorldPrev, float4(0.0f, 0.0f, 0.0f, 1.0f)).xyz;
564+
565+
// Invert the perspective projection of the view-space position
566+
float3 direction = mul(CamInvProjPrev, float4(uv, 0.0f, 1.0f)).xyz;
567+
// Transform the direction from camera to world space and normalize
568+
direction = mul(CamToWorldPrev, float4(direction, 0.0f)).xyz;
569+
direction = normalize(direction);
570+
571+
return CreateRay(origin, direction);
572+
}
573+
559574
inline float2 AlignUV(float2 BaseUV, const float4 TexScale, const int2 TexDim2, float Rotation = 0, bool IsAlbedo = false) {
560575
if(TexDim2.x <= 0) return -1;
561576
float4 TexDim;

TrueTrace/Resources/MainCompute/ReSTIRGI.compute

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ void ReSTIRGIKernel(uint3 id : SV_DispatchThreadID, uint3 id2 : SV_GroupThreadID
131131
const float3 GeomNorm = i_octahedral_32(asuint(GBuffer.x));
132132
const float3 SurfNorm = i_octahedral_32(asuint(GBuffer.y));
133133
float3 PrimaryHitPosition = LoadSurfaceInfo(id.xy);
134+
const float3 DirectionalPosition = GBuffer.z * CameraRay.direction + CameraRay.origin;
134135

135136
ColData CenterCol = GlobalColors[pixel_index];
136137
float4 Data = CenterCol.Data;
@@ -211,7 +212,9 @@ void ReSTIRGIKernel(uint3 id : SV_DispatchThreadID, uint3 id2 : SV_GroupThreadID
211212
if(UseReSTIRGITemporal && (!RetracedSample)) {
212213
float dist_depth = (abs(GBuffer.z - PrevGBuffer.z)) / abs(GBuffer.z);
213214
float dot_geo_normals = dot(GeomNorm, i_octahedral_32(asuint(PrevGBuffer.x)));
214-
if ((dist_depth < 0.1f && dot_geo_normals > 0.7) && Case != 3 && IsTemporalValid) {
215+
SmallerRay NeighborRay = CreateCameraRayPrev(prevIndex / float2(screen_width, screen_height) * 2.0f - 1.0f);
216+
float3 ray = (PrevGBuffer.z * NeighborRay.direction + NeighborRay.origin) - DirectionalPosition;
217+
if ((abs(dot(GeomNorm, ray)) < 0.1f && dot_geo_normals > 0.7) && Case != 3 && IsTemporalValid) {
215218
// if(PrevRes.z != 0 || ggx_distribution(dot(normalize(-normalize(CalcPos(WorldPosB[prevIndex]) - PrimaryHitPosition) + CameraRay.direction), SurfNorm), clamp(SurfaceMat.roughness, 0.089 * 0.089, 1.0)) > 0.1f * randomNEE(126, pixel_index).y) {
216219
UpdateReservoir(CurrentRes, wsum, PrevRes, randomNEE(126, pixel_index).x, CachedID, prevIndex);
217220
CurrentRes.x += PrevRes.x;

TrueTrace/Resources/RayTracingMaster.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,8 @@ private void SetBool(string Name, bool IN) {
440440
GenerateShader.SetBool(Name, IN);
441441
ReSTIRGI.SetBool(Name, IN);
442442
}
443-
443+
Matrix4x4 CamInvProjPrev;
444+
Matrix4x4 CamToWorldPrev;
444445
Vector3 PrevPos;
445446
private Vector2 HDRIParams = Vector2.zero;
446447
private void SetShaderParameters(CommandBuffer cmd)
@@ -468,8 +469,14 @@ private void SetShaderParameters(CommandBuffer cmd)
468469
ShadingShader.SetComputeBuffer(TransferKernel, "BufferData", CurBounceInfoBuffer);
469470
ShadingShader.SetComputeBuffer(ShadeKernel, "BufferData", CurBounceInfoBuffer);
470471

472+
var EA = CamToWorldPrev;
473+
var EB = CamInvProjPrev;
474+
CamInvProjPrev = _camera.projectionMatrix.inverse;
475+
CamToWorldPrev = _camera.cameraToWorldMatrix;
471476
SetMatrix("CamInvProj", _camera.projectionMatrix.inverse);
472477
SetMatrix("CamToWorld", _camera.cameraToWorldMatrix);
478+
SetMatrix("CamInvProjPrev", EB);
479+
SetMatrix("CamToWorldPrev", EA);
473480
SetMatrix("ViewMatrix", _camera.worldToCameraMatrix);
474481
var E = _camera.transform.position - PrevPos;
475482
SetVector("Up", _camera.transform.up, cmd);

TrueTrace/Resources/Utility/MaterialPresets.xml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,72 @@
6868
<Rotation>0</Rotation>
6969
<Flags>0</Flags>
7070
</RayObjectDatas>
71+
<RayObjectDatas>
72+
<ID>0</ID>
73+
<MatName>Glass</MatName>
74+
<OptionID>1</OptionID>
75+
<TransCol>
76+
<x>0</x>
77+
<y>0</y>
78+
<z>0</z>
79+
</TransCol>
80+
<BaseCol>
81+
<x>1</x>
82+
<y>1</y>
83+
<z>1</z>
84+
</BaseCol>
85+
<MetRemap>
86+
<x>0</x>
87+
<y>1</y>
88+
</MetRemap>
89+
<RoughRemap>
90+
<x>0</x>
91+
<y>1</y>
92+
</RoughRemap>
93+
<Emiss>0</Emiss>
94+
<EmissCol>
95+
<x>1</x>
96+
<y>1</y>
97+
<z>1</z>
98+
</EmissCol>
99+
<Rough>0</Rough>
100+
<IOR>1.33</IOR>
101+
<Met>0</Met>
102+
<SpecTint>0</SpecTint>
103+
<Sheen>0</Sheen>
104+
<SheenTint>0</SheenTint>
105+
<Clearcoat>0</Clearcoat>
106+
<ClearcoatGloss>0</ClearcoatGloss>
107+
<Anisotropic>0</Anisotropic>
108+
<Flatness>0</Flatness>
109+
<DiffTrans>0</DiffTrans>
110+
<SpecTrans>1</SpecTrans>
111+
<FollowMat>false</FollowMat>
112+
<ScatterDist>0</ScatterDist>
113+
<Spec>0</Spec>
114+
<AlphaCutoff>0.1</AlphaCutoff>
115+
<NormStrength>1</NormStrength>
116+
<Hue>0</Hue>
117+
<Saturation>1</Saturation>
118+
<Brightness>1</Brightness>
119+
<Contrast>1</Contrast>
120+
<BlendColor>
121+
<x>1</x>
122+
<y>1</y>
123+
<z>1</z>
124+
</BlendColor>
125+
<BlendFactor>0</BlendFactor>
126+
<MainTexScaleOffset>
127+
<x>1</x>
128+
<y>1</y>
129+
<z>0</z>
130+
<w>0</w>
131+
</MainTexScaleOffset>
132+
<SecondaryTextureScale>
133+
<x>1</x>
134+
<y>1</y>
135+
</SecondaryTextureScale>
136+
<Rotation>0</Rotation>
137+
<Flags>0</Flags>
138+
</RayObjectDatas>
71139
</RayObjs>

0 commit comments

Comments
 (0)