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.

209 lines
10 KiB

  1. // Made with Amplify Shader Editor
  2. // Available at the Unity Asset Store - http://u3d.as/y3X
  3. Shader "ASESampleShaders/RefractedShadows"
  4. {
  5. Properties
  6. {
  7. [HideInInspector] __dirty( "", Int ) = 1
  8. [HideInInspector]_SpecColor("SpecularColor",Color)=(1,1,1,1)
  9. _NormalMap("Normal Map", 2D) = "bump" {}
  10. _NormalScale("Normal Scale", Range( 0 , 1)) = 0
  11. _ShadowTransform("Shadow Transform", Range( 0 , 5)) = 0.5
  12. [HideInInspector] _texcoord( "", 2D ) = "white" {}
  13. }
  14. SubShader
  15. {
  16. Tags{ "RenderType" = "Opaque" "Queue" = "Transparent+0" "IsEmissive" = "true" }
  17. Cull Back
  18. GrabPass{ }
  19. CGINCLUDE
  20. #include "UnityStandardUtils.cginc"
  21. #include "UnityCG.cginc"
  22. #include "UnityPBSLighting.cginc"
  23. #include "Lighting.cginc"
  24. #pragma target 3.0
  25. #ifdef UNITY_PASS_SHADOWCASTER
  26. #undef INTERNAL_DATA
  27. #undef WorldReflectionVector
  28. #undef WorldNormalVector
  29. #define INTERNAL_DATA half3 internalSurfaceTtoW0; half3 internalSurfaceTtoW1; half3 internalSurfaceTtoW2;
  30. #define WorldReflectionVector(data,normal) reflect (data.worldRefl, half3(dot(data.internalSurfaceTtoW0,normal), dot(data.internalSurfaceTtoW1,normal), dot(data.internalSurfaceTtoW2,normal)))
  31. #define WorldNormalVector(data,normal) fixed3(dot(data.internalSurfaceTtoW0,normal), dot(data.internalSurfaceTtoW1,normal), dot(data.internalSurfaceTtoW2,normal))
  32. #endif
  33. struct Input
  34. {
  35. float3 worldNormal;
  36. INTERNAL_DATA
  37. float2 uv_texcoord;
  38. float3 worldPos;
  39. float4 screenPos;
  40. };
  41. uniform float _NormalScale;
  42. uniform sampler2D _NormalMap;
  43. uniform float4 _NormalMap_ST;
  44. uniform sampler2D _GrabTexture;
  45. uniform float _ShadowTransform;
  46. void surf( Input i , inout SurfaceOutput o )
  47. {
  48. o.Normal = float3(0,0,1);
  49. float2 uv_NormalMap = i.uv_texcoord * _NormalMap_ST.xy + _NormalMap_ST.zw;
  50. float3 tex2DNode10 = UnpackScaleNormal( tex2D( _NormalMap, uv_NormalMap ) ,_NormalScale );
  51. float3 ase_worldPos = i.worldPos;
  52. float3 ase_worldViewDir = normalize( UnityWorldSpaceViewDir( ase_worldPos ) );
  53. float dotResult25 = dot( WorldNormalVector( i , tex2DNode10 ) , ase_worldViewDir );
  54. float4 ase_screenPos = float4( i.screenPos.xyz , i.screenPos.w + 0.00000000001 );
  55. float4 ase_screenPos9 = ase_screenPos;
  56. #if UNITY_UV_STARTS_AT_TOP
  57. float scale9 = -1.0;
  58. #else
  59. float scale9 = 1.0;
  60. #endif
  61. float halfPosW9 = ase_screenPos9.w * 0.5;
  62. ase_screenPos9.y = ( ase_screenPos9.y - halfPosW9 ) * _ProjectionParams.x* scale9 + halfPosW9;
  63. ase_screenPos9.xyzw /= ase_screenPos9.w;
  64. float4 screenColor8 = tex2Dproj( _GrabTexture, UNITY_PROJ_COORD( ( ase_screenPos9 + float4( tex2DNode10 , 0.0 ) ) ) );
  65. o.Emission = ( ( 1.0 - ( dotResult25 * 0.8 ) ) * screenColor8 ).rgb;
  66. float3 ase_worldlightDir = normalize( UnityWorldSpaceLightDir( ase_worldPos ) );
  67. float dotResult6 = dot( WorldNormalVector( i , tex2DNode10 ) , ase_worldlightDir );
  68. o.Alpha = ( 1.0 - saturate( (dotResult6*_ShadowTransform + _ShadowTransform) ) );
  69. }
  70. ENDCG
  71. CGPROGRAM
  72. #pragma surface surf BlinnPhong keepalpha fullforwardshadows exclude_path:deferred
  73. ENDCG
  74. Pass
  75. {
  76. Name "ShadowCaster"
  77. Tags{ "LightMode" = "ShadowCaster" }
  78. ZWrite On
  79. CGPROGRAM
  80. #pragma vertex vert
  81. #pragma fragment frag
  82. #pragma target 3.0
  83. #pragma multi_compile_shadowcaster
  84. #pragma multi_compile UNITY_PASS_SHADOWCASTER
  85. #pragma skip_variants FOG_LINEAR FOG_EXP FOG_EXP2
  86. # include "HLSLSupport.cginc"
  87. #if ( SHADER_API_D3D11 || SHADER_API_GLCORE || SHADER_API_GLES3 || SHADER_API_METAL || SHADER_API_VULKAN )
  88. #define CAN_SKIP_VPOS
  89. #endif
  90. #include "UnityCG.cginc"
  91. #include "Lighting.cginc"
  92. #include "UnityPBSLighting.cginc"
  93. sampler3D _DitherMaskLOD;
  94. struct v2f
  95. {
  96. V2F_SHADOW_CASTER;
  97. float4 screenPos : TEXCOORD7;
  98. float4 tSpace0 : TEXCOORD1;
  99. float4 tSpace1 : TEXCOORD2;
  100. float4 tSpace2 : TEXCOORD3;
  101. float4 texcoords01 : TEXCOORD4;
  102. UNITY_VERTEX_INPUT_INSTANCE_ID
  103. };
  104. v2f vert( appdata_full v )
  105. {
  106. v2f o;
  107. UNITY_SETUP_INSTANCE_ID( v );
  108. UNITY_INITIALIZE_OUTPUT( v2f, o );
  109. UNITY_TRANSFER_INSTANCE_ID( v, o );
  110. float3 worldPos = mul( unity_ObjectToWorld, v.vertex ).xyz;
  111. fixed3 worldNormal = UnityObjectToWorldNormal( v.normal );
  112. fixed3 worldTangent = UnityObjectToWorldDir( v.tangent.xyz );
  113. fixed tangentSign = v.tangent.w * unity_WorldTransformParams.w;
  114. fixed3 worldBinormal = cross( worldNormal, worldTangent ) * tangentSign;
  115. o.tSpace0 = float4( worldTangent.x, worldBinormal.x, worldNormal.x, worldPos.x );
  116. o.tSpace1 = float4( worldTangent.y, worldBinormal.y, worldNormal.y, worldPos.y );
  117. o.tSpace2 = float4( worldTangent.z, worldBinormal.z, worldNormal.z, worldPos.z );
  118. o.texcoords01 = float4( v.texcoord.xy, v.texcoord1.xy );
  119. TRANSFER_SHADOW_CASTER_NORMALOFFSET( o )
  120. o.screenPos = ComputeScreenPos( o.pos );
  121. return o;
  122. }
  123. fixed4 frag( v2f IN
  124. #if !defined( CAN_SKIP_VPOS )
  125. , UNITY_VPOS_TYPE vpos : VPOS
  126. #endif
  127. ) : SV_Target
  128. {
  129. UNITY_SETUP_INSTANCE_ID( IN );
  130. Input surfIN;
  131. UNITY_INITIALIZE_OUTPUT( Input, surfIN );
  132. surfIN.uv_texcoord.xy = IN.texcoords01.xy;
  133. float3 worldPos = float3( IN.tSpace0.w, IN.tSpace1.w, IN.tSpace2.w );
  134. fixed3 worldViewDir = normalize( UnityWorldSpaceViewDir( worldPos ) );
  135. surfIN.worldPos = worldPos;
  136. surfIN.worldNormal = float3( IN.tSpace0.z, IN.tSpace1.z, IN.tSpace2.z );
  137. surfIN.internalSurfaceTtoW0 = IN.tSpace0.xyz;
  138. surfIN.internalSurfaceTtoW1 = IN.tSpace1.xyz;
  139. surfIN.internalSurfaceTtoW2 = IN.tSpace2.xyz;
  140. surfIN.screenPos = IN.screenPos;
  141. SurfaceOutput o;
  142. UNITY_INITIALIZE_OUTPUT( SurfaceOutput, o )
  143. surf( surfIN, o );
  144. #if defined( CAN_SKIP_VPOS )
  145. float2 vpos = IN.pos;
  146. #endif
  147. half alphaRef = tex3D( _DitherMaskLOD, float3( vpos.xy * 0.25, o.Alpha * 0.9375 ) ).a;
  148. clip( alphaRef - 0.01 );
  149. SHADOW_CASTER_FRAGMENT( IN )
  150. }
  151. ENDCG
  152. }
  153. }
  154. Fallback "Diffuse"
  155. CustomEditor "ASEMaterialInspector"
  156. }
  157. /*ASEBEGIN
  158. Version=13202
  159. 487;574;979;444;2025.876;664.6953;3.45599;False;False
  160. Node;AmplifyShaderEditor.RangedFloatNode;13;-1398.398,237.6999;Float;False;Property;_NormalScale;Normal Scale;1;0;0;0;1;0;1;FLOAT
  161. Node;AmplifyShaderEditor.SamplerNode;10;-1064.799,169.1;Float;True;Property;_NormalMap;Normal Map;0;0;None;True;0;True;bump;Auto;True;Object;-1;Auto;Texture2D;6;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;1.0;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1.0;False;5;FLOAT3;FLOAT;FLOAT;FLOAT;FLOAT
  162. Node;AmplifyShaderEditor.CommentaryNode;31;-648.5012,-490.8;Float;False;476.999;396.6;Traditional nDotV to fake thickness;3;25;28;26;;1,1,1,1;0;0
  163. Node;AmplifyShaderEditor.CommentaryNode;33;-682.7992,411.2999;Float;False;444.1991;333.4001;Traditional nDotL to fake custom shadowing;3;6;4;7;;1,1,1,1;0;0
  164. Node;AmplifyShaderEditor.WorldNormalVector;26;-598.5012,-440.8002;Float;False;1;0;FLOAT3;0,0,0;False;4;FLOAT3;FLOAT;FLOAT;FLOAT
  165. Node;AmplifyShaderEditor.WorldNormalVector;4;-632.7992,461.2999;Float;False;1;0;FLOAT3;0,0,0;False;4;FLOAT3;FLOAT;FLOAT;FLOAT
  166. Node;AmplifyShaderEditor.CommentaryNode;32;-553.2001,-27.89989;Float;False;681.9003;359.4998;Simple Refraction with normal perturbance;3;8;12;9;;1,1,1,1;0;0
  167. Node;AmplifyShaderEditor.WorldSpaceLightDirHlpNode;7;-626.5995,632.7;Float;False;1;0;FLOAT;0.0;False;1;FLOAT3
  168. Node;AmplifyShaderEditor.ViewDirInputsCoordNode;28;-522.2015,-283.2002;Float;False;World;0;4;FLOAT3;FLOAT;FLOAT;FLOAT
  169. Node;AmplifyShaderEditor.GrabScreenPosition;9;-503.2005,22.10012;Float;False;0;0;5;FLOAT4;FLOAT;FLOAT;FLOAT;FLOAT
  170. Node;AmplifyShaderEditor.DotProductOpNode;6;-397.6001,530.8999;Float;False;2;0;FLOAT3;0,0,0;False;1;FLOAT3;0,0,0;False;1;FLOAT
  171. Node;AmplifyShaderEditor.DotProductOpNode;25;-330.5021,-322.8004;Float;False;2;0;FLOAT3;0,0,0;False;1;FLOAT3;0,0,0;False;1;FLOAT
  172. Node;AmplifyShaderEditor.RangedFloatNode;22;-539.9011,771.3002;Float;False;Property;_ShadowTransform;Shadow Transform;2;0;0.5;0;5;0;1;FLOAT
  173. Node;AmplifyShaderEditor.ScaleAndOffsetNode;23;-176.8009,670.4999;Float;False;3;0;FLOAT;0.0;False;1;FLOAT;0.5;False;2;FLOAT;0.5;False;1;FLOAT
  174. Node;AmplifyShaderEditor.SimpleAddOpNode;12;-256,144;Float;False;2;2;0;FLOAT4;0,0,0,0;False;1;FLOAT3;0.0,0,0,0;False;1;FLOAT4
  175. Node;AmplifyShaderEditor.ScaleNode;30;-97.90162,-189.4999;Float;False;0.8;1;0;FLOAT;0.0;False;1;FLOAT
  176. Node;AmplifyShaderEditor.ScreenColorNode;8;-88.29998,119.5999;Float;False;Global;_GrabScreen0;Grab Screen 0;1;0;Object;-1;False;1;0;FLOAT4;0,0,0,0;False;5;COLOR;FLOAT;FLOAT;FLOAT;FLOAT
  177. Node;AmplifyShaderEditor.SaturateNode;20;33.49896,590.6998;Float;False;1;0;FLOAT;0.0;False;1;FLOAT
  178. Node;AmplifyShaderEditor.OneMinusNode;29;94.29845,-138.0001;Float;False;1;0;FLOAT;0.0;False;1;FLOAT
  179. Node;AmplifyShaderEditor.OneMinusNode;18;212.4997,445.4994;Float;False;1;0;FLOAT;0.0;False;1;FLOAT
  180. Node;AmplifyShaderEditor.SimpleMultiplyOpNode;27;295.2985,-33.50013;Float;False;2;2;0;FLOAT;0.0;False;1;COLOR;0;False;1;COLOR
  181. Node;AmplifyShaderEditor.StandardSurfaceOutputNode;0;526.9,-104.2;Float;False;True;2;Float;ASEMaterialInspector;0;0;BlinnPhong;ASESampleShaders/RefractedShadows;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;Back;0;0;False;0;0;Translucent;0.5;True;True;0;False;Opaque;Transparent;ForwardOnly;True;True;True;True;True;True;True;True;True;True;True;True;True;True;True;True;True;False;0;255;255;0;0;0;0;False;0;4;10;25;False;0.5;True;0;Zero;Zero;0;Zero;Zero;Add;Add;0;False;0;0,0,0,0;VertexOffset;False;Cylindrical;False;Relative;0;;-1;-1;-1;-1;0;0;0;14;0;FLOAT3;0,0,0;False;1;FLOAT3;0,0,0;False;2;FLOAT3;0,0,0;False;3;FLOAT;0.0;False;4;FLOAT;0.0;False;6;FLOAT3;0,0,0;False;7;FLOAT3;0,0,0;False;8;FLOAT;0.0;False;9;FLOAT;0.0;False;10;OBJECT;0;False;11;FLOAT3;0.0,0,0;False;12;FLOAT3;0,0,0;False;14;FLOAT4;0,0,0,0;False;15;FLOAT3;0,0,0;False;0
  182. WireConnection;10;5;13;0
  183. WireConnection;26;0;10;0
  184. WireConnection;4;0;10;0
  185. WireConnection;6;0;4;0
  186. WireConnection;6;1;7;0
  187. WireConnection;25;0;26;0
  188. WireConnection;25;1;28;0
  189. WireConnection;23;0;6;0
  190. WireConnection;23;1;22;0
  191. WireConnection;23;2;22;0
  192. WireConnection;12;0;9;0
  193. WireConnection;12;1;10;0
  194. WireConnection;30;0;25;0
  195. WireConnection;8;0;12;0
  196. WireConnection;20;0;23;0
  197. WireConnection;29;0;30;0
  198. WireConnection;18;0;20;0
  199. WireConnection;27;0;29;0
  200. WireConnection;27;1;8;0
  201. WireConnection;0;2;27;0
  202. WireConnection;0;9;18;0
  203. ASEEND*/
  204. //CHKSM=07C921B5E38AF05C003671AE4D03E15F1682F35C