Unity에서는 HLSL 프로그래밍 언어를 사용하여 셰이더 프로그램을 작성합니다.
Unity는 원래 Cg 언어를 사용했고, 그에 따라 Unity의 일부 셰이더 키워드(CGPROGRAM
)와 파일 확장자(.cginc
) 이름을 사용했습니다. Unity는 Cg를 더 이상 사용하지 않지만, 이러한 키워드와 파일 확장자는 계속 지원됩니다. 모든 셰이더 프로그램 코드는 Cg 관련 키워드와 파일 확장자를 사용하더라도 유효한 HLSL이어야 합니다.
HLSLPROGRAM
사용과 CGPROGRAM
사용 간의 유일한 차이점은 Unity가 셰이더 프로그램을 컴파일할 때 자동으로 포함하는 파일에 있습니다. 이는 이전 버전과의 호환성을 위한 것입니다. 자세한 내용은 빌트인 셰이더 포함 파일을 참조하십시오.
HLSL 언어 자체에는 두 개의 구문, 즉 “레거시” DX9 스타일 구문과 좀더 현대적인 DX10+ 스타일 구문이 있습니다.
차이점은 주로 텍스처 샘플링 함수가 작동하는 방식에 있습니다.
sampler2D
, tex2D()
및 유사 함수를 사용합니다. 이 구문은 모든 플랫폼에서 작동합니다.Texture2D
, SamplerState
및 .Sample()
함수를 사용합니다. 이 구문의 일부 형식은 OpenGL 플랫폼에서 작동하지 않습니다. 이는 텍스처와 샘플러가 OpenGL에서 서로 다른 오브젝트가 아니기 때문입니다.Unity에서는 사전 정의된 매크로를 사용하여 텍스처를 선언하고 샘플링함으로써 HLSL 구문 플랫폼 지원 문제를 방지할 수 있습니다. Unity는 셰이더가 컴파일되는 플랫폼에 따라 이러한 매크로를 가장 적합한 구문으로 확장합니다.
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.