<p>As I understand <a href="https://github.com/KhronosGroup/GLSL/blob/master/extensions/ext/GLSL_EXT_ray_tracing.txt" rel="nofollow noreferrer">GLSL_EXT_ray_tracing.txt</a>, <code>gl_RayTmaxEXT</code> contains the <strong>current t</strong> in intersection shaders, due to the following pieces of information given in <a href="https://github.com/KhronosGroup/GLSL/blob/master/extensions/ext/GLSL_EXT_ray_tracing.txt" rel="nofollow noreferrer">GLSL_EXT_ray_tracing.txt</a>:</p>
<pre><code> In the intersection language, built-in variables are declared as follows

    ...

    // Ray parameters
    in          float  gl_RayTminEXT;
    in volatile float  gl_RayTmaxEXT;
    in          uint   gl_IncomingRayFlagsEXT;

    ...
</code></pre>
<p>=&gt; due to the <code>volatile</code> declaration of <code>gl_RayTmaxEXT</code>.</p>
<p>Also the description of <code>bool reportIntersectionEXT(float hitT, uint hitKind);</code> remarks that <code>gl_RayTmaxEXT</code> is not constant:</p>
<blockquote>
<p>If the intersection is not ignored in the
any-hit shader, &lt;hitT&gt; is committed as the new gl_RayTmaxEXT value of the
current ray,  is committed as the new value for gl_HitKindEXT, and
true is returned.</p>
</blockquote>

CC BY-SA 4.0
2023-02-09T22:16:53.573Z
2023-02-09T22:16:53.573Z
j00hi
<p>According to this <a href="https://github.com/KhronosGroup/GLSL/blob/master/extensions/ext/GLSL_EXT_ray_tracing.txt" rel="nofollow noreferrer">document</a>, one should be able to extract those values through
<em>gl_RayTminEXT</em> and <em>gl_RayTmaxEXT</em> <strong>GLSL</strong> built-ins for intersection shader.</p>
<p>Further comments are welcome.</p>

CC BY-SA 4.0
2023-01-22T10:27:12.310Z
2023-01-22T10:27:12.310Z
Vectorizer
<p>I am working on the port of a demo from DXR to Vulkan Ray Tracing extension using GLSL.
In DXR/HLSL space, there are <em>RayTMin()</em> and R<em>ayTCurrent()</em> functions to retrieve the starting and the current end point of the ray  (<em>Origin + (Direction * RayTMin)</em> and  <em>Origin + (Direction * RayTCurrent)</em>, respectively).
In Vulkan RT/GLSL space, one specifies the <strong>tMin</strong> and <strong>tMax</strong> values in the  <em>traceRayEXT(...)</em> call, but how does one retrieve the &quot;<strong>current t</strong>&quot; and &quot;<strong>t min</strong>&quot; values in an intersection shader?</p>

<raytracing><glsl><vulkan><hlsl><raymarching>
Porting from DXR/HLSL to Vulkan Ray Tracing Extension/GLSL
Vectorizer
# Porting from DXR/HLSL to Vulkan Ray Tracing Extension/GLSL

(Asked by: username_0 on 2023-01-22)

I am working on the port of a demo from DXR to Vulkan Ray Tracing extension using GLSL.
In DXR/HLSL space, there are *RayTMin()* and R*ayTCurrent()* functions to retrieve the starting and the current end point of the ray (*Origin + (Direction \* RayTMin)* and *Origin + (Direction \* RayTCurrent)*, respectively).
In Vulkan RT/GLSL space, one specifies the **tMin** and **tMax** values in the *traceRayEXT(...)* call, but how does one retrieve the "**current t**" and "**t min**" values in an intersection shader?

**Tags:** raytracing, glsl, vulkan, hlsl, raymarching


---

## 2 answers

### Answer by username_1 on 2023-02-09. Score: 1

As I understand [GLSL\_EXT\_ray\_tracing.txt](https://github.com/KhronosGroup/GLSL/blob/master/extensions/ext/GLSL_EXT_ray_tracing.txt), `gl_RayTmaxEXT` contains the **current t** in intersection shaders, due to the following pieces of information given in [GLSL\_EXT\_ray\_tracing.txt](https://github.com/KhronosGroup/GLSL/blob/master/extensions/ext/GLSL_EXT_ray_tracing.txt):

```
 In the intersection language, built-in variables are declared as follows

    ...

    // Ray parameters
    in          float  gl_RayTminEXT;
    in volatile float  gl_RayTmaxEXT;
    in          uint   gl_IncomingRayFlagsEXT;

    ...

```

=> due to the `volatile` declaration of `gl_RayTmaxEXT`.

Also the description of `bool reportIntersectionEXT(float hitT, uint hitKind);` remarks that `gl_RayTmaxEXT` is not constant:

> If the intersection is not ignored in the
> any-hit shader, <hitT> is committed as the new gl\_RayTmaxEXT value of the
> current ray, is committed as the new value for gl\_HitKindEXT, and
> true is returned.


---

### Answer by username_0 on 2023-01-22. Score: 1

According to this [document](https://github.com/KhronosGroup/GLSL/blob/master/extensions/ext/GLSL_EXT_ray_tracing.txt), one should be able to extract those values through
*gl\_RayTminEXT* and *gl\_RayTmaxEXT* **GLSL** built-ins for intersection shader.

Further comments are welcome.


---

