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.

173 lines
7.9 KiB

  1. // Made with Amplify Shader Editor
  2. // Available at the Unity Asset Store - http://u3d.as/y3X
  3. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  4. Shader "Hidden/PostProcess/Pixelize/ScreenAndMask"
  5. {
  6. Properties
  7. {
  8. _MainTex ( "Screen", 2D ) = "black" {}
  9. }
  10. SubShader
  11. {
  12. ZTest Always
  13. Cull Off
  14. ZWrite Off
  15. Pass
  16. {
  17. CGPROGRAM
  18. #pragma vertex vert_img_custom
  19. #pragma fragment frag
  20. #pragma target 3.0
  21. #include "UnityCG.cginc"
  22. #include "UnityShaderVariables.cginc"
  23. struct appdata_img_custom
  24. {
  25. float4 vertex : POSITION;
  26. half2 texcoord : TEXCOORD0;
  27. };
  28. struct v2f_img_custom
  29. {
  30. float4 pos : SV_POSITION;
  31. half2 uv : TEXCOORD0;
  32. half2 stereoUV : TEXCOORD2;
  33. #if UNITY_UV_STARTS_AT_TOP
  34. half4 uv2 : TEXCOORD1;
  35. half4 stereoUV2 : TEXCOORD3;
  36. #endif
  37. float4 ase_texcoord4 : TEXCOORD4;
  38. };
  39. uniform sampler2D _MainTex;
  40. uniform half4 _MainTex_TexelSize;
  41. uniform half4 _MainTex_ST;
  42. uniform float3 _SpherePosition;
  43. uniform sampler2D _CameraDepthTexture;
  44. uniform float _SphereRadius;
  45. uniform float _MaskDensity;
  46. uniform float _MaskExponent;
  47. v2f_img_custom vert_img_custom ( appdata_img_custom v )
  48. {
  49. v2f_img_custom o;
  50. float4 ase_clipPos = UnityObjectToClipPos(v.vertex);
  51. float4 screenPos = ComputeScreenPos(ase_clipPos);
  52. o.ase_texcoord4 = screenPos;
  53. o.pos = UnityObjectToClipPos ( v.vertex );
  54. o.uv = float4( v.texcoord.xy, 1, 1 );
  55. #if UNITY_UV_STARTS_AT_TOP
  56. o.uv2 = float4( v.texcoord.xy, 1, 1 );
  57. o.stereoUV2 = UnityStereoScreenSpaceUVAdjust ( o.uv2, _MainTex_ST );
  58. if ( _MainTex_TexelSize.y < 0.0 )
  59. o.uv.y = 1.0 - o.uv.y;
  60. #endif
  61. o.stereoUV = UnityStereoScreenSpaceUVAdjust ( o.uv, _MainTex_ST );
  62. return o;
  63. }
  64. half4 frag ( v2f_img_custom i ) : SV_Target
  65. {
  66. #ifdef UNITY_UV_STARTS_AT_TOP
  67. half2 uv = i.uv2;
  68. half2 stereoUV = i.stereoUV2;
  69. #else
  70. half2 uv = i.uv;
  71. half2 stereoUV = i.stereoUV;
  72. #endif
  73. half4 finalColor;
  74. // ase common template code
  75. float3 CamPosition11_g2 = _WorldSpaceCameraPos;
  76. float3 SphereCenter4_g2 = _SpherePosition;
  77. float3 SphereToCam17_g2 = ( CamPosition11_g2 - SphereCenter4_g2 );
  78. float4 screenPos = i.ase_texcoord4;
  79. float4 ase_screenPosNorm = screenPos / screenPos.w;
  80. ase_screenPosNorm.z = ( UNITY_NEAR_CLIP_VALUE >= 0 ) ? ase_screenPosNorm.z : ase_screenPosNorm.z * 0.5 + 0.5;
  81. float4 tex2DNode36_g1 = tex2D( _CameraDepthTexture, ase_screenPosNorm.xy );
  82. #ifdef UNITY_REVERSED_Z
  83. float4 staticSwitch38_g1 = ( 1.0 - tex2DNode36_g1 );
  84. #else
  85. float4 staticSwitch38_g1 = tex2DNode36_g1;
  86. #endif
  87. float3 appendResult39_g1 = (float3(ase_screenPosNorm.x , ase_screenPosNorm.y , staticSwitch38_g1.r));
  88. float4 appendResult42_g1 = (float4((appendResult39_g1*2.0 + -1.0) , 1.0));
  89. float4 temp_output_43_0_g1 = mul( unity_CameraInvProjection, appendResult42_g1 );
  90. float4 appendResult49_g1 = (float4(( ( (temp_output_43_0_g1).xyz / (temp_output_43_0_g1).w ) * float3( 1,1,-1 ) ) , 1.0));
  91. float3 WorldPosition122_g2 = mul( unity_CameraToWorld, appendResult49_g1 ).xyz;
  92. float3 temp_output_9_0_g2 = ( _WorldSpaceCameraPos - WorldPosition122_g2 );
  93. float3 normalizeResult10_g2 = normalize( temp_output_9_0_g2 );
  94. float3 ViewDirection12_g2 = normalizeResult10_g2;
  95. float dotResult20_g2 = dot( SphereToCam17_g2 , ViewDirection12_g2 );
  96. float DirectionsSimilarity21_g2 = dotResult20_g2;
  97. float dotResult24_g2 = dot( SphereToCam17_g2 , SphereToCam17_g2 );
  98. float SphereRadius5_g2 = _SphereRadius;
  99. float Ratio25_g2 = ( ( DirectionsSimilarity21_g2 * DirectionsSimilarity21_g2 ) - ( dotResult24_g2 - ( SphereRadius5_g2 * SphereRadius5_g2 ) ) );
  100. float SqrtRatio37_g2 = sqrt( Ratio25_g2 );
  101. float temp_output_40_0_g2 = ( SqrtRatio37_g2 + -DirectionsSimilarity21_g2 );
  102. float DistanceToPixel114_g2 = -length( temp_output_9_0_g2 );
  103. float RejectionValue162_g2 = (( temp_output_40_0_g2 < DistanceToPixel114_g2 ) ? -1.0 : Ratio25_g2 );
  104. float temp_output_41_0_g2 = ( -DirectionsSimilarity21_g2 - SqrtRatio37_g2 );
  105. float3 ExitPoint44_g2 = ( CamPosition11_g2 + ( ViewDirection12_g2 * max( temp_output_41_0_g2 , DistanceToPixel114_g2 ) ) );
  106. float DistanceToEntryPoint139_g2 = temp_output_40_0_g2;
  107. float3 EntryPoint45_g2 = ( ( DistanceToEntryPoint139_g2 * ViewDirection12_g2 ) + CamPosition11_g2 );
  108. float temp_output_170_0_g2 = ( 1.0 - ( distance( SphereCenter4_g2 , ( ( ExitPoint44_g2 + EntryPoint45_g2 ) * float3( 0.5,0.5,0.5 ) ) ) / SphereRadius5_g2 ) );
  109. float LinearDensity173_g2 = temp_output_170_0_g2;
  110. float4 appendResult136 = (float4(tex2D( _MainTex, i.uv.xy ).rgb , pow( ( (( RejectionValue162_g2 < 0.0 ) ? 0.0 : LinearDensity173_g2 ) * _MaskDensity ) , _MaskExponent )));
  111. finalColor = appendResult136;
  112. return finalColor;
  113. }
  114. ENDCG
  115. }
  116. }
  117. CustomEditor "ASEMaterialInspector"
  118. }
  119. /*ASEBEGIN
  120. Version=16304
  121. 1722;92;1161;923;-154.8722;649.91;1.449605;True;False
  122. Node;AmplifyShaderEditor.Vector3Node;4;380.8583,44.91288;Float;False;Global;_SpherePosition;_SpherePosition;7;0;Create;True;0;0;False;0;0,0,0;0,1.5,0;0;4;FLOAT3;0;FLOAT;1;FLOAT;2;FLOAT;3
  123. Node;AmplifyShaderEditor.RangedFloatNode;10;379.863,211.7047;Float;False;Global;_SphereRadius;_SphereRadius;2;0;Create;True;0;0;False;0;1;6;0;0;0;1;FLOAT;0
  124. Node;AmplifyShaderEditor.FunctionNode;140;220.753,-42.58594;Float;False;Reconstruct World Position From Depth;0;;1;e7094bcbcc80eb140b2a3dbe6a861de8;0;0;1;FLOAT4;0
  125. Node;AmplifyShaderEditor.RangedFloatNode;8;993.168,198.614;Float;False;Global;_MaskDensity;_MaskDensity;2;0;Create;True;0;0;False;0;1;4.9;0;3;0;1;FLOAT;0
  126. Node;AmplifyShaderEditor.FunctionNode;141;724.8454,-38.27131;Float;False;Compute Volumetric Sphere;-1;;2;21b394060dee4e24d99ea8f6db991160;2,164,1,154,1;3;3;FLOAT3;0,0,0;False;1;FLOAT3;0,0,0;False;2;FLOAT;1;False;7;FLOAT;97;FLOAT;178;FLOAT;88;FLOAT;0;FLOAT3;68;FLOAT3;75;INT;53
  127. Node;AmplifyShaderEditor.SimpleMultiplyOpNode;9;1362.593,152.5419;Float;False;2;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
  128. Node;AmplifyShaderEditor.RangedFloatNode;137;1240.171,296.0089;Float;False;Global;_MaskExponent;_MaskExponent;2;0;Create;True;0;0;False;0;3;3;0.2;5;0;1;FLOAT;0
  129. Node;AmplifyShaderEditor.TemplateShaderPropertyNode;131;752.8643,-365.0398;Float;False;0;0;_MainTex;Shader;0;5;SAMPLER2D;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  130. Node;AmplifyShaderEditor.TexCoordVertexDataNode;1;673.2322,-285.6174;Float;False;0;2;0;5;FLOAT2;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  131. Node;AmplifyShaderEditor.PowerNode;139;1581.171,162.0089;Float;False;2;0;FLOAT;0;False;1;FLOAT;1;False;1;FLOAT;0
  132. Node;AmplifyShaderEditor.SamplerNode;132;937.8646,-362.0398;Float;True;Property;_TextureSample0;Texture Sample 0;4;0;Create;True;0;0;False;0;None;None;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;6;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;0;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  133. Node;AmplifyShaderEditor.DynamicAppendNode;136;1872.132,-94.7847;Float;False;FLOAT4;4;0;FLOAT3;0,0,0;False;1;FLOAT;0;False;2;FLOAT;0;False;3;FLOAT;0;False;1;FLOAT4;0
  134. Node;AmplifyShaderEditor.TemplateMultiPassMasterNode;0;2109.486,-96.0928;Float;False;True;2;Float;ASEMaterialInspector;0;2;Hidden/PostProcess/Pixelize/ScreenAndMask;c71b220b631b6344493ea3cf87110c93;True;SubShader 0 Pass 0;0;0;SubShader 0 Pass 0;1;False;False;False;True;2;False;-1;False;False;True;2;False;-1;True;7;False;-1;False;True;0;False;0;False;False;False;False;False;False;False;False;False;False;True;2;0;;0;0;Standard;0;0;1;True;False;1;0;FLOAT4;0,0,0,0;False;0
  135. WireConnection;141;3;140;0
  136. WireConnection;141;1;4;0
  137. WireConnection;141;2;10;0
  138. WireConnection;9;0;141;97
  139. WireConnection;9;1;8;0
  140. WireConnection;139;0;9;0
  141. WireConnection;139;1;137;0
  142. WireConnection;132;0;131;0
  143. WireConnection;132;1;1;0
  144. WireConnection;136;0;132;0
  145. WireConnection;136;3;139;0
  146. WireConnection;0;0;136;0
  147. ASEEND*/
  148. //CHKSM=6B2FEFF5038291CDD78AE92807ECD78FC43BB37D