Gem.shader 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
  2. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  3. Shader "FX/Gem"
  4. {
  5. Properties {
  6. _Color ("Color", Color) = (1,1,1,1)
  7. _ReflectionStrength ("Reflection Strength", Range(0.0,2.0)) = 1.0
  8. _EnvironmentLight ("Environment Light", Range(0.0,2.0)) = 1.0
  9. _Emission ("Emission", Range(0.0,2.0)) = 0.0
  10. [NoScaleOffset] _RefractTex ("Refraction Texture", Cube) = "" {}
  11. }
  12. SubShader {
  13. Tags {
  14. "Queue" = "Transparent"
  15. }
  16. // First pass - here we render the backfaces of the diamonds. Since those diamonds are more-or-less
  17. // convex objects, this is effectively rendering the inside of them.
  18. Pass {
  19. Cull Front
  20. ZWrite Off
  21. CGPROGRAM
  22. #pragma vertex vert
  23. #pragma fragment frag
  24. #include "UnityCG.cginc"
  25. struct v2f {
  26. float4 pos : SV_POSITION;
  27. float3 uv : TEXCOORD0;
  28. };
  29. v2f vert (float4 v : POSITION, float3 n : NORMAL)
  30. {
  31. v2f o;
  32. o.pos = UnityObjectToClipPos(v);
  33. // TexGen CubeReflect:
  34. // reflect view direction along the normal, in view space.
  35. float3 viewDir = normalize(ObjSpaceViewDir(v));
  36. o.uv = -reflect(viewDir, n);
  37. o.uv = mul(unity_ObjectToWorld, float4(o.uv,0));
  38. return o;
  39. }
  40. fixed4 _Color;
  41. samplerCUBE _RefractTex;
  42. half _EnvironmentLight;
  43. half _Emission;
  44. half4 frag (v2f i) : SV_Target
  45. {
  46. half3 refraction = texCUBE(_RefractTex, i.uv).rgb * _Color.rgb;
  47. half4 reflection = UNITY_SAMPLE_TEXCUBE(unity_SpecCube0, i.uv);
  48. reflection.rgb = DecodeHDR (reflection, unity_SpecCube0_HDR);
  49. half3 multiplier = reflection.rgb * _EnvironmentLight + _Emission;
  50. return half4(refraction.rgb * multiplier.rgb, 1.0f);
  51. }
  52. ENDCG
  53. }
  54. // Second pass - here we render the front faces of the diamonds.
  55. Pass {
  56. ZWrite On
  57. Blend One One
  58. CGPROGRAM
  59. #pragma vertex vert
  60. #pragma fragment frag
  61. #include "UnityCG.cginc"
  62. struct v2f {
  63. float4 pos : SV_POSITION;
  64. float3 uv : TEXCOORD0;
  65. half fresnel : TEXCOORD1;
  66. };
  67. v2f vert (float4 v : POSITION, float3 n : NORMAL)
  68. {
  69. v2f o;
  70. o.pos = UnityObjectToClipPos(v);
  71. // TexGen CubeReflect:
  72. // reflect view direction along the normal, in view space.
  73. float3 viewDir = normalize(ObjSpaceViewDir(v));
  74. o.uv = -reflect(viewDir, n);
  75. o.uv = mul(unity_ObjectToWorld, float4(o.uv,0));
  76. o.fresnel = 1.0 - saturate(dot(n,viewDir));
  77. return o;
  78. }
  79. fixed4 _Color;
  80. samplerCUBE _RefractTex;
  81. half _ReflectionStrength;
  82. half _EnvironmentLight;
  83. half _Emission;
  84. half4 frag (v2f i) : SV_Target
  85. {
  86. half3 refraction = texCUBE(_RefractTex, i.uv).rgb * _Color.rgb;
  87. half4 reflection = UNITY_SAMPLE_TEXCUBE(unity_SpecCube0, i.uv);
  88. reflection.rgb = DecodeHDR (reflection, unity_SpecCube0_HDR);
  89. half3 reflection2 = reflection * _ReflectionStrength * i.fresnel;
  90. half3 multiplier = reflection.rgb * _EnvironmentLight + _Emission;
  91. return fixed4(reflection2 + refraction.rgb * multiplier, 1.0f);
  92. }
  93. ENDCG
  94. }
  95. // Shadow casting & depth texture support -- so that gems can
  96. // cast shadows
  97. UsePass "VertexLit/SHADOWCASTER"
  98. }
  99. }