Cg/HLSL 버텍스 프로그램에서
메시 버텍스 데이터는 버텍스 셰이더 함수에 입력으로
전달됩니다. 각 입력에는 입력에 대해 지정된 시맨틱이 있어야 합니다. 예를 들어, POSITION
입력은 버텍스 포지션이고 NORMAL
은 버텍스 노멀입니다.
버텍스 데이터 입력이 하나씩 나열되는 것이 아니라 구조체로 선언되어 있는 경우도 있습니다. 자주 사용되는 일반적인 버텍스 구조는 UnityCG.cginc 포함 파일 내에 정의되어 있으며 대부분의 경우에 이 구조만 사용해도 충분합니다. 다음과 같은 구조가 정의되어 있습니다:
appdata_base
: 포지션, 노멀, 하나의 텍스처 좌표appdata_tan
: 포지션, 탄젠트, 노멀, 하나의 텍스처 좌표appdata_full
: 포지션, 탄젠트, 노멀, 네 개의 텍스처 좌표, 컬러예제: 셰이더는 메시의 노멀에 기반하여 메시에 컬러를 칠하며, 버텍스 프로그램 입력으로 appdata_base
를 사용합니다.
Shader "VertexInputSimple" {
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
fixed4 color : COLOR;
};
v2f vert (appdata_base v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.color.xyz = v.normal * 0.5 + 0.5;
o.color.w = 1.0;
return o;
}
fixed4 frag (v2f i) : SV_Target { return i.color; }
ENDCG
}
}
}
다른 버텍스 데이터에 접근하려면 버텍스 구조를 직접 선언하거나 버텍스 셰이더에 입력 파라미터를 추가해야 합니다. 버텍스 데이터는 Cg/HLSL 시맨틱에 의해 식별되며 다음 리스트에 속해야 합니다.
POSITION
는 버텍스 포지션이며 보통 float3
또 float4
입니다.NORMAL
은 버텍스 노멀이며 보통 float3
입니다.TEXCOORD0
는 첫 번째 UV 좌표이며 보통 float2
, float3
또 float4
입니다.TEXCOORD1
, TEXCOORD2
및 TEXCOORD3
은 각각 두 번째, 세 번째 및 네 번째 UV 좌표입니다.TANGENT
는 탄젠트 벡터(노멀 매핑에 사용됨)이며 보통 float4
입니다.COLOR
는 버텍스당 컬러이며 보통 float4
입니다.버텍스 셰이더 입력에서 요구되는 것보다 더 적은 컴포넌트만 메시 데이터에 포함되어
있을 경우 나머지는 모두 0으로 채워집니다(디폴트가 1인 .w
컴포넌트 제외). 예를 들어, 메시 텍스처 좌표는 대부분의 경우
x와 y 컴포넌트만 있는 2D 벡터입니다. 버텍스 셰이더가
TEXCOORD0
시맨틱이 붙은 float4
입력을 선언하면 버텍스 셰이더가
받게 되는 값은 (x,y,0,1)을 포함합니다.
이러한 기법을 사용하여 빌트인 렌더 파이프라인에서 버텍스 데이터를 시각화하는 방법의 예는 버텍스 데이터 시각화를 참조하십시오.
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.