Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "Custom/HoloSight" {
- Properties {
- _Color ("Color", Color) = (1,1,1,1)
- _MainTex ("Albedo (RGB)", 2D) = "white" {}
- _Glossiness ("Smoothness", Range(0,1)) = 0.5
- _Metallic ("Metallic", Range(0,1)) = 0.0
- _Sharpness ("Dot Sharpness", Range(0,100000)) = 10000
- _Distance ("Virtual Distance", Range(0, 1000.0)) = 1.0
- }
- SubShader {
- Tags {
- "RenderType"="Transparent"
- "Queue" = "Transparent"
- }
- LOD 200
- ZWrite On
- ZTest LEqual
- CGPROGRAM
- #pragma surface surf Standard fullforwardshadows alpha
- #pragma target 3.0
- sampler2D _MainTex;
- float4 _MainTex_ST;
- struct Input {
- float2 uv_MainTex;
- float3 viewDir;
- };
- half _Glossiness;
- half _Metallic;
- fixed4 _Color;
- int _Sharpness;
- float _Distance;
- UNITY_INSTANCING_BUFFER_START(Props)
- UNITY_INSTANCING_BUFFER_END(Props)
- void surf (Input IN, inout SurfaceOutputStandard o) {
- float3 cameraModelSpace = mul(unity_WorldToObject, float4(_WorldSpaceCameraPos, 1.0)).xyz;
- // direction from camera to (0,0,_distance) (center of the reticle), in model space
- float3 cameraToCenterModelSpace = normalize(cameraModelSpace - float3(0,0,_Distance));
- // the view direction for this fragment, in modelspace
- float3 viewDirModelSpace = normalize(mul((float3x3)unity_WorldToObject, IN.viewDir));
- // since the virtual plane of the reticle is the XY plane (in model space)
- // we get the UV for this fragment as the difference between camera to center
- // and viewDir (i.e. camera to current fragment).
- float3 cameraVsViewModelSpace = cameraToCenterModelSpace - viewDirModelSpace;
- // scale, and back to (0,1) UV coords
- float2 uv = float2(cameraVsViewModelSpace.xy *_MainTex_ST) + float2(0.5, 0.5);
- fixed4 tex;
- // be completely transparent outside UV bounds. a little hacky.
- if (uv.x < 0 || uv.y < 0 || uv.x > 1 || uv.y > 1) {
- tex = fixed4(0,0,0,0);
- } else {
- tex = tex2D(_MainTex, clamp(uv, float2(0,0), float2(1,1)));
- }
- o.Albedo = tex.rgb * _Color;
- o.Emission = o.Albedo;
- o.Metallic = _Metallic;
- o.Smoothness = _Glossiness;
- o.Alpha = tex.a;
- }
- ENDCG
- }
- FallBack "Diffuse"
- }
Advertisement
Add Comment
Please, Sign In to add comment