This repository was archived by the owner on May 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 135
Expand file tree
/
Copy pathVaOcean_CS.usf
More file actions
65 lines (52 loc) · 1.64 KB
/
VaOcean_CS.usf
File metadata and controls
65 lines (52 loc) · 1.64 KB
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
// Created 2014-2016 Vladimir Alyamkin. MIT license
#include "/Engine/Private/Common.ush"
#define PI 3.1415926536f
#define BLOCK_SIZE_X 16
#define BLOCK_SIZE_Y 16
// Immutable
uint g_ActualDim;
uint g_InWidth;
uint g_OutWidth;
uint g_OutHeight;
uint g_DtxAddressOffset;
uint g_DtyAddressOffset;
// Buffers
StructuredBuffer<float2> g_InputH0;
StructuredBuffer<float> g_InputOmega;
RWStructuredBuffer<float2> g_OutputHt;
//////////////////////////////////////////////////////////////////////////
// Pre-FFT data preparation: H(0) -> H(t)
[numthreads(BLOCK_SIZE_X, BLOCK_SIZE_Y, 1)]
void UpdateSpectrumCS(uint3 DTid : SV_DispatchThreadID)
{
int in_index = DTid.y * g_InWidth + DTid.x;
int in_mindex = (g_ActualDim - DTid.y) * g_InWidth + (g_ActualDim - DTid.x);
int out_index = DTid.y * g_OutWidth + DTid.x;
// H(0) -> H(t)
float2 h0_k = g_InputH0[in_index];
float2 h0_mk = g_InputH0[in_mindex];
float sin_v, cos_v;
sincos(g_InputOmega[in_index] * PerFrameSp.Time, sin_v, cos_v);
float2 ht;
ht.x = (h0_k.x + h0_mk.x) * cos_v - (h0_k.y + h0_mk.y) * sin_v;
ht.y = (h0_k.x - h0_mk.x) * sin_v + (h0_k.y - h0_mk.y) * cos_v;
// H(t) -> Dx(t), Dy(t)
float kx = DTid.x - g_ActualDim * 0.5f;
float ky = DTid.y - g_ActualDim * 0.5f;
float sqr_k = kx * kx + ky * ky;
float rsqr_k = 0;
if (sqr_k > 1e-12f)
{
rsqr_k = 1 / sqrt(sqr_k);
}
kx *= rsqr_k;
ky *= rsqr_k;
float2 dt_x = float2(ht.y * kx, -ht.x * kx);
float2 dt_y = float2(ht.y * ky, -ht.x * ky);
if ((DTid.x < g_OutWidth) && (DTid.y < g_OutHeight))
{
g_OutputHt[out_index] = ht;
g_OutputHt[out_index + g_DtxAddressOffset] = dt_x;
g_OutputHt[out_index + g_DtyAddressOffset] = dt_y;
}
}