Shader学习笔记-HLSL
前言 上一篇介绍了ShaderLab的结构,这一篇继续介绍Shader的主要逻辑部分。 Unity的旧版本用的是CG语言,现在逐步淘汰了,主要用微软的HLSL,并加了一些Unity自己的语法。 预处理 include include and include_with_pragmas directives in HLSL - Unity 手册 在 HLSL 中,#include 指令是一种预处理器指令。它们指示编译器将一个 HLSL 文件的内容包含在另一个 HLSL 文件中。它们包含的文件称为包含文件。 #include_with_pragmas 指令的工作方式与常规 #include 指令相同,但它也允许您在包含文件中使用 #pragma 指令。这意味着 #include_with_pragmas 指令允许您在多个文件之间共享 #pragma 指令。 在 HLSL 中向着色器编译器提供信息 Provide information to the shader compiler in HLSL - Unity 手册 #pragma target 3.0 #pragma exclude_renderers vulkan #pragma vertex vert #pragma fragment frag // The rest of your HLSL code goes here 指定着色器阶段 语句 功能 #pragma vertex <name> Compile the function with the given name as the vertex shader. Replace with the function name. This directive is required in regular graphics shaders.将具有给定名称的函数编译为顶点着色器。 替换为函数名称。此指令在常规图形着色器中是必需的。 #pragma fragment <name> Compile the function with the given name as the fragment shader. Replace with the function name. This directive is required in regular graphics shaders.将具有给定名称的函数编译为片段着色器。 替换为函数名称。此指令在常规图形着色器中是必需的。 #pragma geometry <name> Compile the function with the given name as the geometry shader. Replace with the function name. This option automatically turns on #pragma require geometry; for more information, see Targeting shader models and GPU features in HLSL.将具有给定名称的函数编译为几何着色器。 替换为函数名称。此选项会自动打开 #pragma 需要几何图形;有关详细信息,请参阅在 HLSL 中面向着色器模型和 GPU 功能。Note: Metal does not support geometry shaders.注意:Metal 不支持几何体着色器。 #pragma hull <name> Compile the function with the given name as the DirectX 11 hull shader. Replace with the function name. This automatically adds #pragma require tessellation; for more information, see Targeting shader models and GPU features in HLSL.将具有给定名称的函数编译为 DirectX 11 hull 着色器。 替换为函数名称。这会自动添加 #pragma 需要曲面细分;有关详细信息,请参阅在 HLSL 中面向着色器模型和 GPU 功能。 #pragma domain <name> Compile the function with the given name as the DirectX 11 domain shader. Replace with the function name. This option automatically turns on #pragma require tessellation; for more information, see Targeting shader models and GPU features in HLSL.将具有给定名称的函数编译为 DirectX 11 域着色器。 替换为函数名称。此选项会自动打开 #pragma 需要镶嵌;有关详细信息,请参阅在 HLSL 中面向着色器模型和 GPU 功能。 着色器变体和关键字 ...