在 Unity 中,着色器程序是用 HLSL 语言的一个变种(也称为 Cg,但对于大部分实际使用情况,这两种语言没有区别)编写的。
目前,为了在不同平台之间实现最大程度的可移植性,请使用 DX9 风格的 HLSL 编写程序(例如,使用 DX9 风格的 sampler2D
和 tex2D
进行纹理采样,而不是使用 DX10 风格的 Texture2D
、SamplerState
和 tex.Sample
)。
在内部将使用不同的着色器编译器来编译着色器程序:
#pragma prefer_hlsl2glsl gles
实现的如果确实需要确定正在使用哪个编译器(为了使用仅一种编译器支持的 HLSL 语法,或解决编译器错误),可以使用预定义的着色器宏。例如,使用 HLSL 编译器进行编译时设置 UNITY_COMPILER_HLSL
(针对 D3D 或 GLCore/GLES3/GLES 平台);通过 hlsl2glsl 进行编译时设置 UNITY_COMPILER_HLSL2GLSL
。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.