Advertisement
Edwarddv

Screenspace locked to world position

Oct 2nd, 2018
1,247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "EdShaders/ScreenWorldSpace"
  2. {
  3.     Properties
  4.     {
  5.         _ScreenSpaceTexture("ScreenSpaceTexture", 2D) = "white" {}
  6.         _TexScale("Tex Scale", Float) = 0
  7.         [HideInInspector] __dirty( "", Int ) = 1
  8.     }
  9.  
  10.     SubShader
  11.     {
  12.         Tags{ "RenderType" = "Transparent"  "Queue" = "Geometry+0" "IsEmissive" = "true"  }
  13.         Cull Back
  14.         Blend SrcAlpha OneMinusSrcAlpha
  15.        
  16.         CGPROGRAM
  17.         #include "UnityCG.cginc"
  18.         #include "UnityShaderVariables.cginc"
  19.         #pragma target 3.0
  20.         #pragma surface surf Standard keepalpha addshadow fullforwardshadows
  21.         struct Input
  22.         {
  23.             float3 worldPos;
  24.         };
  25.  
  26.         uniform sampler2D _ScreenSpaceTexture;
  27.         uniform float _TexScale;
  28.  
  29.         void surf( Input i , inout SurfaceOutputStandard o )
  30.         {
  31.             float3 ase_vertex3Pos = mul( unity_WorldToObject, float4( i.worldPos , 1 ) );
  32.             float4 unityObjectToClipPos164 = UnityObjectToClipPos( ase_vertex3Pos );
  33.             float4 computeScreenPos162 = ComputeScreenPos( unityObjectToClipPos164 );
  34.             float4 unityObjectToClipPos170 = UnityObjectToClipPos( float3(0,0,0) );
  35.             float4 computeScreenPos171 = ComputeScreenPos( unityObjectToClipPos170 );
  36.             float4 transform182 = mul(unity_ObjectToWorld,float4( 0,0,0,1 ));
  37.             o.Emission = tex2D( _ScreenSpaceTexture, ( ( ( ( computeScreenPos162 / (computeScreenPos162).w ) * _TexScale ) - ( ( computeScreenPos171 / (computeScreenPos171).w ) * _TexScale ) ) * distance( ( float4( _WorldSpaceCameraPos , 0.0 ) - transform182 ) , float4( 0,0,0,0 ) ) ).xy ).rgb;
  38.             o.Alpha = 1;
  39.         }
  40.  
  41.         ENDCG
  42.     }
  43.     Fallback "Diffuse"
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement