OverviewFilesCommitsIssuesDocsReleasesPeers

nvidia-rtx-godot commits / a170120

Provide dFdx/dFdy/fwidth stubs for RT hit shaders
Screen-space derivatives do not exist in ray tracing: a hit shader has no 2x2 pixel quad, so dFdx/dFdy/fwidth have no closest-hit overload and glslang rejects any shader that calls them: RT shader compile failed (hg2_v0_closest_hit): ERROR: 0:3411: 'dFdx' : no matching overloaded function found That fails the whole hit group, build_tlas skips every surface whose hit group is not ready, and the geometry ends up invisible while its collision -- being CPU-side -- still works. Both consumers hit it: dc_level.gdshader:117 and the dc-terrain shader each take dFdx/dFdy of the world position and project it through the face's projection axes to feed textureGrad. Macros rather than functions, because redefining a built-in with an existing signature is not legal GLSL and macros stay type-generic. LIMITATION, deliberately not hidden: the derivative is zero, so textureGrad selects LOD 0 and screen-footprint mip selection is lost under RT. Expect aliasing on minified detail -- the seam-glint behaviour dc_level's textureGrad was written for does not survive this. The correct replacement is ray differentials / ray cones, which need the hit triangle's attribute gradients and therefore cannot be expressed as a macro over an arbitrary expression; the position case (dFdx(world_pos)) is the tractable one to do first. Verified by compiling the real closest-hit stage offline with dc_level's exact textureGrad path (dump lines 3407-3415) substituted into the template. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
a1701201030971c7489514a1017bf20b19872a79
by plankatron <fleeky@gmail.com> · 2026-07-29T14:55:43.000Z

Changed files (1) +21 -0

servers/rendering/renderer_rd/shaders/raytracing/raytracing_custom_globals_inc.glsl +21 -0
……@@ -39,6 +39,27 @@ vec4 rt_frag_coord = vec4(0.0);
3939float alpha_antialiasing_edge = 0.0;
4040vec2 alpha_texture_coordinate = vec2(0.0);
4141
42// Screen-space derivatives do not exist in ray tracing: a hit shader has no 2x2
43// pixel quad, so dFdx/dFdy/fwidth have no closest-hit overload and glslang
44// rejects any shader calling them -- failing the whole hit group, which
45// build_tlas then skips, leaving the geometry invisible but still collidable.
46//
47// These are macros rather than functions because redefining a built-in with an
48// existing signature is not legal GLSL, and macros stay type-generic.
49//
50// LIMITATION: the derivative is zero, so textureGrad/textureQueryLod select
51// LOD 0 and screen-footprint mip selection is lost under RT (expect aliasing on
52// minified detail). Doing this properly needs ray differentials or ray cones,
53// which require the hit triangle's attribute gradients and so cannot be
54// expressed as a macro over an arbitrary expression.
55#define dFdx(m_v) ((m_v) * 0.0)
56#define dFdy(m_v) ((m_v) * 0.0)
57#define dFdxCoarse(m_v) ((m_v) * 0.0)
58#define dFdyCoarse(m_v) ((m_v) * 0.0)
59#define dFdxFine(m_v) ((m_v) * 0.0)
60#define dFdyFine(m_v) ((m_v) * 0.0)
61#define fwidth(m_v) ((m_v) * 0.0)
62
4263// Screen/depth textures are unavailable in RT -- alias to bindless slot 0
4364// so shaders that reference them still compile (reads return dummy values).
4465#define depth_buffer bindless_textures[0]