-
Notifications
You must be signed in to change notification settings - Fork 861
/
Copy pathrayQuery-allOps.comp
222 lines (183 loc) · 5.8 KB
/
rayQuery-allOps.comp
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#version 460
#extension GL_EXT_ray_query : enable
#extension GL_EXT_ray_flags_primitive_culling : enable
#extension GL_EXT_ray_tracing_position_fetch : enable
layout(primitive_culling);
struct Ray
{
vec3 pos;
float tmin;
vec3 dir;
float tmax;
};
layout(std430, set = 0, binding = 0) buffer Log
{
uint x;
uint y;
};
layout(binding = 1, set = 0) uniform accelerationStructureEXT rtas;
layout(std430, set = 0, binding = 2) buffer Rays { Ray rays[]; };
void doSomething()
{
x = 0;
y = 0;
}
Ray makeRayDesc()
{
Ray ray;
ray.pos= vec3(0,0,0);
ray.dir = vec3(1,0,0);
ray.tmin = 0.0f;
ray.tmax = 9999.0;
return ray;
}
void main()
{
Ray ray = makeRayDesc();
rayQueryEXT rayQuery;
rayQueryInitializeEXT(rayQuery, rtas, gl_RayFlagsNoneEXT, 0xFF, ray.pos, ray.tmin, ray.dir, ray.tmax);
mat4x3 _mat4x3;
mat3x4 _mat3x4;
while (rayQueryProceedEXT(rayQuery))
{
uint candidateType = rayQueryGetIntersectionTypeEXT(rayQuery, false);
switch(candidateType)
{
case gl_RayQueryCandidateIntersectionTriangleEXT:
rayQueryTerminateEXT(rayQuery);
_mat4x3 = rayQueryGetIntersectionObjectToWorldEXT(rayQuery, false);
_mat3x4 = transpose(_mat4x3);
rayQueryConfirmIntersectionEXT(rayQuery);
if (rayQueryGetIntersectionFrontFaceEXT(rayQuery, true))
{
doSomething();
}
if (rayQueryGetIntersectionBarycentricsEXT(rayQuery, true).x == 0)
{
doSomething();
}
if (rayQueryGetIntersectionInstanceCustomIndexEXT(rayQuery, true) > 0)
{
doSomething();
}
if (rayQueryGetIntersectionInstanceIdEXT(rayQuery, true) > 0)
{
doSomething();
}
if (rayQueryGetIntersectionObjectRayDirectionEXT(rayQuery, true).x > 0)
{
doSomething();
}
if (rayQueryGetIntersectionObjectRayOriginEXT(rayQuery, true).x > 0)
{
doSomething();
}
if (rayQueryGetIntersectionPrimitiveIndexEXT(rayQuery, true) > 0)
{
doSomething();
}
if (rayQueryGetIntersectionTEXT(rayQuery, true) > 0.f)
{
doSomething();
}
if (rayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetEXT(rayQuery, true) > 0)
{
doSomething();
}
break;
case gl_RayQueryCandidateIntersectionAABBEXT:
{
_mat4x3 = rayQueryGetIntersectionObjectToWorldEXT(rayQuery, false);
_mat3x4 = transpose(_mat4x3);
if (rayQueryGetIntersectionCandidateAABBOpaqueEXT(rayQuery))
{
doSomething();
}
float t = 0.5;
rayQueryGenerateIntersectionEXT(rayQuery, t);
rayQueryTerminateEXT(rayQuery);
break;
}
}
}
if(_mat3x4[0][0] == _mat4x3[0][0])
{
doSomething();
}
uint committedStatus = rayQueryGetIntersectionTypeEXT(rayQuery, true);
switch(committedStatus)
{
case gl_RayQueryCommittedIntersectionNoneEXT :
_mat4x3 = rayQueryGetIntersectionWorldToObjectEXT(rayQuery, false);
_mat3x4 = transpose(_mat4x3);
break;
case gl_RayQueryCommittedIntersectionTriangleEXT :
_mat4x3 = rayQueryGetIntersectionWorldToObjectEXT(rayQuery, true);
_mat3x4 = transpose(_mat4x3);
if (rayQueryGetIntersectionFrontFaceEXT(rayQuery, true))
{
doSomething();
}
if (rayQueryGetIntersectionBarycentricsEXT(rayQuery, true).y == 0)
{
doSomething();
}
{
vec3 positions[3];
rayQueryGetIntersectionTriangleVertexPositionsEXT(rayQuery, true, positions);
if (positions[0].x < 0 && positions[2].y > 0)
{
doSomething();
}
}
break;
case gl_RayQueryCommittedIntersectionGeneratedEXT :
if(rayQueryGetIntersectionGeometryIndexEXT(rayQuery, true) > 0)
{
doSomething();
}
if(rayQueryGetIntersectionInstanceIdEXT(rayQuery, true) > 0)
{
doSomething();
}
if(rayQueryGetIntersectionInstanceCustomIndexEXT(rayQuery, true) > 0)
{
doSomething();
}
if(rayQueryGetIntersectionObjectRayDirectionEXT(rayQuery, true).z > 0)
{
doSomething();
}
if(rayQueryGetIntersectionObjectRayOriginEXT(rayQuery, true).x > 0)
{
doSomething();
}
if(rayQueryGetIntersectionPrimitiveIndexEXT(rayQuery, true) > 0)
{
doSomething();
}
if(rayQueryGetIntersectionTEXT(rayQuery, true) > 0.f)
{
doSomething();
}
break;
}
if (_mat3x4[0][0] == _mat4x3[0][0])
{
doSomething();
}
if (rayQueryGetRayFlagsEXT(rayQuery) > gl_RayFlagsSkipTrianglesEXT)
{
doSomething();
}
if (rayQueryGetRayTMinEXT(rayQuery) > 0.0)
{
doSomething();
}
vec3 o = rayQueryGetWorldRayOriginEXT(rayQuery);
vec3 d = rayQueryGetWorldRayDirectionEXT(rayQuery);
if (o.x == d.z)
{
doSomething();
}
}