-
Notifications
You must be signed in to change notification settings - Fork 56
/
ProbeCommon.hlsl
100 lines (80 loc) · 3.98 KB
/
ProbeCommon.hlsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* Copyright (c) 2019-2023, NVIDIA CORPORATION. All rights reserved.
*
* NVIDIA CORPORATION and its licensors retain all intellectual property
* and proprietary rights in and to this software, related documentation
* and any modifications thereto. Any use, reproduction, disclosure or
* distribution of this software and related documentation without an express
* license agreement from NVIDIA CORPORATION is strictly prohibited.
*/
#ifndef RTXGI_DDGI_PROBE_COMMON_HLSL
#define RTXGI_DDGI_PROBE_COMMON_HLSL
#include "Common.hlsl"
#include "ProbeDataCommon.hlsl"
#include "ProbeRayCommon.hlsl"
#include "ProbeIndexing.hlsl"
#include "ProbeOctahedral.hlsl"
//------------------------------------------------------------------------
// Probe World Position
//------------------------------------------------------------------------
/**
* Computes the world-space position of a probe from the probe's 3D grid-space coordinates.
* Probe relocation is not considered.
*/
float3 DDGIGetProbeWorldPosition(int3 probeCoords, DDGIVolumeDescGPU volume)
{
// Multiply the grid coordinates by the probe spacing
float3 probeGridWorldPosition = probeCoords * volume.probeSpacing;
// Shift the grid of probes by half of each axis extent to center the volume about its origin
float3 probeGridShift = (volume.probeSpacing * (volume.probeCounts - 1)) * 0.5f;
// Center the probe grid about the origin
float3 probeWorldPosition = (probeGridWorldPosition - probeGridShift);
// Rotate the probe grid if infinite scrolling is not enabled
if (!IsVolumeMovementScrolling(volume)) probeWorldPosition = RTXGIQuaternionRotate(probeWorldPosition, volume.rotation);
// Translate the grid to the volume's center
probeWorldPosition += volume.origin + (volume.probeScrollOffsets * volume.probeSpacing);
return probeWorldPosition;
}
/**
* Computes the world-space position of a probe from the probe's 3D grid-space coordinates.
* When probe relocation is enabled, offsets are loaded from the probe data
* Texture2D and used to adjust the final world position.
*/
float3 DDGIGetProbeWorldPosition(int3 probeCoords, DDGIVolumeDescGPU volume, Texture2DArray<float4> probeData)
{
// Get the probe's world-space position
float3 probeWorldPosition = DDGIGetProbeWorldPosition(probeCoords, volume);
// If the volume has probe relocation enabled, account for the probe offsets
if (volume.probeRelocationEnabled)
{
// Get the scroll adjusted probe index
int probeIndex = DDGIGetScrollingProbeIndex(probeCoords, volume);
// Find the texture coordinates of the probe in the Probe Data texture
uint3 coords = DDGIGetProbeTexelCoords(probeIndex, volume);
// Load the probe's world-space position offset and add it to the current world position
probeWorldPosition += DDGILoadProbeDataOffset(probeData, coords, volume);
}
return probeWorldPosition;
}
/**
* Computes the world-space position of a probe from the probe's 3D grid-space coordinates.
* When probe relocation is enabled, offsets are loaded from the probe data
* RWTexture2D and used to adjust the final world position.
*/
float3 DDGIGetProbeWorldPosition(int3 probeCoords, DDGIVolumeDescGPU volume, RWTexture2DArray<float4> probeData)
{
// Get the probe's world-space position
float3 probeWorldPosition = DDGIGetProbeWorldPosition(probeCoords, volume);
// If the volume has probe relocation enabled, account for the probe offsets
if (volume.probeRelocationEnabled)
{
// Get the scroll adjusted probe index
int probeIndex = DDGIGetScrollingProbeIndex(probeCoords, volume);
// Find the texture coordinates of the probe in the Probe Data texture
uint3 coords = DDGIGetProbeTexelCoords(probeIndex, volume);
// Load the probe's world-space position offset and add it to the current world position
probeWorldPosition += DDGILoadProbeDataOffset(probeData, coords, volume);
}
return probeWorldPosition;
}
#endif // RTXGI_DDGI_PROBE_COMMON_HLSL