Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.78 KB | None | 0 0
  1. Shader "StandardBoostedXrayExtrude"
  2. {
  3.     Properties
  4.     {
  5.    
  6.     _ColorXray("Color Xray", Color) = (1,0.792,0,1)
  7.     _BumpScale("Scale NormalMap", Float) = 1.0
  8.  
  9.     }
  10.  
  11.         SubShader{
  12.  
  13.  
  14.         Pass
  15.     {
  16.         Tags
  17.     {
  18.         //"RenderType" = "Opaque"
  19.         "Queue" = "Opaque"//AlphaTest+49
  20.         "ForceNoShadowCasting" = "True"
  21.     }
  22.         Stencil
  23.     {
  24.         Ref 32//WriteMask 32//
  25.         Comp always
  26.         Pass replace// IncrSat//
  27.         ZFail keep
  28.     }
  29.         Blend SrcAlpha OneMinusSrcAlpha
  30.  
  31.         CGPROGRAM
  32. #pragma vertex vert
  33. #pragma fragment frag
  34. #include "UnityCG.cginc"
  35.         // Properties
  36.         uniform float4 _ColorXray;
  37.     //  sampler2D _BumpMap;
  38.     struct vertexInput
  39.     {
  40.         float4 vertex : POSITION;
  41.         float3 normal : NORMAL;
  42.     };
  43.  
  44.     struct vertexOutput
  45.     {
  46.         float4 pos : SV_POSITION;
  47.     };
  48.  
  49.     vertexOutput vert(vertexInput input)
  50.     {
  51.        
  52.         input.vertex.xyz += input.normal *0.01;
  53.         vertexOutput output;
  54.         output.pos = UnityObjectToClipPos(input.vertex);
  55.         return output;
  56.     }
  57.  
  58.     float4 frag(vertexOutput input) : COLOR
  59.     {
  60.     return float4(0, 0, 0, 0);
  61.     }
  62.  
  63.         ENDCG
  64.     }
  65.        
  66.         Pass
  67.     {
  68.         Tags
  69.     {
  70.         //"RenderType" = "Opaque"
  71.         "Queue" = "AlphaTest+49"//AlphaTest+49
  72.         "ForceNoShadowCasting" = "True"
  73.     }
  74.         // Won't draw where it sees ref value 32
  75.         Cull Back // draw front faces
  76.         ZWrite OFF
  77.         ZTest Always
  78.         Stencil
  79.     {
  80.         //Ref 32
  81.         ReadMask 32//Ref 32
  82.         Comp Equal//NotEqual
  83.         Pass keep
  84.     }
  85.         Blend SrcAlpha OneMinusSrcAlpha
  86.        
  87.         CGPROGRAM
  88. #pragma vertex vert
  89. #pragma fragment frag
  90. #include "UnityCG.cginc"
  91.         // Properties
  92.         uniform float4 _ColorXray;
  93.     uniform sampler2D _CameraDepthTexture;
  94.  
  95. //  sampler2D _BumpMap;
  96.     struct vertexInput
  97.     {
  98.         float4 vertex : POSITION;
  99.         float3 normal : NORMAL;
  100.     };
  101.  
  102.     struct vertexOutput
  103.     {
  104.         float4 pos : SV_POSITION;
  105.         float3 normal : TEXCOORD0;
  106.         float3 viewDirection : POSITION2;
  107.         float4 projPos : TEXCOORD1;
  108.     };
  109.  
  110.     vertexOutput vert(vertexInput v)
  111.     {
  112.         v.vertex.xyz += v.normal *0.01;
  113.         vertexOutput output;
  114.         output.pos = UnityObjectToClipPos(v.vertex);
  115.         output.normal = normalize(mul(float4(v.normal,0), unity_WorldToObject).xyz);
  116.         float3 mulRes = mul(unity_ObjectToWorld, v.vertex);
  117.         output.viewDirection = normalize(_WorldSpaceCameraPos - mulRes);
  118.         output.projPos = ComputeScreenPos(output.pos);
  119.         COMPUTE_EYEDEPTH(output.projPos.z);
  120.         return output;
  121.     }
  122.  
  123.     float4 frag(vertexOutput input) : COLOR
  124.     {
  125.         float SceneWaterDepth = max(0, input.projPos.z - _ProjectionParams.g)-max(0, LinearEyeDepth(UNITY_SAMPLE_DEPTH(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(input.projPos)))) - _ProjectionParams.g);
  126.     if(SceneWaterDepth<3)
  127.     return float4(0, 0, 0,0);
  128.         float newOpacity =1.15 -abs(dot(input.viewDirection,  input.normal));
  129.     newOpacity = (newOpacity*(newOpacity)+0.1)*_ColorXray.a;
  130.     float4 output = float4(_ColorXray.rgb, newOpacity);
  131.         return output;
  132.     }
  133.  
  134.         ENDCG
  135.     }
  136.     }
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement