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.

113 lines
3.6 KiB

  1. //
  2. // OvrAvatar PC single component shader
  3. // For use on non-expressive face meshes and other components
  4. //
  5. // Unity Surface Shader implementation
  6. // Mobile vertex/fragment shader is recommended for use on mobile platforms for performance
  7. //
  8. // Uses transparent queue for fade effects
  9. //
  10. Shader "OvrAvatar/Avatar_PC_SingleComponent"
  11. {
  12. Properties
  13. {
  14. [NoScaleOffset] _MainTex("Color (RGB)", 2D) = "white" {}
  15. [NoScaleOffset] _NormalMap("Normal Map", 2D) = "bump" {}
  16. [NoScaleOffset] _RoughnessMap("Roughness Map", 2D) = "black" {}
  17. _BaseColor("Color Tint", Color) = (1.0,1.0,1.0,1.0)
  18. _Dimmer("Dimmer", Range(0.0,1.0)) = 1.0
  19. _Alpha("Alpha", Range(0.0,1.0)) = 1.0
  20. _DiffuseIntensity("Diffuse Intensity", Range(0.0,1.0)) = 0.3
  21. _SmoothnessMultiplier("Smoothness Multiplier", Range(0.0,1.0)) = 1.0
  22. _MetallicMultiplier("Metallic Multiplier", Range(0.0,1.0)) = 1.0
  23. _RimIntensity("Rim Intensity", Range(0.0,10.0)) = 5.0
  24. [HideInInspector] _SrcBlend("", Float) = 1
  25. [HideInInspector] _DstBlend("", Float) = 0
  26. }
  27. SubShader
  28. {
  29. Blend [_SrcBlend] [_DstBlend]
  30. Cull Back
  31. CGPROGRAM
  32. #pragma surface surf Standard keepalpha fullforwardshadows
  33. #pragma target 3.0
  34. #pragma fragmentoption ARB_precision_hint_fastest
  35. #include "UnityCG.cginc"
  36. sampler2D _MainTex;
  37. sampler2D _NormalMap;
  38. sampler2D _RoughnessMap;
  39. half4 _BaseColor;
  40. half _Dimmer;
  41. half _Alpha;
  42. half _DiffuseIntensity;
  43. half _SmoothnessMultiplier;
  44. half _MetallicMultiplier;
  45. half _RimIntensity;
  46. struct Input
  47. {
  48. float2 uv_MainTex;
  49. float2 uv_NormalMap;
  50. float2 uv_RoughnessMap;
  51. float3 viewDir;
  52. float3 worldNormal; INTERNAL_DATA
  53. };
  54. void surf(Input IN, inout SurfaceOutputStandard o)
  55. {
  56. // Diffuse texture sample
  57. half4 albedoColor = tex2D(_MainTex, IN.uv_MainTex);
  58. // Unpack normal map
  59. #if (UNITY_VERSION >= 20171)
  60. o.Normal = UnpackNormal(tex2D(_NormalMap, IN.uv_MainTex));
  61. #else
  62. o.Normal = tex2D(_NormalMap, IN.uv_MainTex) * 2.0 - 1.0;
  63. #endif
  64. // Roughness contains metallic in r, smoothness in a
  65. half4 roughnessTex = tex2D(_RoughnessMap, IN.uv_MainTex);
  66. // Normal/Light/View calculations
  67. half NdotL = saturate(dot(WorldNormalVector(IN, o.Normal), _WorldSpaceLightPos0.xyz));
  68. half VdotN = saturate(dot(normalize(IN.viewDir), o.Normal));
  69. // Color space conversions if we are in linear
  70. #ifndef UNITY_COLORSPACE_GAMMA
  71. _BaseColor.rgb = LinearToGammaSpace(_BaseColor.rgb);
  72. #endif
  73. // Set smoothness and metallic
  74. o.Smoothness = roughnessTex.a * _SmoothnessMultiplier;
  75. o.Metallic = roughnessTex.r * _MetallicMultiplier;
  76. // Final base color including DiffuseIntensity and NdotL for lighting gradient
  77. _BaseColor.rgb += _DiffuseIntensity * NdotL;
  78. // Multiply texture with base color
  79. o.Albedo = albedoColor.rgb * _BaseColor;
  80. // Rim term
  81. o.Albedo += pow(1.0 - VdotN, _RimIntensity) * NdotL;
  82. // Global dimmer
  83. o.Albedo *= _Dimmer;
  84. // Convert back to linear color space if we are in linear
  85. #if !defined(UNITY_COLORSPACE_GAMMA)
  86. o.Albedo = GammaToLinearSpace(o.Albedo);
  87. #endif
  88. o.Albedo = saturate(o.Albedo);
  89. // Global alpha
  90. o.Alpha = albedoColor.a * _Alpha;
  91. }
  92. ENDCG
  93. }
  94. Fallback "Diffuse"
  95. }