때로는 동일한 셰이더가 다양한 상황에서 서로 다른 작업을 수행하기를 원할 수 있습니다. 예를 들어 다양한 머티리얼에 대해 다르게 설정하거나 다양한 하드웨어에 대한 기능을 정의하거나 런타임 시 셰이더의 동작을 동적으로 변경할 수 있습니다. 텍스처 읽기, 버텍스 입력, 인터폴레이터, 루프와 같이 필요하지 않음에도 계산 소모를 많이 하는 코드를 실행하지 않으려고 할 수도 있습니다.
조건부를 사용하여 GPU가 특정 조건에서만 실행하는 동작을 정의할 수 있습니다.
** 다양한 조건부 유형
셰이더에서 조건부를 사용하려면 다음 접근 방식을 사용할 수 있습니다.
셰이더의 조건부에는 "범용" 접근 방식이 없으며 주어진 프로젝트에서 주어진 셰이더에 대한 각 접근 방식의 장점과 단점을 고려해야 합니다.
다음의 내용을 유념해야 합니다.
일반적으로 가장 좋은 방법은 애플리케이션의 성능을 프로파일링하고 사례별로 신중하게 결정하는 것입니다. 예를 들어 GPU 사용량을 약간 증가시킬 수 있다면 동적 브랜치를 사용하여 “충분히 좋은” GPU 성능을 달성하고 더 많은 배리언트를 도입할 위험을 줄이는 것이 가장 좋을 수 있습니다. 그러나 GPU 성능이 해당 셰이더의 주요 관심사이고 추가 배리언트 사용량을 이미 계산했다면 배리언트 사용을 선택할 수 있습니다.
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.