Jean Moreno 님이 제공 하신 MatCap 쉐이더를 조금 손봤습니다.

Jean Moreno 님이 제공 하신 MatCap 쉐이더를 조금 손봤습니다.
기본적인 MatCap 에 림라이팅을 추가 했습니다.
림파워는 변수로 뺐고 림레인지는 림라이팅 폴오프 이미지를 직접 만들어 적용 해 주면 됩니다.


RimTexture.


// MatCap Shader, (c) 2013 Jean Moreno
//MatCap Shader Ghost based Texture unit added Customizing Author (c) 2013 JP.Lee

Shader "MatCap/Vertex/Textured Multiply_Rim"
{
Properties
{
_RimPower ("RimPower", Range(0,3)) = 1
_MainTex ("Base (RGB)", 2D) = "white" {}
_MatCap ("MatCap (RGB)", 2D) = "white" {}
_MatRim ("RimTex (RGB)", 2D) = "white" {}


}

Subshader
{
Tags { "RenderType"="Opaque" }
Pass
{


Tags { "LightMode" = "Always" }


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

struct v2f
{
float4 pos : SV_POSITION;
float2 uv  : TEXCOORD0;
float2 cap : TEXCOORD1;
};

uniform float4 _MainTex_ST;

v2f vert (appdata_base v)
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);

half2 capCoord;
capCoord.x = dot(UNITY_MATRIX_IT_MV[0].xyz,v.normal);
capCoord.y = dot(UNITY_MATRIX_IT_MV[1].xyz,v.normal);
o.cap = capCoord * 0.5 + 0.5;

return o;
}

uniform sampler2D _MainTex;
uniform sampler2D _MatCap;
uniform sampler2D _MatRim;
uniform float _RimPower;

fixed4 frag (v2f i) : COLOR
{
fixed4 tex = tex2D(_MainTex, i.uv);
fixed4 mc = tex2D(_MatCap, i.cap);
fixed4 mcRim = tex2D(_MatRim, i.cap);

return tex * mc * 2.0 + (mcRim * _RimPower);
}
ENDCG
}
}

Fallback "VertexLit"
}


Game Developer Leegoon copyright all right reserved since 2010.

Comments