Guest User

HoloSight.shader

a guest
Mar 14th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/HoloSight" {
  2.     Properties {
  3.         _Color ("Color", Color) = (1,1,1,1)
  4.         _MainTex ("Albedo (RGB)", 2D) = "white" {}
  5.         _Glossiness ("Smoothness", Range(0,1)) = 0.5
  6.         _Metallic ("Metallic", Range(0,1)) = 0.0
  7.         _Sharpness ("Dot Sharpness", Range(0,100000)) = 10000
  8.         _Distance ("Virtual Distance", Range(0, 1000.0)) = 1.0
  9.     }
  10.     SubShader {
  11.         Tags {
  12.           "RenderType"="Transparent"
  13.           "Queue" = "Transparent"
  14.         }
  15.         LOD 200
  16.         ZWrite On
  17.         ZTest LEqual
  18.  
  19.         CGPROGRAM
  20.         #pragma surface surf Standard fullforwardshadows alpha
  21.  
  22.         #pragma target 3.0
  23.  
  24.         sampler2D _MainTex;
  25.         float4 _MainTex_ST;
  26.  
  27.         struct Input {
  28.             float2 uv_MainTex;
  29.             float3 viewDir;
  30.         };
  31.  
  32.         half _Glossiness;
  33.         half _Metallic;
  34.         fixed4 _Color;
  35.         int _Sharpness;
  36.         float _Distance;
  37.  
  38.         UNITY_INSTANCING_BUFFER_START(Props)
  39.         UNITY_INSTANCING_BUFFER_END(Props)
  40.  
  41.         void surf (Input IN, inout SurfaceOutputStandard o) {
  42.             float3 cameraModelSpace = mul(unity_WorldToObject, float4(_WorldSpaceCameraPos, 1.0)).xyz;
  43.             // direction from camera to (0,0,_distance) (center of the reticle), in model space
  44.             float3 cameraToCenterModelSpace = normalize(cameraModelSpace - float3(0,0,_Distance));
  45.             // the view direction for this fragment, in modelspace
  46.             float3 viewDirModelSpace = normalize(mul((float3x3)unity_WorldToObject, IN.viewDir));
  47.             // since the virtual plane of the reticle is the XY plane (in model space)
  48.             // we get the UV for this fragment as the difference between camera to center
  49.             // and viewDir (i.e. camera to current fragment).
  50.             float3 cameraVsViewModelSpace = cameraToCenterModelSpace - viewDirModelSpace;
  51.             // scale, and back to (0,1) UV coords
  52.             float2 uv = float2(cameraVsViewModelSpace.xy *_MainTex_ST) + float2(0.5, 0.5);
  53.             fixed4 tex;
  54.             // be completely transparent outside UV bounds. a little hacky.
  55.             if (uv.x < 0 || uv.y < 0 || uv.x > 1 || uv.y > 1) {
  56.                 tex = fixed4(0,0,0,0);
  57.             } else {
  58.                 tex = tex2D(_MainTex, clamp(uv, float2(0,0), float2(1,1)));
  59.             }
  60.  
  61.             o.Albedo = tex.rgb * _Color;
  62.             o.Emission = o.Albedo;
  63.             o.Metallic = _Metallic;
  64.             o.Smoothness = _Glossiness;
  65.             o.Alpha = tex.a;
  66.         }
  67.         ENDCG
  68.     }
  69.     FallBack "Diffuse"
  70. }
Advertisement
Add Comment
Please, Sign In to add comment