본문 바로가기

Material, BluePrint/Material

UNITY - Matcap

Matcap

Shader "Custom/Matcap" 
{
  Properties
  {
 	 _MainTex ("Base (RGB)", 2D) = "white" {}
 	 _Matcap  ("Matcap(RGB)", 2D) = "white"{}
 	 _mStrong ("MatStrong", Range(0,2) ) = 1.0
  }
  SubShader
  {
  	Tags { "RenderType"="Opaque" }

    pass

    {
    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag
    #include "UnityCG.cginc"

    sampler2D _MainTex;
    sampler2D _Matcap;

    //타일링, 오프셋 조절을 위해서 쓰임.
    uniform fixed4 _MainTex_ST; 
    uniform fixed _mStrong;

    struct vI
    {
      float4 mPosition : POSITION;
      float2 mTexcoord : TEXCOORD0;
      float3 mNormal  : NORMAL;
    };

    struct vO
    {
      float4 mPositon  : POSITION;
      float2 mTexcoord : TEXCOORD0;
      float2 mMatcap : TEXCOORD1;
      //float3 tan1 : TEXCOORD3;
      //float3 tan2 : TEXCOORD4;
    };


    vO vert(vI i)
    {
      vO o;
      o.mPositon = mul(UNITY_MATRIX_MVP, i.mPosition);
       //타일링, 오프셋 조절을 위해서 쓰임.
      o.mTexcoord = TRANSFORM_TEX(i.mTexcoord,_MainTex);

      half2 capCoord; 
      //모델뷰행렬의 x,y벡터(아직완전히 이해 못했음) 와 노멀과의 내적구함, 그러면 값은 -1~1 사이가 되겠지.
      capCoord.x = dot(UNITY_MATRIX_MV[0].xyz, i.mNormal); 
      capCoord.y = dot(UNITY_MATRIX_MV[1].xyz, i.mNormal); 
      o.mMatcap = capCoord*0.5+0.5; 
      // TANGENT_SPACE_ROTATION;
      // o.tan1 = mul(rotation, UNITY_MATRIX_IT_MV[0].xyz);
      // o.tan2 = mul(rotation, UNITY_MATRIX_IT_MV[1].xyz);
      // float2 litSphereUV;
      // litSphereUV.x = dot(o.tan1,i.mNormal);
      // litSphereUV.y = dot(o.tan2,i.mNormal);
      // o.mMatcap = litSphereUV*0.5 + 0.5;
      return o;
    }

    float4 frag(vO i) : COLOR
    {
      fixed4 oColor = tex2D(_MainTex, i.mTexcoord);
      fixed4 oMatcap = tex2D(_Matcap, i.mMatcap);
      fixed4 final = lerp(oColor, oMatcap * _mStrong, oColor.a);
      return final;
    }

    ENDCG
    Zwrite on
    }
  } 
}

'Material, BluePrint > Material' 카테고리의 다른 글

UNITY- [Triple s]  (0) 2020.05.07
UNITY- [Triple s-ProtoType]  (0) 2020.05.07
UNITY - vertex anim  (0) 2020.05.07
UNITY - Outline  (0) 2020.05.07
UNITY - Lobby  (0) 2020.05.07