Unity Kajiya Hair Shader corrected by Vert Normals

Source: Internet
Author: User
Tags abs pow

Shader "Hairshader"
{
Properties
{
_maintex ("Diffuse (RGB) Alpha (A)", 2D) = "White" {}
_color ("Main Color", color) = (0,0,0,1)
_speculartex ("Specular (R) Gloss (G) Anisotropic Mask (B)", 2D) = "Gray" {}
_specularmultipliert ("Specular Multiplier T", float) = 5.0
_specularmultipliern ("Specular Multiplier N", float) = 10.0
_specularcolor ("Specular color", color) = (0.5,0.5,0.5,1)
_cutoff ("Alpha cut-off Threshold", float) = 0.5
_glossinterp ("Gloss interploter", Range ( -1,1)) = 0
_wavespeed ("Wave speed", Vector) = (1,1,1,1)
_wavesize ("Wave Size", float) = 0.1
_wavephase ("Wave Phase", float) = 0.02
}

Subshader
{
Tags {"Queue" = "Geometry" "ignoreprojector" = "True" "rendertype" = "Transparentcutout"}

Cull OFF
Zwrite on
ZTest lequal

Cgprogram
#pragma surface surf Aniso vertex:vert
#pragma target 3.0

struct SURFACEOUTPUTANISO
{
Fixed3 Albedo;
Fixed3 Normal;
FIXED3 emission;
Half specular;
Fixed Gloss;
Fixed Alpha;
Fixed anisomask;

Half3 Tangentv;
};

struct Input
{
FLOAT2 Uv_maintex;
Half3 Tangentv;
};


FLOAT4 _wavespeed;
float _wavesize;
float _wavephase;

void Vert (InOut appdata_full V, out Input O)
{
Unity_initialize_output (Input, O);

FLOAT3 waves = _wavesize * V.TANGENT.XYZ;
FLOAT3 freq = _time.y * _WAVESPEED.XYZ;
V.VERTEX.XYZ + = cos (freq + v.vertex.xyz * _wavephase) * waves;
O.tangentv = v.tangent.xyz;
}


sampler2d _maintex, _speculartex;
Float _specularmultipliert,_specularmultipliern, _glossinterp, _cutoff;
Fixed4 _specularcolor, _color;

Void Surf (Input in, InOut surfaceoutputaniso o)
{
Fixed4 albedo = tex2d (_maintex, In.uv_maintex);
O.albedo = Lerp (albedo.rgb,albedo.rgb*_color.rgb,0.5);
O.alpha = albedo.a;
Clip (O.alpha-_cutoff);
Fixed3 spec = tex2d (_speculartex, In.uv_maintex). RGB;
O.specular = SPEC.R;
O.gloss = SPEC.G;
O.anisomask = spec.b;
O.tangentv = In.tangentv;
}

Inline Fixed4 Lightinganiso (surfaceoutputaniso s, fixed3 Lightdir, Fixed3 viewdir, fixed atten)
{
Half3 h = Normalize (Lightdir + viewdir);
float Ndotl = saturate (dot (s.normal, lightdir));

Half3 T = normalize (Cross (S.normal, S.tangentv));
Half3 L = normalize (Lightdir);
Half3 V =-normalize (Viewdir);

float sq1 = (1.0-abs (dot (T, L));
float SQ2 = (1.0-abs (dot (T, V)));
float Aniso = ABS (dot (t,l) * DOT (s.normal,v));
Aniso + = sq1 * SQ2;
Aniso = Pow (aniso, _specularmultipliert);

float Blinn = POW (dot (s.normal, h), _specularmultipliern) * S.GLOSS;

Float spec = saturate (Lerp (Blinn, Aniso, S.anisomask + _glossinterp) * s.specular) * _SPECULARCOLOR;

Fixed4 C;
C.rgb = spec;
C.A = S.alpha;
return C;
}
Endcg


}
FallBack OFF
}

Unity Kajiya Hair Shader corrected by Vert Normals

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.