Grizmu

Unity ViewSpaceFloor Shader

Jul 15th, 2025
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PowerShell 10.18 KB | Source Code | 0 0
  1. // Made with Amplify Shader Editor v1.9.1.2
  2. // Available at the Unity Asset Store - http://u3d.as/y3X
  3. Shader "ViewSpaceFloor"
  4. {
  5.     Properties
  6.     {
  7.         _Texture0("Texture 0", 2D) = "white" {}
  8.         _ScreenOffset("ScreenOffset", Vector) = (0,0,0,0)
  9.         _Scale("Scale", Vector) = (1,1,0,0)
  10.         _Tint("Tint", Color) = (1,1,1,1)
  11.         _VertexStartOffset("VertexStartOffset", Vector) = (0,0,0,0)
  12.         _VertexScale("VertexScale", Vector) = (0,0,0,0)
  13.         _Range("Range", Float) = 0.05
  14.         _TargetPosition("TargetPosition", Float) = 0
  15.         [HideInInspector] __dirty( "", Int ) = 1
  16.     }
  17.  
  18.     SubShader
  19.     {
  20.         Tags{ "RenderType" = "Opaque"  "Queue" = "Geometry+0" }
  21.         Cull Back
  22.         CGPROGRAM
  23.         #include "UnityPBSLighting.cginc"
  24.         #include "UnityShaderVariables.cginc"
  25.         #pragma target 3.0
  26.         #pragma surface surf StandardCustomLighting keepalpha addshadow fullforwardshadows
  27.         struct Input
  28.         {
  29.             float4 screenPos;
  30.             float3 worldPos;
  31.         };
  32.  
  33.         struct SurfaceOutputCustomLightingCustom
  34.         {
  35.             half3 Albedo;
  36.             half3 Normal;
  37.             half3 Emission;
  38.             half Metallic;
  39.             half Smoothness;
  40.             half Occlusion;
  41.             half Alpha;
  42.             Input SurfInput;
  43.             UnityGIInput GIData;
  44.         };
  45.  
  46.         uniform sampler2D _Texture0;
  47.         uniform float2 _Scale;
  48.         uniform float2 _ScreenOffset;
  49.         uniform float3 _VertexScale;
  50.         uniform float _TargetPosition;
  51.         uniform float _Range;
  52.         uniform float3 _VertexStartOffset;
  53.         uniform float4 _Tint;
  54.  
  55.         inline half4 LightingStandardCustomLighting( inout SurfaceOutputCustomLightingCustom s, half3 viewDir, UnityGI gi )
  56.         {
  57.             UnityGIInput data = s.GIData;
  58.             Input i = s.SurfInput;
  59.             half4 c = 0;
  60.             #ifdef UNITY_PASS_FORWARDBASE
  61.             float ase_lightAtten = data.atten;
  62.             if( _LightColor0.a == 0)
  63.             ase_lightAtten = 0;
  64.             #else
  65.             float3 ase_lightAttenRGB = gi.light.color / ( ( _LightColor0.rgb ) + 0.000001 );
  66.             float ase_lightAtten = max( max( ase_lightAttenRGB.r, ase_lightAttenRGB.g ), ase_lightAttenRGB.b );
  67.             #endif
  68.             #if defined(HANDLE_SHADOWS_BLENDING_IN_GI)
  69.             half bakedAtten = UnitySampleBakedOcclusion(data.lightmapUV.xy, data.worldPos);
  70.             float zDist = dot(_WorldSpaceCameraPos - data.worldPos, UNITY_MATRIX_V[2].xyz);
  71.             float fadeDist = UnityComputeShadowFadeDistance(data.worldPos, zDist);
  72.             ase_lightAtten = UnityMixRealtimeAndBakedShadows(data.atten, bakedAtten, UnityComputeShadowFade(fadeDist));
  73.             #endif
  74.             float4 ase_screenPos = float4( i.screenPos.xyz , i.screenPos.w + 0.00000000001 );
  75.             float4 ase_screenPosNorm = ase_screenPos / ase_screenPos.w;
  76.             ase_screenPosNorm.z = ( UNITY_NEAR_CLIP_VALUE >= 0 ) ? ase_screenPosNorm.z : ase_screenPosNorm.z * 0.5 + 0.5;
  77.             float clampResult83 = clamp( ( ( _TargetPosition - ase_screenPosNorm.y ) / _Range ) , 0.0 , 1.0 );
  78.             float4 appendResult88 = (float4(_VertexScale.x , ( _VertexScale.y * clampResult83 ) , _VertexScale.z , 0.0));
  79.             float3 ase_vertex3Pos = mul( unity_WorldToObject, float4( i.worldPos , 1 ) );
  80.             c.rgb = ( ( tex2D( _Texture0, ( ( ( ase_screenPosNorm * float4( _Scale, 0.0 , 0.0 ) ) + float4( _ScreenOffset, 0.0 , 0.0 ) ) + ( appendResult88 * float4( ( ase_vertex3Pos + _VertexStartOffset ) , 0.0 ) ) ).xy ) * _Tint ) * ase_lightAtten ).rgb;
  81.             c.a = 1;
  82.             return c;
  83.         }
  84.  
  85.         inline void LightingStandardCustomLighting_GI( inout SurfaceOutputCustomLightingCustom s, UnityGIInput data, inout UnityGI gi )
  86.         {
  87.             s.GIData = data;
  88.         }
  89.  
  90.         void surf( Input i , inout SurfaceOutputCustomLightingCustom o )
  91.         {
  92.             o.SurfInput = i;
  93.         }
  94.  
  95.         ENDCG
  96.     }
  97.     Fallback "Diffuse"
  98.     CustomEditor "ASEMaterialInspector"
  99. }
  100. /*ASEBEGIN
  101. Version=19102
  102. Node;AmplifyShaderEditor.CommentaryNode;98;-985.8995,-135.2;Inherit;False;613.4502;425.1021;XY View Space scaling and offseting, to fit the render with the background texture;5;5;6;8;9;4;;1,1,1,1;0;0
  103. Node;AmplifyShaderEditor.CommentaryNode;97;-1483.371,316.1996;Inherit;False;1278.052;677.4745;Y View Space - with a height clamp where we want the distortion effect to end;4;16;86;93;94;;1,1,1,1;0;0
  104. Node;AmplifyShaderEditor.CommentaryNode;96;53.70387,245.4827;Inherit;False;363.6272;260.347;This allows shadows to work;2;92;90;;1,1,1,1;0;0
  105. Node;AmplifyShaderEditor.CommentaryNode;94;-835.142,662.4852;Inherit;False;368.3609;330.7082;Mesh Vertex Offset;3;13;12;40;;1,1,1,1;0;0
  106. Node;AmplifyShaderEditor.CommentaryNode;93;-999.3121,359.6997;Inherit;False;461.5712;285.72;Scaling;3;18;88;87;;1,1,1,1;0;0
  107. Node;AmplifyShaderEditor.CommentaryNode;86;-1476.271,654.1996;Inherit;False;615.27;294.1062;Vertial positioning;6;80;79;81;83;84;85;;1,1,1,1;0;0
  108. Node;AmplifyShaderEditor.SimpleMultiplyOpNode;87;-823.3145,551.6996;Inherit;False;2;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
  109. Node;AmplifyShaderEditor.DynamicAppendNode;88;-663.3145,423.6997;Inherit;False;FLOAT4;4;0;FLOAT;0;False;1;FLOAT;0;False;2;FLOAT;0;False;3;FLOAT;0;False;1;FLOAT4;0
  110. Node;AmplifyShaderEditor.SimpleDivideOpNode;85;-1127.312,718.1996;Inherit;False;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
  111. Node;AmplifyShaderEditor.SimpleSubtractOpNode;84;-1255.312,702.1996;Inherit;False;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
  112. Node;AmplifyShaderEditor.SimpleAddOpNode;40;-577.7234,726.3027;Inherit;False;2;2;0;FLOAT3;0,0,0;False;1;FLOAT3;0,0,0;False;1;FLOAT3;0
  113. Node;AmplifyShaderEditor.PosVertexDataNode;12;-796.584,712.4852;Inherit;False;0;0;5;FLOAT3;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  114. Node;AmplifyShaderEditor.Vector3Node;13;-807.2419,850.7735;Inherit;False;Property;_VertexStartOffset;VertexStartOffset;4;0;Create;True;0;0;0;False;0;False;0,0,0;0,2.4,0;0;4;FLOAT3;0;FLOAT;1;FLOAT;2;FLOAT;3
  115. Node;AmplifyShaderEditor.ClampOpNode;83;-999.3121,702.1996;Inherit;False;3;0;FLOAT;0;False;1;FLOAT;0;False;2;FLOAT;1;False;1;FLOAT;0
  116. Node;AmplifyShaderEditor.LightAttenuation;90;66.00387,430.7693;Inherit;False;0;1;FLOAT;0
  117. Node;AmplifyShaderEditor.Vector3Node;18;-994.1121,405.0997;Inherit;False;Property;_VertexScale;VertexScale;5;0;Create;True;0;0;0;False;0;False;0,0,0;0,-0.05,0;0;4;FLOAT3;0;FLOAT;1;FLOAT;2;FLOAT;3
  118. Node;AmplifyShaderEditor.ScreenPosInputsNode;4;-935.8995,-85.20001;Float;False;0;False;0;5;FLOAT4;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  119. Node;AmplifyShaderEditor.SimpleMultiplyOpNode;9;-695.8995,58.8;Inherit;False;2;2;0;FLOAT4;0,0,0,0;False;1;FLOAT2;0,0;False;1;FLOAT4;0
  120. Node;AmplifyShaderEditor.Vector2Node;8;-932.785,86.91755;Inherit;False;Property;_Scale;Scale;2;0;Create;True;0;0;0;False;0;False;1,1;0.9535,0.916;0;3;FLOAT2;0;FLOAT;1;FLOAT;2
  121. Node;AmplifyShaderEditor.SimpleAddOpNode;6;-510.7396,74.55874;Inherit;False;2;2;0;FLOAT4;0,0,0,0;False;1;FLOAT2;0,0;False;1;FLOAT4;0
  122. Node;AmplifyShaderEditor.Vector2Node;5;-698.7629,171.3221;Inherit;False;Property;_ScreenOffset;ScreenOffset;1;0;Create;True;0;0;0;False;0;False;0,0;0.0234,0.065;0;3;FLOAT2;0;FLOAT;1;FLOAT;2
  123. Node;AmplifyShaderEditor.SimpleMultiplyOpNode;92;286.3511,290.2823;Inherit;False;2;2;0;COLOR;0,0,0,0;False;1;FLOAT;0;False;1;COLOR;0
  124. Node;AmplifyShaderEditor.TexturePropertyNode;1;-367.2188,-128.7771;Inherit;True;Property;_Texture0;Texture 0;0;0;Create;True;0;0;0;False;0;False;None;983d44bd067c45f439d18542afe67d47;False;white;Auto;Texture2D;-1;0;2;SAMPLER2D;0;SAMPLERSTATE;1
  125. Node;AmplifyShaderEditor.SamplerNode;2;-137.266,-127.3966;Inherit;True;Property;_TextureSample0;Texture Sample 0;1;0;Create;True;0;0;0;False;0;False;-1;None;None;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;8;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;6;FLOAT;0;False;7;SAMPLERSTATE;;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  126. Node;AmplifyShaderEditor.ColorNode;10;-69.27036,62.85463;Inherit;False;Property;_Tint;Tint;3;0;Create;True;0;0;0;False;0;False;1,1,1,1;1,1,1,0;True;0;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  127. Node;AmplifyShaderEditor.SimpleMultiplyOpNode;11;178.3978,81.24503;Inherit;False;2;2;0;COLOR;0,0,0,0;False;1;COLOR;0,0,0,0;False;1;COLOR;0
  128. Node;AmplifyShaderEditor.StandardSurfaceOutputNode;0;454.1351,-113.4529;Float;False;True;-1;2;ASEMaterialInspector;0;0;CustomLighting;ViewSpaceFloor;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;Back;0;False;;0;False;;False;0;False;;0;False;;False;0;Opaque;0.5;True;True;0;False;Opaque;;Geometry;All;12;all;True;True;True;True;0;False;;False;0;False;;255;False;;255;False;;0;False;;0;False;;0;False;;0;False;;0;False;;0;False;;0;False;;0;False;;False;2;15;10;25;False;0.5;True;0;0;False;;3;False;;0;0;False;;0;False;;0;False;;0;False;;0;False;0;0,0,0,0;VertexOffset;True;False;Cylindrical;False;True;Relative;0;;-1;-1;-1;-1;0;False;0;0;False;;-1;0;False;;0;0;0;False;0.1;False;;0;False;;False;15;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;False;6;FLOAT3;0,0,0;False;7;FLOAT3;0,0,0;False;8;FLOAT;0;False;9;FLOAT;0;False;10;FLOAT;0;False;13;FLOAT3;0,0,0;False;11;FLOAT3;0,0,0;False;12;FLOAT3;0,0,0;False;14;FLOAT4;0,0,0,0;False;15;FLOAT3;0,0,0;False;0
  129. Node;AmplifyShaderEditor.SimpleAddOpNode;17;-195.186,252.4631;Inherit;False;2;2;0;FLOAT4;0,0,0,0;False;1;FLOAT4;0,0,0,0;False;1;FLOAT4;0
  130. Node;AmplifyShaderEditor.RangedFloatNode;81;-1445.448,700.8519;Inherit;False;Property;_TargetPosition;TargetPosition;7;0;Create;True;0;0;0;False;0;False;0;0.13;0;0;0;1;FLOAT;0
  131. Node;AmplifyShaderEditor.RangedFloatNode;80;-1261.878,839.6336;Inherit;False;Property;_Range;Range;6;0;Create;True;0;0;0;False;0;False;0.05;0.1;0;0;0;1;FLOAT;0
  132. Node;AmplifyShaderEditor.SimpleMultiplyOpNode;16;-435.5105,499.9633;Inherit;True;2;2;0;FLOAT4;0,0,0,0;False;1;FLOAT3;0,0,0;False;1;FLOAT4;0
  133. Node;AmplifyShaderEditor.ScreenPosInputsNode;79;-1465.663,783.5473;Float;False;0;False;0;5;FLOAT4;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  134. WireConnection;87;0;18;2
  135. WireConnection;87;1;83;0
  136. WireConnection;88;0;18;1
  137. WireConnection;88;1;87;0
  138. WireConnection;88;2;18;3
  139. WireConnection;85;0;84;0
  140. WireConnection;85;1;80;0
  141. WireConnection;84;0;81;0
  142. WireConnection;84;1;79;2
  143. WireConnection;40;0;12;0
  144. WireConnection;40;1;13;0
  145. WireConnection;83;0;85;0
  146. WireConnection;9;0;4;0
  147. WireConnection;9;1;8;0
  148. WireConnection;6;0;9;0
  149. WireConnection;6;1;5;0
  150. WireConnection;92;0;11;0
  151. WireConnection;92;1;90;0
  152. WireConnection;2;0;1;0
  153. WireConnection;2;1;17;0
  154. WireConnection;11;0;2;0
  155. WireConnection;11;1;10;0
  156. WireConnection;0;13;92;0
  157. WireConnection;17;0;6;0
  158. WireConnection;17;1;16;0
  159. WireConnection;16;0;88;0
  160. WireConnection;16;1;40;0
  161. ASEEND*/
  162. //CHKSM=5864C468B0D127EDCDBFAE96590D4A84141602F3
Tags: Unity
Advertisement
Add Comment
Please, Sign In to add comment