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.

71 lines
1.4 KiB

  1. // UNITY_SHADER_NO_UPGRADE
  2. Shader "Custom/TransparentFresnel"
  3. {
  4. Properties{
  5. _Color("Rim Color", Color) = (0.5,0.5,0.5,0.5)
  6. _FPOW("FPOW Fresnel", Float) = 5.0
  7. _R0("R0 Fresnel", Float) = 0.05
  8. _MainTex("Bumpmap", 2D) = "bump" {}
  9. }
  10. Category{
  11. Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
  12. Blend SrcAlpha OneMinusSrcAlpha
  13. ZWrite On
  14. SubShader{
  15. Pass{
  16. CGPROGRAM
  17. #pragma vertex vert
  18. #pragma fragment frag
  19. #include "UnityCG.cginc"
  20. sampler2D _MainTex;
  21. fixed4 _Color;
  22. float _FPOW;
  23. float _R0;
  24. struct appdata_t {
  25. float4 vertex : POSITION;
  26. fixed4 color : COLOR;
  27. float2 texcoord : TEXCOORD0;
  28. float3 normal : NORMAL;
  29. };
  30. struct v2f {
  31. float4 vertex : POSITION;
  32. fixed4 color : COLOR;
  33. float2 texcoord : TEXCOORD0;
  34. };
  35. float4 _MainTex_ST;
  36. v2f vert(appdata_t v)
  37. {
  38. v2f o;
  39. #if UNITY_VERSION >= 560
  40. o.vertex = UnityObjectToClipPos(v.vertex);
  41. #else
  42. o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
  43. #endif
  44. o.color = v.color;
  45. o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
  46. float3 viewDir = normalize(ObjSpaceViewDir(v.vertex));
  47. half fresnel = saturate(1.0 - dot(v.normal, viewDir));
  48. fresnel = pow(fresnel, _FPOW);
  49. fresnel = _R0 + (1.0 - _R0) * fresnel;
  50. o.color *= fresnel;
  51. return o;
  52. }
  53. fixed4 frag(v2f i) : COLOR
  54. {
  55. return 2.0f * i.color * _Color * tex2D(_MainTex, i.texcoord);
  56. }
  57. ENDCG
  58. }
  59. }
  60. }
  61. }