HLSL 与 GLSL,在编写 Unity 着色器时
HLSL vs GLSL, in writing Unity shaders
由于支持平台,对要使用的着色语言(HLSL 或 GLSL)感到困惑。
HLSL 资源很多,但我通过网络看到它是特定于 DirectX (windows) 的。如果我打算 运行 我的申请 android 会有问题吗?
-我不能完全依赖ShaderGraph-
谢谢
您可以在 Android 平台上的 Unity 中使用 HLSL。来自 the documentation:
HLSL syntax
The HLSL language itself has two syntaxes: a “legacy” DX9-style syntax, and a more modern DX10+ style syntax.
The difference is mostly in how texture sampling functions work:
- The legacy syntax uses sampler2D, tex2D() and similar functions. This syntax works on all platforms.
- The DX10+ syntax uses Texture2D, SamplerState and .Sample() functions. Some forms of this syntax do not work on OpenGL platforms, due to how textures and samplers are not different objects in OpenGL.
In Unity, you can avoid problems with HLSL syntax platform support by using predefined macros to declare and sample textures. Unity expands these macros to the most appropriate syntax, depending on the platform that the shader is being compiled for.
Shader compilers
Different platforms use different shader compilers for shader program compilation as follows:
- Windows and Microsoft platforms (DX11, DX12 and Xbox One) all use Microsoft’s HLSL compiler (currently FXC / D3DCompiler_47).
- OpenGL (Core & ES), Metal and Vulkan use Microsoft’s HLSL followed by bytecode translation into GLSL, Metal or SPIR-V, using HLSLcc.
- Other console platforms use their respective compilers (e.g. PSSL on PS4).
- Surface Shaders use HLSL and MojoShader for code generation analysis step.
由于支持平台,对要使用的着色语言(HLSL 或 GLSL)感到困惑。 HLSL 资源很多,但我通过网络看到它是特定于 DirectX (windows) 的。如果我打算 运行 我的申请 android 会有问题吗? -我不能完全依赖ShaderGraph-
谢谢
您可以在 Android 平台上的 Unity 中使用 HLSL。来自 the documentation:
HLSL syntax
The HLSL language itself has two syntaxes: a “legacy” DX9-style syntax, and a more modern DX10+ style syntax.
The difference is mostly in how texture sampling functions work:
- The legacy syntax uses sampler2D, tex2D() and similar functions. This syntax works on all platforms.
- The DX10+ syntax uses Texture2D, SamplerState and .Sample() functions. Some forms of this syntax do not work on OpenGL platforms, due to how textures and samplers are not different objects in OpenGL. In Unity, you can avoid problems with HLSL syntax platform support by using predefined macros to declare and sample textures. Unity expands these macros to the most appropriate syntax, depending on the platform that the shader is being compiled for.
Shader compilers
Different platforms use different shader compilers for shader program compilation as follows:
- Windows and Microsoft platforms (DX11, DX12 and Xbox One) all use Microsoft’s HLSL compiler (currently FXC / D3DCompiler_47).
- OpenGL (Core & ES), Metal and Vulkan use Microsoft’s HLSL followed by bytecode translation into GLSL, Metal or SPIR-V, using HLSLcc.
- Other console platforms use their respective compilers (e.g. PSSL on PS4).
- Surface Shaders use HLSL and MojoShader for code generation analysis step.