2016년 6월 30일 목요일

Unity Shader vert and frag



vertex structures : 버텍스 하나에 담긴 정보를 나열한 스트럭트

기호에 맞게 정의하여 사용, 또는 UnityCG.cginc 을 include 하여
아래의 미리 정의된 형태 사용

appdata_base:    position,             normal, 1 texture coordinate.
appdata_tan:      position, tangent, normal, 1 texture coordinate.
appdata_full:      position, tangent, normal, 4 texture coordinates, color.



스스로 정의하여 사용한다면...

POSITION (vertex position) :               typically float3 or float4
NORMAL (vertex normal):                  typically a float3
TEXCOORD0 (first UV coordinate) :      typically float2, float3 or float4.
TEXCOORD1, TEXCOORD2 and TEXCOORD3 are the 2nd, 3rd and 4th UV coordinates
TANGENT (used for normal mapping) : typically a float4.
COLOR (per-vertex color) :                 typically a float4.

이런 식으로 커스텀 버텍스 스트럭트를 정의 한다.(필요 없는건 뺀다)
struct appdata
{
    float4 vertex : POSITION;
    float4 texcoord : TEXCOORD0;
    fixed4 color : COLOR;
    float3 normal : NORMAL;
    float4 tangent : TANGENT;
};

참고 :
calculate bitangent ->
float3 bitangent = cross( v.normal, v.tangent.xyz ) * v.tangent.w;
두 백터에 수직인 벡터는 방향이 정 반대인 벡터 두개가 나오는데 * v.tangent.w 가
둘중 하나를 고르는 역할을 하는 듯 하다. w의 의미를 알아내야 한다.











=======================================================

댓글 없음:

댓글 쓰기