• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#version 460
2#extension GL_EXT_ray_query : enable
3#extension GL_EXT_ray_flags_primitive_culling : enable
4
5layout(primitive_culling);
6struct Ray
7{
8    vec3 pos;
9    float tmin;
10    vec3 dir;
11    float tmax;
12};
13
14layout(std430, set = 0, binding = 0) buffer Log
15{
16    uint x;
17    uint y;
18};
19
20layout(binding = 1, set = 0) uniform accelerationStructureEXT rtas;
21layout(std430, set = 0, binding = 2) buffer Rays { Ray rays[]; };
22
23void doSomething()
24{
25    x = 0;
26    y = 0;
27}
28
29Ray makeRayDesc()
30{
31    Ray ray;
32    ray.pos= vec3(0,0,0);
33    ray.dir = vec3(1,0,0);
34    ray.tmin = 0.0f;
35    ray.tmax = 9999.0;
36    return ray;
37}
38
39void main()
40{
41    Ray ray = makeRayDesc();
42    rayQueryEXT rayQuery;
43    rayQueryInitializeEXT(rayQuery, rtas, gl_RayFlagsNoneEXT, 0xFF, ray.pos, ray.tmin, ray.dir, ray.tmax);
44
45    mat4x3 _mat4x3;
46    mat3x4 _mat3x4;
47
48    while (rayQueryProceedEXT(rayQuery))
49    {
50        uint candidateType = rayQueryGetIntersectionTypeEXT(rayQuery, false);
51        switch(candidateType)
52        {
53            case gl_RayQueryCandidateIntersectionTriangleEXT:
54
55                rayQueryTerminateEXT(rayQuery);
56                _mat4x3 = rayQueryGetIntersectionObjectToWorldEXT(rayQuery, false);
57                _mat3x4 = transpose(_mat4x3);
58                rayQueryConfirmIntersectionEXT(rayQuery);
59
60                if (rayQueryGetIntersectionFrontFaceEXT(rayQuery, true))
61                {
62                    doSomething();
63                }
64
65                if (rayQueryGetIntersectionBarycentricsEXT(rayQuery, true).x == 0)
66                {
67                    doSomething();
68                }
69
70                if (rayQueryGetIntersectionInstanceCustomIndexEXT(rayQuery, true) > 0)
71                {
72                    doSomething();
73                }
74
75                if (rayQueryGetIntersectionInstanceIdEXT(rayQuery, true) > 0)
76                {
77                    doSomething();
78                }
79
80                if (rayQueryGetIntersectionObjectRayDirectionEXT(rayQuery, true).x > 0)
81                {
82                    doSomething();
83                }
84
85                if (rayQueryGetIntersectionObjectRayOriginEXT(rayQuery, true).x > 0)
86                {
87                    doSomething();
88                }
89
90                if (rayQueryGetIntersectionPrimitiveIndexEXT(rayQuery, true) > 0)
91                {
92                    doSomething();
93                }
94
95                if (rayQueryGetIntersectionTEXT(rayQuery, true) > 0.f)
96                {
97                    doSomething();
98                }
99
100                if (rayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetEXT(rayQuery, true) > 0)
101                {
102                    doSomething();
103                }
104                break;
105
106            case gl_RayQueryCandidateIntersectionAABBEXT:
107            {
108                _mat4x3 = rayQueryGetIntersectionObjectToWorldEXT(rayQuery, false);
109                _mat3x4 = transpose(_mat4x3);
110                if (rayQueryGetIntersectionCandidateAABBOpaqueEXT(rayQuery))
111                {
112                    doSomething();
113                }
114
115                float t = 0.5;
116                rayQueryGenerateIntersectionEXT(rayQuery, t);
117                rayQueryTerminateEXT(rayQuery);
118                break;
119            }
120        }
121    }
122
123    if(_mat3x4[0][0] == _mat4x3[0][0])
124    {
125        doSomething();
126    }
127
128    uint committedStatus = rayQueryGetIntersectionTypeEXT(rayQuery, true);
129
130    switch(committedStatus)
131    {
132        case gl_RayQueryCommittedIntersectionNoneEXT :
133            _mat4x3 = rayQueryGetIntersectionWorldToObjectEXT(rayQuery, false);
134            _mat3x4 = transpose(_mat4x3);
135            break;
136
137        case gl_RayQueryCommittedIntersectionTriangleEXT :
138            _mat4x3 = rayQueryGetIntersectionWorldToObjectEXT(rayQuery, true);
139            _mat3x4 = transpose(_mat4x3);
140
141            if (rayQueryGetIntersectionFrontFaceEXT(rayQuery, true))
142            {
143                doSomething();
144            }
145
146            if (rayQueryGetIntersectionBarycentricsEXT(rayQuery, true).y == 0)
147            {
148                doSomething();
149            }
150            break;
151
152        case gl_RayQueryCommittedIntersectionGeneratedEXT :
153
154            if(rayQueryGetIntersectionGeometryIndexEXT(rayQuery, true) > 0)
155            {
156                doSomething();
157            }
158
159            if(rayQueryGetIntersectionInstanceIdEXT(rayQuery, true) > 0)
160            {
161                doSomething();
162            }
163
164            if(rayQueryGetIntersectionInstanceCustomIndexEXT(rayQuery, true) > 0)
165            {
166                doSomething();
167            }
168
169            if(rayQueryGetIntersectionObjectRayDirectionEXT(rayQuery, true).z > 0)
170            {
171                doSomething();
172            }
173
174            if(rayQueryGetIntersectionObjectRayOriginEXT(rayQuery, true).x > 0)
175            {
176                doSomething();
177            }
178
179            if(rayQueryGetIntersectionPrimitiveIndexEXT(rayQuery, true) > 0)
180            {
181                doSomething();
182            }
183
184            if(rayQueryGetIntersectionTEXT(rayQuery, true) > 0.f)
185            {
186                doSomething();
187            }
188            break;
189    }
190
191    if (_mat3x4[0][0] == _mat4x3[0][0])
192    {
193        doSomething();
194    }
195
196    if (rayQueryGetRayFlagsEXT(rayQuery) > gl_RayFlagsSkipTrianglesEXT)
197    {
198        doSomething();
199    }
200
201    if (rayQueryGetRayTMinEXT(rayQuery) > 0.0)
202    {
203        doSomething();
204    }
205
206    vec3 o = rayQueryGetWorldRayOriginEXT(rayQuery);
207    vec3 d = rayQueryGetWorldRayDirectionEXT(rayQuery);
208
209    if (o.x == d.z)
210    {
211        doSomething();
212    }
213}
214