BlueGit

blue-star ggj-2020

Files

ggj-2020 / Assets / Oculus / Avatar / Resources / Materials / Expressive / AvatarEyeLens.shader

AvatarEyeLens.shader

Project Import
timfa Tim Falken · pushed by timfa · 6 years ago
b77834a1 History
AvatarEyeLens.shader 2.9 KiB Download Raw
1//
2// OvrAvatar eye lens shader
3//
4// Generates glint on the eye lens of expressive avatars
5//
6
7Shader "OvrAvatar/Avatar_EyeLens"
8{
9 Properties
10 {
11 _Cube("Cubemap Reflection", CUBE) = "black" {}
12 _ReflectionIntensity("Reflection Intensity", Range(0.0,1.0)) = 0.2
13 _GlintStrength("Glint Strength", Range(0, 10)) = 1.57
14 _GlintSpead("Glint Spead", Range(32, 2048)) = 600
15 _Alpha("Alpha", Range(0.0,1.0)) = 1.0
16 }
17
18 SubShader
19 {
20 Tags { "LightMode" = "ForwardBase" "Queue" = "Transparent" "RenderType" = "Transparent" "IgnoreProjector" = "True" }
21 Pass
22 {
23 Blend SrcAlpha OneMinusSrcAlpha
24
25 CGPROGRAM
26 #pragma vertex vert
27 #pragma fragment frag
28 #pragma fragmentoption ARB_precision_hint_fastest
29 #pragma target 3.0
30 #include "UnityCG.cginc"
31 #include "UnityLightingCommon.cginc"
32 #include "AutoLight.cginc"
33
34 samplerCUBE _Cube;
35 half _ReflectionIntensity;
36 half _GlintStrength;
37 half _GlintSpead;
38 half _Alpha;
39
40 struct VertexInput
41 {
42 float4 vertex : POSITION;
43 float3 normal : NORMAL;
44 };
45
46 struct VertexOutput
47 {
48 float4 pos : SV_POSITION;
49 float4 posWorld : TEXCOORD1;
50 float3 normalDir : TEXCOORD2;
51 };
52
53 VertexOutput vert(VertexInput v)
54 {
55 VertexOutput o = (VertexOutput)0;
56 o.normalDir = UnityObjectToWorldNormal(v.normal);
57 o.posWorld = mul(unity_ObjectToWorld, v.vertex);
58 o.pos = UnityObjectToClipPos(v.vertex);
59 return o;
60 }
61
62 float4 frag(VertexOutput i) : COLOR
63 {
64 i.normalDir = normalize(i.normalDir);
65 half3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
66 half NdotLV = max(0, dot(i.normalDir, normalize(_WorldSpaceLightPos0.xyz + viewDirection)));
67 half3 spec = pow(NdotLV, _GlintSpead) * _GlintStrength;
68
69 // Sample the default reflection cubemap using the reflection vector
70 half3 viewReflectDirection = reflect(-viewDirection, i.normalDir);
71 half4 skyData = UNITY_SAMPLE_TEXCUBE(unity_SpecCube0, viewReflectDirection);
72 // Decode cubemap data into actual color
73 half3 reflectionColor = DecodeHDR(skyData, unity_SpecCube0_HDR);
74
75 half4 finalColor;
76 finalColor.rgb = reflectionColor.rgb * _ReflectionIntensity;
77 finalColor.rgb += spec;
78 finalColor.a = (finalColor.r + finalColor.g + finalColor.b) / 3;
79
80 return finalColor;
81 }
82 ENDCG
83 }
84 }
85 FallBack "Diffuse"
86}