Advertisement
baikolepus

Outline shader

Oct 28th, 2022
622
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OpenGL Shading 2.61 KB | Source Code | 0 0
  1. Shader "Custom/Outline"
  2. {
  3.     Properties
  4.     {
  5.         //[PerRendererData] _Color ("Glow Color", Color ) = ( 1, 1, 1, 1)
  6.         _Intensity ("Intensity", Float) = 2
  7.         [Enum(UnityEngine.Rendering.BlendMode)] _SrcBlend ("Src Blend", Float) = 1
  8.         [Enum(UnityEngine.Rendering.BlendMode)] _DstBlend ("Dst Blend", Float) = 0
  9.     }
  10.    
  11.     SubShader
  12.     {      
  13.         HLSLINCLUDE
  14.  
  15.         #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  16.        
  17.         struct Attributes
  18.         {
  19.             float4 positionOS   : POSITION;
  20.             float2 uv           : TEXCOORD0;
  21.         };
  22.        
  23.         struct Varyings
  24.         {
  25.             half4 positionCS    : SV_POSITION;
  26.             half2 uv            : TEXCOORD0;
  27.         };
  28.  
  29.         TEXTURE2D_X(_OutlineRenderTexture);
  30.         SAMPLER(sampler_OutlineRenderTexture);
  31.  
  32.         TEXTURE2D_X(_OutlineBluredTexture);
  33.         SAMPLER(sampler_OutlineBluredTexture);
  34.  
  35.         half4 _Color;
  36.         half _Intensity;
  37.  
  38.         Varyings Vertex(Attributes input)
  39.         {
  40.             Varyings output;
  41.             output.positionCS = float4(input.positionOS.xy, 0.0, 1.0);
  42.             output.uv = input.uv;
  43.             if (_ProjectionParams.x < 0.0)
  44.                 output.uv.y = 1.0 - output.uv.y;   
  45.             return output;      
  46.         }
  47.  
  48.         half4 Fragment(Varyings input) : SV_Target
  49.         {
  50.             float2 uv = UnityStereoTransformScreenSpaceTex(input.uv);
  51.             half4 prepassColor = SAMPLE_TEXTURE2D_X(_OutlineRenderTexture, sampler_OutlineRenderTexture, uv);
  52.             half4 bluredColor = SAMPLE_TEXTURE2D_X(_OutlineBluredTexture, sampler_OutlineBluredTexture,uv);
  53.             //half4 difColor = saturate(max( 0, bluredColor.a - prepassColor.a));
  54.             half4 color = bluredColor * _Intensity;
  55.             color.a = saturate(max(0, bluredColor.a - prepassColor.a) );
  56.             color *= color.a;
  57.  
  58.             //color = bluredColor.a - prepassColor.a;
  59.             // color.a = 1;
  60.             return  color;
  61.         }
  62.        
  63.         ENDHLSL        
  64.      
  65.         Pass
  66.         {
  67.  
  68.            
  69.             Blend [_SrcBlend] [_DstBlend]
  70.             ZTest Always    // всегда рисуем, независимо от текущей глубины в буфере
  71.             ZWrite Off      // и ничего в него не пишем
  72.             Cull Off        // рисуем все стороны меша
  73.  
  74.             HLSLPROGRAM
  75.            
  76.             #pragma vertex Vertex
  77.             #pragma fragment Fragment        
  78.  
  79.             ENDHLSL        
  80.         }
  81.     }
  82. }
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement