Unity3D:在 HLSL 中包含和include_with_pragmas指令
推荐:将NSDT场景编辑器加入你的3D工具链
3D工具集:NSDT简石数字孪生
在 HLSL 中包含和include_with_pragmas指令
在 HLSL 中,指令是一种预处理器指令。它们指示编译器将一个 HLSL 文件的内容包含在另一个 HLSL 文件中。它们包含的文件称为包含文件。#include
在 Unity 中,常规指令的工作方式与标准 HLSL 中相同。有关常规指令的详细信息,请参阅 HLSL 文档:包含指令。#include#include
Unity 还提供了特定于 Unity 的附加指令。该指令的工作方式与常规指令相同,但它也允许您在包含文件中使用指令。这意味着该指令允许您在多个文件之间共享指令。#include_with_pragmas#include_with_pragmas#include#pragma#include_with_pragmas#pragma
使用 include_with_pragmas 指令
注意:若要使用指令,必须启用缓存着色器预处理器。#include_with_pragmas
此示例演示如何使用特定于 Unity 的指令来实现常见的工作流程改进:能够为多个着色器打开和关闭着色器调试,而无需每次都编辑每个着色器源文件。#include_with_pragmas
以下行演示了包含文件的内容。它包含一个支持着色器调试的杂注指令:
// Comment out the following line to disable shader debugging
#pragma enable_d3d11_debug_symbols
在要调试的每个着色器中,添加一个指向包含文件的指令。将指令放在其他指令附近,如下所示:#include_with_pragmas#pragma
// Example pragma directives
#pragma target 4.0
#pragma vertex vert
#pragma fragment frag
// Replace path-to-include-file with the path to the include file
#include_with_pragmas "path-to-include-file"
// The rest of the HLSL code goes here
现在,当您想要为所有使用包含文件的着色器打开和关闭着色器调试时,只需更改包含文件中的一行。当 Unity 重新编译着色器时,它会包含修改后的行
由3D建模学习工作室整理翻译,转载请注明出处!