Skip to content

Instantly share code, notes, and snippets.

@slipster216
Last active February 2, 2022 17:12
Show Gist options
  • Save slipster216/88d2ecff0bd49098874a7f801bcef573 to your computer and use it in GitHub Desktop.
Save slipster216/88d2ecff0bd49098874a7f801bcef573 to your computer and use it in GitHub Desktop.
BEGIN_OPTIONS
Workflow "Unlit"
END_OPTIONS
BEGIN_PROPERTIES
_Matcap("Matcap Texture", 2D) = "white" {}
END_PROPERTIES
BEGIN_CODE
TEXTURE2D(_Matcap);
SAMPLER(sampler_Matcap);
void SurfaceFunction(inout Surface o, ShaderData d)
{
float3 up = mul((float3x3)UNITY_MATRIX_I_V, float3(0,1,0));
float3 right = normalize(cross(up, d.worldSpaceViewDir));
up = cross(d.worldSpaceViewDir, right);
float2 matcapUV = mul(float3x3(right, up, d.worldSpaceViewDir), d.worldSpaceNormal).xy;
matcapUV = matcapUV * 0.5 + 0.5;
o.Albedo *= SAMPLE_TEXTURE2D(_Matcap, sampler_Matcap, matcapUV).rgb;
}
END_CODE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment