Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.9 KiB

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