이 페이지는 패스에 이름을 할당하기 위해 ShaderLab 코드에서 Name
블록을 사용하는 방법에 대한 정보를 포함합니다. 패스 정의에 대한 내용은 ShaderLab: 패스 정의를 참조하십시오. 셰이더 오브젝트의 작동 방식과 셰이더 오브젝트, 서브셰이더 및 패스 간 관계에 대해 알아보려면 셰이더 오브젝트 기초를 참조하십시오.
패스는 이름을 가질 수 있습니다. UsePass
및 일부 C# API에서 이름으로 패스를 참조해야 합니다. 패스 이름은 프레임 디버거 툴에서 확인할 수 있습니다.
기능 이름 | 빌트인 렌더 파이프라인 | 유니버설 렌더 파이프라인(URP) | 고해상도 렌더 파이프라인(HDRP) | 커스텀 SRP |
---|---|---|---|---|
ShaderLab: 이름 블록 | 지원 | 지원 | 지원 | 지원 |
ShaderLab에서 패스에 이름을 할당하려면 Pass
블록 안에 Name
블록을 넣으십시오.
서명 | 기능 |
---|---|
Name "<name>" |
패스의 이름을 설정합니다. |
Unity는 내부적으로 이름을 대문자로 변환합니다. ShaderLab 코드에서 이름을 참조할 때는 대문자 배리언트를 사용해야 합니다. 예를 들어, 값이 “example”이라면 EXAMPLE로 참조해야 합니다.
같은 서브셰이더에 이름이 동일한 패스가 두 개 이상 있는 경우, Unity는 코드의 첫 번째 패스를 사용합니다.
Material.FindPass, Material.GetPassName, ShaderData.Pass.Name과 같은 API를 사용하여 C# 스크립트에서 패스의 이름에 액세스할 수 있습니다.
참고: Material.GetShaderPassEnabled와 Material.SetShaderPassEnabled는 이름으로 패스를 참조하지 않으며, 대신 LightMode 태그의 값을 사용하여 패스를 참조합니다.
이 예제 코드는 ExampleNamedPass라는 패스를 포함하는 셰이더 오브젝트인 ContainsNamedPass를 생성합니다.
Shader "Examples/ContainsNamedPass"
{
SubShader
{
Pass
{
Name "ExampleNamedPass"
// The rest of the code that defines the Pass goes here.
}
}
}
다음 C# 코드를 사용하여 이 패스의 이름을 쿼리할 수 있습니다.
using UnityEngine;
public class GetPassName : MonoBehaviour
{
// Place this script on a GameObject with a MeshRenderer component
void Start() {
// Get the material
var material = GetComponent<MeshRenderer>().material;
// Get the name of the first Pass in the active SubShader
// of the Shader object assigned to the material
var passName = material.GetPassName(0);
// Print the name to the console
Debug.Log(passName);
}
}
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.