OverviewFilesCommitsIssuesDocsReleasesPeers

nvidia-rtx-godot commits / 6cc389c

Register the RT-only shader built-ins with ShaderLanguage
PRIMARY_HIT, BOUNCE_INDEX and RAY_FOOTPRINT_X/Y were added to SceneShaderRaytracing's actions.renames but never declared in ShaderTypes. Those are two different mechanisms: renames translate a built-in during CODE GENERATION, while ShaderLanguage validates identifiers against this table long before codegen runs. Any shader referencing them failed to parse -- SHADER ERROR: Unknown identifier in expression: 'RAY_FOOTPRINT_X' WARNING: RT: Failed to preprocess custom shader; falling back to default material -- so dc_level and dc_terrain both silently dropped to the default material and lost all their texturing under path tracing. Declared on the shared spatial fragment table, which means the rasterizer parses them too. It has no renames for them, so uses must stay inside #ifdef RT -- which both consumers do, and where the rasterizer never sees them at all. Note for future changes of this kind: a headless --import cannot catch this. It compiles the RASTER variant, where #ifdef RT strips the block, so the error only appears when the RT variant is built at runtime. Verifying shader built-ins needs an actual path-traced frame. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
6cc389c5a97a303fa05833ba249d4ea5e28f7b95
by plankatron <fleeky@gmail.com> · 2026-07-29T22:24:02.000Z

Changed files (1) +13 -0

servers/rendering/shader_types.cpp +13 -0
……@@ -143,6 +143,19 @@ ShaderTypes::ShaderTypes() {
143143 shader_modes[RSE::SHADER_SPATIAL].functions["fragment"].built_ins["TANGENT"] = ShaderLanguage::TYPE_VEC3;
144144 shader_modes[RSE::SHADER_SPATIAL].functions["fragment"].built_ins["BINORMAL"] = ShaderLanguage::TYPE_VEC3;
145145 shader_modes[RSE::SHADER_SPATIAL].functions["fragment"].built_ins["VIEW"] = constt(ShaderLanguage::TYPE_VEC3);
146 // Ray-tracing-only built-ins. They must be declared HERE as well as renamed in
147 // SceneShaderRaytracing: renames only translate a name during code generation,
148 // while ShaderLanguage rejects any identifier missing from this table before
149 // codegen is ever reached ("Unknown identifier in expression").
150 //
151 // Declared on the shared spatial table, so the rasterizer will also PARSE them
152 // -- but it has no rename for them, so a shader must keep its uses inside
153 // #ifdef RT or raster codegen emits an undefined name. Under #ifdef RT the
154 // rasterizer never sees them at all.
155 shader_modes[RSE::SHADER_SPATIAL].functions["fragment"].built_ins["PRIMARY_HIT"] = constt(ShaderLanguage::TYPE_BOOL);
156 shader_modes[RSE::SHADER_SPATIAL].functions["fragment"].built_ins["BOUNCE_INDEX"] = constt(ShaderLanguage::TYPE_UINT);
157 shader_modes[RSE::SHADER_SPATIAL].functions["fragment"].built_ins["RAY_FOOTPRINT_X"] = constt(ShaderLanguage::TYPE_VEC3);
158 shader_modes[RSE::SHADER_SPATIAL].functions["fragment"].built_ins["RAY_FOOTPRINT_Y"] = constt(ShaderLanguage::TYPE_VEC3);
146159 shader_modes[RSE::SHADER_SPATIAL].functions["fragment"].built_ins["NORMAL_MAP"] = ShaderLanguage::TYPE_VEC3;
147160 shader_modes[RSE::SHADER_SPATIAL].functions["fragment"].built_ins["NORMAL_MAP_DEPTH"] = ShaderLanguage::TYPE_FLOAT;
148161 shader_modes[RSE::SHADER_SPATIAL].functions["fragment"].built_ins["BENT_NORMAL_MAP"] = ShaderLanguage::TYPE_VEC3;