-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathoptix_kernels.cu
More file actions
81 lines (64 loc) · 3.19 KB
/
optix_kernels.cu
File metadata and controls
81 lines (64 loc) · 3.19 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "material_sets_shared.h"
using namespace Shared;
RT_PIPELINE_LAUNCH_PARAMETERS PipelineLaunchParameters plp;
struct HitPointParameter {
float b1, b2;
int32_t primIndex;
CUDA_DEVICE_FUNCTION CUDA_INLINE static HitPointParameter get() {
HitPointParameter ret;
float2 bc = optixGetTriangleBarycentrics();
ret.b1 = bc.x;
ret.b2 = bc.y;
ret.primIndex = optixGetPrimitiveIndex();
return ret;
}
};
/*
JP: CH/AH/ISプログラムにてoptixGetSbtDataPointer()で取得できるポインターの位置に
GeometryInstanceAccelerationStructureのsetUserData(), setChildUserData(),
GeometryInstanceのsetUserData(), MaterialのsetUserData()
で設定したデータが順番に並んでいる(各データの相対的な開始位置は指定したアラインメントに従う)。
各データの開始位置は前方のデータのサイズによって変わるので、例えば同じGASに属していても
GASの子ごとのデータサイズが異なればGeometryInstanceのデータの開始位置は異なる可能性があることに注意。
このサンプルではGAS、GASの子達にはユーザーデータは設定していない。
EN: Data set by each of
GeometryInstanceAccelerationStructure's setUserData() and setChildUserData(),
GeometryInstance's setUserData(), Material's setUserData()
line up in the order (Each relative offset follows the specified alignment)
at the position pointed by optixGetSbtDataPointer() called in CH/AH/IS programs.
Note that the start position of each data changes depending on the sizes of forward data.
Therefore for example, the start positions of GeometryInstance's data are different
if data sizes of GAS children are different even if those belong to the same GAS.
This sample does not set user data to GAS and GAS's children.
*/
struct HitGroupSBTRecordData {
GeometryData geomData;
MaterialData matData;
CUDA_DEVICE_FUNCTION CUDA_INLINE static const HitGroupSBTRecordData &get() {
return *reinterpret_cast<HitGroupSBTRecordData*>(optixGetSbtDataPointer());
}
};
CUDA_DEVICE_KERNEL void RT_RG_NAME(raygen)() {
uint2 launchIndex = make_uint2(optixGetLaunchIndex().x, optixGetLaunchIndex().y);
float x = static_cast<float>(launchIndex.x + 0.5f) / plp.imageSize.x;
float y = static_cast<float>(launchIndex.y + 0.5f) / plp.imageSize.y;
float vh = 2 * std::tan(plp.camera.fovY * 0.5f);
float vw = plp.camera.aspect * vh;
float3 origin = plp.camera.position;
float3 direction = normalize(plp.camera.orientation * make_float3(vw * (0.5f - x), vh * (0.5f - y), 1));
float3 color;
MyPayloadSignature::trace(
plp.travHandle, origin, direction,
0.0f, FLT_MAX, 0.0f, 0xFF, OPTIX_RAY_FLAG_NONE,
RayType_Primary, NumRayTypes, RayType_Primary,
color);
plp.resultBuffer[launchIndex] = make_float4(color, 1.0f);
}
CUDA_DEVICE_KERNEL void RT_MS_NAME(miss)() {
float3 color = make_float3(0, 0, 0.1f);
MyPayloadSignature::set(&color);
}
CUDA_DEVICE_KERNEL void RT_CH_NAME(closesthit)() {
auto sbtr = HitGroupSBTRecordData::get();
MyPayloadSignature::set(&sbtr.matData.color);
}