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.

283 lines
14 KiB

  1. // Made with Amplify Shader Editor
  2. // Available at the Unity Asset Store - http://u3d.as/y3X
  3. Shader "ASESampleShaders/ReflectRefractSoapBubble"
  4. {
  5. Properties
  6. {
  7. [HideInInspector] __dirty( "", Int ) = 1
  8. _Opacity("Opacity", Range( 0 , 1)) = 0
  9. _SoapAmount("Soap Amount", Range( 0 , 1)) = 0
  10. _Specular("Specular", Range( 0 , 1)) = 0
  11. _IndexofRefraction("Index of Refraction", Range( -3 , 4)) = 1
  12. _Smoothness("Smoothness", Range( 0 , 1)) = 0.8
  13. _Foam("Foam", 2D) = "white" {}
  14. _TextureSample3("Texture Sample 3", 2D) = "white" {}
  15. [HideInInspector] _texcoord( "", 2D ) = "white" {}
  16. [Header(Refraction)]
  17. _ChromaticAberration("Chromatic Aberration", Range( 0 , 0.3)) = 0.1
  18. }
  19. SubShader
  20. {
  21. Tags{ "RenderType" = "Opaque" "Queue" = "Transparent+0" }
  22. Cull Back
  23. GrabPass{ "RefractionGrab0" }
  24. CGINCLUDE
  25. #include "UnityShaderVariables.cginc"
  26. #include "UnityPBSLighting.cginc"
  27. #include "Lighting.cginc"
  28. #pragma target 3.0
  29. #ifdef UNITY_PASS_SHADOWCASTER
  30. #undef INTERNAL_DATA
  31. #undef WorldReflectionVector
  32. #undef WorldNormalVector
  33. #define INTERNAL_DATA half3 internalSurfaceTtoW0; half3 internalSurfaceTtoW1; half3 internalSurfaceTtoW2;
  34. #define WorldReflectionVector(data,normal) reflect (data.worldRefl, half3(dot(data.internalSurfaceTtoW0,normal), dot(data.internalSurfaceTtoW1,normal), dot(data.internalSurfaceTtoW2,normal)))
  35. #define WorldNormalVector(data,normal) fixed3(dot(data.internalSurfaceTtoW0,normal), dot(data.internalSurfaceTtoW1,normal), dot(data.internalSurfaceTtoW2,normal))
  36. #endif
  37. struct Input
  38. {
  39. float3 worldNormal;
  40. INTERNAL_DATA
  41. float3 worldPos;
  42. float2 uv_texcoord;
  43. float4 screenPos;
  44. };
  45. uniform float _Specular;
  46. uniform sampler2D _TextureSample3;
  47. uniform sampler2D _Foam;
  48. uniform float4 _Foam_ST;
  49. uniform float _SoapAmount;
  50. uniform float _Smoothness;
  51. uniform float _Opacity;
  52. uniform sampler2D RefractionGrab0;
  53. uniform float _ChromaticAberration;
  54. uniform float _IndexofRefraction;
  55. void vertexDataFunc( inout appdata_full v, out Input o )
  56. {
  57. UNITY_INITIALIZE_OUTPUT( Input, o );
  58. float3 temp_cast_0 = ( ( cos( ( ( 5.0 * v.vertex.y ) + _Time.y ) ) * 0.015 ) + ( sin( ( ( 5.0 * v.vertex.y ) + _Time.y ) ) * 0.005 ) );
  59. v.vertex.xyz += temp_cast_0;
  60. }
  61. inline float4 Refraction( Input i, SurfaceOutputStandardSpecular o, float indexOfRefraction, float chomaticAberration ) {
  62. float3 worldNormal = o.Normal;
  63. float4 screenPos = i.screenPos;
  64. #if UNITY_UV_STARTS_AT_TOP
  65. float scale = -1.0;
  66. #else
  67. float scale = 1.0;
  68. #endif
  69. float halfPosW = screenPos.w * 0.5;
  70. screenPos.y = ( screenPos.y - halfPosW ) * _ProjectionParams.x * scale + halfPosW;
  71. #if SHADER_API_D3D9 || SHADER_API_D3D11
  72. screenPos.w += 0.0000001;
  73. #endif
  74. float2 projScreenPos = ( screenPos / screenPos.w ).xy;
  75. float3 worldViewDir = normalize( UnityWorldSpaceViewDir( i.worldPos ) );
  76. float3 refractionOffset = ( ( ( ( indexOfRefraction - 1.0 ) * mul( UNITY_MATRIX_V, float4( worldNormal, 0.0 ) ) ) * ( 1.0 / ( screenPos.z + 1.0 ) ) ) * ( 1.0 - dot( worldNormal, worldViewDir ) ) );
  77. float2 cameraRefraction = float2( refractionOffset.x, -( refractionOffset.y * _ProjectionParams.x ) );
  78. float4 redAlpha = tex2D( RefractionGrab0, ( projScreenPos + cameraRefraction ) );
  79. float green = tex2D( RefractionGrab0, ( projScreenPos + ( cameraRefraction * ( 1.0 - chomaticAberration ) ) ) ).g;
  80. float blue = tex2D( RefractionGrab0, ( projScreenPos + ( cameraRefraction * ( 1.0 + chomaticAberration ) ) ) ).b;
  81. return float4( redAlpha.r, green, blue, redAlpha.a );
  82. }
  83. void RefractionF( Input i, SurfaceOutputStandardSpecular o, inout fixed4 color )
  84. {
  85. #ifdef UNITY_PASS_FORWARDBASE
  86. color.rgb = color.rgb + Refraction( i, o, _IndexofRefraction, _ChromaticAberration ) * ( 1 - color.a );
  87. color.a = 1;
  88. #endif
  89. }
  90. void surf( Input i , inout SurfaceOutputStandardSpecular o )
  91. {
  92. o.Normal = float3(0,0,1);
  93. float3 worldViewDir = normalize( UnityWorldSpaceViewDir( i.worldPos ) );
  94. float4 temp_cast_0 = _Specular;
  95. float2 uv_Foam = i.uv_texcoord * _Foam_ST.xy + _Foam_ST.zw;
  96. float2 temp_cast_1 = ( ( tex2D( _Foam,(abs( uv_Foam+(_SinTime.x*0.5 + 0.5) * float2(1,1 )))).r + ( abs( (uv_Foam.x*2.0 + -1.0) ) * 0.5 ) ) + _Time.x );
  97. o.Specular = ( ( 1.0 - saturate( ( pow( dot( WorldNormalVector( i, float3(0,0,1) ) , worldViewDir ) , 2.0 ) - 0.1 ) ) ) * lerp( temp_cast_0 , saturate( tex2D( _TextureSample3,temp_cast_1) ) , _SoapAmount ) ).xyz;
  98. o.Smoothness = _Smoothness;
  99. o.Alpha = _Opacity;
  100. o.Normal = o.Normal + 0.00001 * i.screenPos * i.worldPos;
  101. }
  102. ENDCG
  103. CGPROGRAM
  104. #pragma multi_compile _ALPHAPREMULTIPLY_ON
  105. #pragma surface surf StandardSpecular keepalpha finalcolor:RefractionF exclude_path:deferred vertex:vertexDataFunc
  106. ENDCG
  107. Pass
  108. {
  109. Name "ShadowCaster"
  110. Tags{ "LightMode" = "ShadowCaster" }
  111. ZWrite On
  112. CGPROGRAM
  113. #pragma vertex vert
  114. #pragma fragment frag
  115. #pragma target 3.0
  116. #pragma multi_compile_instancing
  117. #pragma multi_compile_shadowcaster
  118. #pragma multi_compile UNITY_PASS_SHADOWCASTER
  119. #pragma skip_variants FOG_LINEAR FOG_EXP FOG_EXP2
  120. # include "HLSLSupport.cginc"
  121. #if ( SHADER_API_D3D11 || SHADER_API_GLCORE || SHADER_API_GLES3 || SHADER_API_METAL || SHADER_API_VULKAN )
  122. #define CAN_SKIP_VPOS
  123. #endif
  124. #include "UnityCG.cginc"
  125. #include "Lighting.cginc"
  126. #include "UnityPBSLighting.cginc"
  127. sampler3D _DitherMaskLOD;
  128. struct v2f
  129. {
  130. V2F_SHADOW_CASTER;
  131. float3 worldPos : TEXCOORD6;
  132. float4 tSpace0 : TEXCOORD1;
  133. float4 tSpace1 : TEXCOORD2;
  134. float4 tSpace2 : TEXCOORD3;
  135. float4 texcoords01 : TEXCOORD4;
  136. UNITY_VERTEX_INPUT_INSTANCE_ID
  137. };
  138. v2f vert( appdata_full v )
  139. {
  140. v2f o;
  141. UNITY_SETUP_INSTANCE_ID( v );
  142. UNITY_INITIALIZE_OUTPUT( v2f, o );
  143. UNITY_TRANSFER_INSTANCE_ID( v, o );
  144. Input customInputData;
  145. vertexDataFunc( v, customInputData );
  146. float3 worldPos = mul( unity_ObjectToWorld, v.vertex ).xyz;
  147. half3 worldNormal = UnityObjectToWorldNormal( v.normal );
  148. fixed3 worldTangent = UnityObjectToWorldDir( v.tangent.xyz );
  149. fixed tangentSign = v.tangent.w * unity_WorldTransformParams.w;
  150. fixed3 worldBinormal = cross( worldNormal, worldTangent ) * tangentSign;
  151. o.tSpace0 = float4( worldTangent.x, worldBinormal.x, worldNormal.x, worldPos.x );
  152. o.tSpace1 = float4( worldTangent.y, worldBinormal.y, worldNormal.y, worldPos.y );
  153. o.tSpace2 = float4( worldTangent.z, worldBinormal.z, worldNormal.z, worldPos.z );
  154. o.texcoords01 = float4( v.texcoord.xy, v.texcoord1.xy );
  155. o.worldPos = worldPos;
  156. TRANSFER_SHADOW_CASTER_NORMALOFFSET( o )
  157. return o;
  158. }
  159. fixed4 frag( v2f IN
  160. #if !defined( CAN_SKIP_VPOS )
  161. , UNITY_VPOS_TYPE vpos : VPOS
  162. #endif
  163. ) : SV_Target
  164. {
  165. UNITY_SETUP_INSTANCE_ID( IN );
  166. Input surfIN;
  167. UNITY_INITIALIZE_OUTPUT( Input, surfIN );
  168. surfIN.uv_texcoord = IN.texcoords01.xy;
  169. float3 worldPos = float3( IN.tSpace0.w, IN.tSpace1.w, IN.tSpace2.w );
  170. fixed3 worldViewDir = normalize( UnityWorldSpaceViewDir( worldPos ) );
  171. surfIN.worldPos = worldPos;
  172. surfIN.worldNormal = float3( IN.tSpace0.z, IN.tSpace1.z, IN.tSpace2.z );
  173. surfIN.internalSurfaceTtoW0 = IN.tSpace0.xyz;
  174. surfIN.internalSurfaceTtoW1 = IN.tSpace1.xyz;
  175. surfIN.internalSurfaceTtoW2 = IN.tSpace2.xyz;
  176. SurfaceOutputStandardSpecular o;
  177. UNITY_INITIALIZE_OUTPUT( SurfaceOutputStandardSpecular, o )
  178. surf( surfIN, o );
  179. #if defined( CAN_SKIP_VPOS )
  180. float2 vpos = IN.pos;
  181. #endif
  182. half alphaRef = tex3D( _DitherMaskLOD, float3( vpos.xy * 0.25, o.Alpha * 0.9375 ) ).a;
  183. clip( alphaRef - 0.01 );
  184. SHADOW_CASTER_FRAGMENT( IN )
  185. }
  186. ENDCG
  187. }
  188. }
  189. Fallback "Diffuse"
  190. CustomEditor "ASEMaterialInspector"
  191. }
  192. /*ASEBEGIN
  193. Version=5005
  194. 1926;62;1067;610;1238.272;72.85294;3.435406;False;False
  195. Node;AmplifyShaderEditor.CommentaryNode;152;-912,192;Float;False;2577.155;665.7997;;24;157;156;155;150;135;151;142;140;153;81;146;132;121;131;116;164;113;171;179;175;181;180;184;185;Chromatic Specular Reflection
  196. Node;AmplifyShaderEditor.CommentaryNode;112;618.4003,1260.8;Float;False;1036;492;;10;106;97;103;105;102;109;104;110;107;111;Wobble
  197. Node;AmplifyShaderEditor.PosVertexDataNode;97;684.4003,1406.801;Float;False
  198. Node;AmplifyShaderEditor.TimeNode;103;668.4003,1550.801;Float;False
  199. Node;AmplifyShaderEditor.SimpleMultiplyOpNode;105;892.4003,1374.801;Float;False;0;FLOAT;0.0;False;1;FLOAT;0.0;False
  200. Node;AmplifyShaderEditor.SimpleAddOpNode;102;1020.399,1502.801;Float;False;0;FLOAT;0.0;False;1;FLOAT;0,0,0;False
  201. Node;AmplifyShaderEditor.CosOpNode;109;1180.399,1406.801;Float;False;0;FLOAT;0.0;False
  202. Node;AmplifyShaderEditor.SinOpNode;104;1180.399,1502.801;Float;False;0;FLOAT;0.0;False
  203. Node;AmplifyShaderEditor.SimpleMultiplyOpNode;110;1324.399,1406.801;Float;False;0;FLOAT;0.0;False;1;FLOAT;0.015;False
  204. Node;AmplifyShaderEditor.SimpleMultiplyOpNode;107;1324.399,1502.801;Float;False;0;FLOAT;0.0;False;1;FLOAT;0.005;False
  205. Node;AmplifyShaderEditor.SimpleAddOpNode;111;1500.399,1454.801;Float;False;0;FLOAT;0.0;False;1;FLOAT;0.0;False
  206. Node;AmplifyShaderEditor.RangedFloatNode;115;1408,896;Float;False;Property;_Smoothness;Smoothness;5;0;0.8;0;1
  207. Node;AmplifyShaderEditor.RangedFloatNode;41;1408,992;Float;False;Property;_IndexofRefraction;Index of Refraction;4;0;1;-3;4
  208. Node;AmplifyShaderEditor.RangedFloatNode;42;1408,1088;Float;False;Property;_Opacity;Opacity;3;0;0;0;1
  209. Node;AmplifyShaderEditor.SamplerNode;116;-32,240;Float;True;Property;_Foam;Foam;5;0;None;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;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
  210. Node;AmplifyShaderEditor.SinTimeNode;132;-608,384;Float;False
  211. Node;AmplifyShaderEditor.ScaleAndOffsetNode;146;-448,384;Float;False;0;FLOAT;0.0;False;1;FLOAT;0.5;False;2;FLOAT;0.5;False
  212. Node;AmplifyShaderEditor.SimpleMultiplyOpNode;153;-112,592;Float;True;0;FLOAT;0.0;False;1;FLOAT;0.5;False
  213. Node;AmplifyShaderEditor.AbsOpNode;140;-336,592;Float;True;0;FLOAT;0.0;False
  214. Node;AmplifyShaderEditor.ScaleAndOffsetNode;142;-624,592;Float;True;0;FLOAT;0.0;False;1;FLOAT;2.0;False;2;FLOAT;-1.0;False
  215. Node;AmplifyShaderEditor.SimpleAddOpNode;135;288,368;Float;False;0;FLOAT;0.0;False;1;FLOAT;1.32,0,0,0;False
  216. Node;AmplifyShaderEditor.RangedFloatNode;106;668.4003,1310.8;Float;False;Constant;_DeformFrequency;Deform Frequency;8;0;5;0;0
  217. Node;AmplifyShaderEditor.PannerNode;131;-224,256;Float;False;1;1;0;FLOAT2;0,0;False;1;FLOAT;0.0;False
  218. Node;AmplifyShaderEditor.SimpleAddOpNode;150;512,608;Float;False;0;FLOAT;0.0;False;1;FLOAT;0.0;False
  219. Node;AmplifyShaderEditor.TimeNode;151;240,624;Float;False
  220. Node;AmplifyShaderEditor.StandardSurfaceOutputNode;0;1856,832;Float;False;True;2;Float;ASEMaterialInspector;StandardSpecular;ASESampleShaders/ReflectRefractSoapBubble;False;False;False;False;False;False;False;False;False;False;False;False;Back;0;3;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;0;FLOAT3;0,0,0;False;1;FLOAT3;0,0,0;False;2;FLOAT3;0,0,0;False;3;FLOAT3;0,0,0;False;4;FLOAT;0.0;False;5;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.0;False;11;FLOAT3;0,0,0;False;12;FLOAT3;0,0,0;False;13;OBJECT;0.0;False;14;FLOAT4;0,0,0,0;False;15;FLOAT3;0,0,0;False
  221. Node;AmplifyShaderEditor.TextureCoordinatesNode;121;-864,256;Float;True;0;116;2;0;FLOAT2;1,1;False;1;FLOAT2;0,0;False
  222. Node;AmplifyShaderEditor.ViewDirInputsCoordNode;156;480,400;Float;False;World
  223. Node;AmplifyShaderEditor.WorldNormalVector;155;432,256;Float;False;0;FLOAT3;0,0,0;False
  224. Node;AmplifyShaderEditor.DotProductOpNode;157;640,320;Float;False;0;FLOAT3;0.0;False;1;FLOAT3;0,0,0;False
  225. Node;AmplifyShaderEditor.SaturateNode;171;1072,320;Float;False;0;FLOAT;0.0;False
  226. Node;AmplifyShaderEditor.OneMinusNode;180;1216,320;Float;False;0;FLOAT;0.0;False
  227. Node;AmplifyShaderEditor.PowerNode;175;768,320;Float;False;0;FLOAT;0.0;False;1;FLOAT;2.0;False
  228. Node;AmplifyShaderEditor.SimpleSubtractOpNode;181;928,320;Float;False;0;FLOAT;0.0;False;1;FLOAT;0.1;False
  229. Node;AmplifyShaderEditor.SimpleMultiplyOpNode;179;1440,384;Float;True;0;FLOAT;0.0;False;1;FLOAT4;0.0;False
  230. Node;AmplifyShaderEditor.LerpOp;184;1248,464;Float;False;0;FLOAT;0,0,0,0;False;1;FLOAT4;0.0;False;2;FLOAT;0.0;False
  231. Node;AmplifyShaderEditor.SaturateNode;185;1056,464;Float;False;0;FLOAT4;0.0;False
  232. Node;AmplifyShaderEditor.RangedFloatNode;113;720,768;Float;False;Property;_Specular;Specular;4;0;0;0;1
  233. Node;AmplifyShaderEditor.RangedFloatNode;164;720,672;Float;False;Property;_SoapAmount;Soap Amount;4;0;0;0;1
  234. Node;AmplifyShaderEditor.SamplerNode;81;720,448;Float;True;Property;_TextureSample3;Texture Sample 3;7;0;None;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;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
  235. WireConnection;105;0;106;0
  236. WireConnection;105;1;97;2
  237. WireConnection;102;0;105;0
  238. WireConnection;102;1;103;2
  239. WireConnection;109;0;102;0
  240. WireConnection;104;0;102;0
  241. WireConnection;110;0;109;0
  242. WireConnection;107;0;104;0
  243. WireConnection;111;0;110;0
  244. WireConnection;111;1;107;0
  245. WireConnection;116;1;131;0
  246. WireConnection;146;0;132;1
  247. WireConnection;153;0;140;0
  248. WireConnection;140;0;142;0
  249. WireConnection;142;0;121;1
  250. WireConnection;135;0;116;1
  251. WireConnection;135;1;153;0
  252. WireConnection;131;0;121;0
  253. WireConnection;131;1;146;0
  254. WireConnection;150;0;135;0
  255. WireConnection;150;1;151;1
  256. WireConnection;0;3;179;0
  257. WireConnection;0;4;115;0
  258. WireConnection;0;8;41;0
  259. WireConnection;0;9;42;0
  260. WireConnection;0;11;111;0
  261. WireConnection;157;0;155;0
  262. WireConnection;157;1;156;0
  263. WireConnection;171;0;181;0
  264. WireConnection;180;0;171;0
  265. WireConnection;175;0;157;0
  266. WireConnection;181;0;175;0
  267. WireConnection;179;0;180;0
  268. WireConnection;179;1;184;0
  269. WireConnection;184;0;113;0
  270. WireConnection;184;1;185;0
  271. WireConnection;184;2;164;0
  272. WireConnection;185;0;81;0
  273. WireConnection;81;1;150;0
  274. ASEEND*/
  275. //CHKSM=540670CE8DB5C674C8EF8A5C4884C681FF275FA1