Irisdescent.shader 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. Shader "Immersal/Samples/Irisdescent"
  2. {
  3. Properties
  4. {
  5. _DirectSpecular("Direct Specular Color", Color) = (1.0, 1.0, 1.0, 1.0)
  6. _DirectGlossiness("Direct Specular Glossiness", Range(1, 50)) = 10
  7. _IndirectSpecular("indirect Specular Color", Color) = (1.0, 1.0, 1.0, 1.0)
  8. _IndirectGlossiness("Indirect Specular Glossiness", Range(0, 1)) = 0.5
  9. _FresnelExponent("Fresnel Exponent", Range(0, 10)) = 1.0
  10. _MainTex("Glossiness Texture", 2D) = "white" {}
  11. [NoScaleOffset]
  12. _IBLTexCube("IBL Cubemap", Cube) = "black" {}
  13. }
  14. SubShader
  15. {
  16. Tags
  17. {
  18. "LightMode" = "UniversalForward"
  19. }
  20. LOD 100
  21. Pass
  22. {
  23. CGPROGRAM
  24. #pragma vertex vert
  25. #pragma fragment frag
  26. // make fog work
  27. #pragma multi_compile_fog
  28. #include "UnityCG.cginc"
  29. struct appdata
  30. {
  31. float4 P : POSITION;
  32. half3 N : NORMAL;
  33. half2 uv0 : TEXCOORD0;
  34. };
  35. struct v2f
  36. {
  37. float4 P : SV_POSITION;
  38. half3 N : NORMAL;
  39. half2 uv0 : TEXCOORD0;
  40. fixed3 Cd : COLOR;
  41. fixed3 I : TEXCOORD1;
  42. fixed3 R : TEXCOORD2;
  43. fixed3 L : TEXCOORD3;
  44. fixed falloff : TEXCOORD4;
  45. UNITY_FOG_COORDS(5)
  46. };
  47. sampler2D _MainTex;
  48. float4 _MainTex_ST;
  49. samplerCUBE _IBLTexCube;
  50. fixed3 _IndirectSpecular;
  51. fixed _IndirectGlossiness;
  52. fixed3 _DirectSpecular;
  53. fixed _DirectGlossiness;
  54. half _FresnelExponent;
  55. #define GLOSSY_MIP_COUNT 6
  56. fixed3 SampleTexCube(samplerCUBE cube, half3 normal, half mip)
  57. {
  58. return texCUBElod(cube, half4(normal, mip));
  59. }
  60. v2f vert(appdata v)
  61. {
  62. v2f o;
  63. UNITY_INITIALIZE_OUTPUT(v2f, o);
  64. o.P = UnityObjectToClipPos(v.P);
  65. o.N = UnityObjectToWorldNormal(v.N);
  66. o.uv0 = TRANSFORM_TEX(v.uv0, _MainTex);
  67. float3 worldPos = mul(unity_ObjectToWorld, v.P).xyz;
  68. o.I = normalize(worldPos - _WorldSpaceCameraPos);
  69. o.R = reflect(o.I, o.N);
  70. o.L = reflect(_WorldSpaceLightPos0, o.N);
  71. half3 H = normalize((o.N + o.R) * 0.5);
  72. fixed mix = pow(1 - 0 - max(0.0, dot(H, -o.I)), _FresnelExponent);
  73. o.falloff = lerp(0.2, 1.0, mix);
  74. UNITY_TRANSFER_FOG(o, o.P);
  75. return o;
  76. }
  77. fixed4 frag(v2f i) : SV_Target
  78. {
  79. fixed glossiness = 1.0 - (tex2D(_MainTex, i.uv0).a * _IndirectGlossiness);
  80. fixed3 directSpecular = pow(max(0.0, dot(i.L, i.I)), _DirectGlossiness) * _DirectSpecular * i.falloff;
  81. fixed3 indirectSpecular = SampleTexCube(_IBLTexCube, i.R, glossiness * GLOSSY_MIP_COUNT) * _IndirectSpecular * i.falloff;
  82. fixed edges = pow(1.0 - max(dot(-i.I, i.N), 0.0), 3.2);
  83. fixed4 color = 1.0;
  84. color.rgb = indirectSpecular + directSpecular + (_DirectSpecular * edges);
  85. // apply fog
  86. UNITY_APPLY_FOG(i.fogCoord, color);
  87. return color;
  88. }
  89. ENDCG
  90. }
  91. }
  92. FallBack "Diffuse"
  93. }