-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcuda_onb.h
More file actions
50 lines (43 loc) · 1012 Bytes
/
cuda_onb.h
File metadata and controls
50 lines (43 loc) · 1012 Bytes
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
//
// Created by 孙万捷 on 16/2/27.
//
#ifndef SUNPATHTRACER_ONB_H
#define SUNPATHTRACER_ONB_H
#include <cuda_runtime.h>
#include "helper_math.h"
class cudaONB
{
public:
__device__ cudaONB(const float3& _w)
{
InitFromW(_w);
}
__device__ cudaONB(const float3& _v, const float3& _w)
{
InitFromVW(_v, _w);
}
__device__ void InitFromW(const float3& _w)
{
w = _w;
if(fabsf(w.x) > fabsf(w.y))
{
float invLength = rsqrtf(w.x * w.x + w.z * w.z);
v = make_float3(-w.z * invLength, 0.f, w.x * invLength);
}
else
{
float invLength = rsqrtf(w.y * w.y + w.z * w.z);
v = make_float3(0.f, w.z * invLength, -w.y * invLength);
}
u = cross(v, w);
}
__device__ void InitFromVW(const float3& _v, const float3& _w)
{
w = _w;
u = cross(_v, w);
v = cross(w, u);
}
public:
float3 u, v, w;
};
#endif //SUNPATHTRACER_ONB_H