530 lines
16 KiB
Plaintext
530 lines
16 KiB
Plaintext
Shader "Unlit URP Shader/OutLine2"
|
|
{
|
|
Properties
|
|
{
|
|
_MainTex("MainTex",2d)="white"{}
|
|
//_OutLineColor("OutLineColor",color)=(1,1,1,1)
|
|
//_OutLineWide("OutLineWide",float)=1
|
|
}
|
|
|
|
SubShader
|
|
{
|
|
Tags { "Queue"="Transparent" "RenderPipeline" = "UniversalPipeline" }
|
|
LOD 100
|
|
|
|
Pass
|
|
{
|
|
Name "0_Fill"
|
|
ZWrite Off
|
|
ZTest Always
|
|
Cull Off
|
|
Stencil
|
|
{
|
|
Ref 2
|
|
Comp Always
|
|
Pass Replace
|
|
ZFail Replace
|
|
}
|
|
HLSLPROGRAM
|
|
// Required to compile gles 2.0 with standard srp library
|
|
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#pragma multi_compile_fog
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
|
|
|
|
|
|
|
struct Attributes
|
|
{
|
|
float4 vertex : POSITION;
|
|
float3 normal : NORMAL;
|
|
float3 smoothNormal : TEXCOORD3;
|
|
};
|
|
|
|
struct Varyings
|
|
{
|
|
float4 position : SV_POSITION;
|
|
float4 color : COLOR;
|
|
};
|
|
|
|
CBUFFER_START(UnityPerMaterial)
|
|
half4 _OutLineColor;
|
|
half _OutLineWide;
|
|
CBUFFER_END
|
|
|
|
|
|
Varyings vert(Attributes v)
|
|
{
|
|
Varyings o = (Varyings)0;
|
|
o.position = TransformObjectToHClip(v.vertex);
|
|
o.color = _OutLineColor;
|
|
//o.color.a=saturate(o.color.a*0.5+_OutLineWide*0.25);
|
|
return o;
|
|
}
|
|
|
|
half4 frag(Varyings i) : SV_Target
|
|
{
|
|
return i.color;
|
|
}
|
|
ENDHLSL
|
|
}
|
|
Pass
|
|
{
|
|
Name "1_Bur"
|
|
ZWrite Off
|
|
ZTest Always
|
|
Cull Off
|
|
Lighting Off
|
|
HLSLPROGRAM
|
|
// Required to compile gles 2.0 with standard srp library
|
|
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#pragma multi_compile_fog
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
|
|
|
|
|
|
|
struct Attributes
|
|
{
|
|
float4 vertex : POSITION;
|
|
float3 normal : NORMAL;
|
|
float2 uv : TEXCOORD0;
|
|
};
|
|
|
|
struct Varyings
|
|
{
|
|
float4 position : SV_POSITION;
|
|
float4 color : COLOR;
|
|
float2 uv:TEXCOORD0;
|
|
};
|
|
CBUFFER_START(UnityPerMaterial)
|
|
half4 _OutLineColor;
|
|
half _OutLineWide;
|
|
CBUFFER_END
|
|
float _BurStength;
|
|
TEXTURE2D(_MainTex);SAMPLER(sampler_MainTex);
|
|
float4 _MainTex_TexelSize;
|
|
float4 Bur(float2 uv)
|
|
{
|
|
float d=_MainTex_TexelSize.xy*_BurStength;
|
|
half4 col=SAMPLE_TEXTURE2D(_MainTex,sampler_MainTex,uv+float2(1,0)*d);
|
|
|
|
col+=SAMPLE_TEXTURE2D(_MainTex,sampler_MainTex,uv+float2(0,1)*d);
|
|
col+=SAMPLE_TEXTURE2D(_MainTex,sampler_MainTex,uv+float2(-1,0)*d);
|
|
col+=SAMPLE_TEXTURE2D(_MainTex,sampler_MainTex,uv+float2(0,-1)*d);
|
|
return col*0.25;
|
|
}
|
|
Varyings vert(Attributes v)
|
|
{
|
|
Varyings o = (Varyings)0;
|
|
o.position = TransformObjectToHClip(v.vertex);
|
|
o.uv=v.uv;
|
|
o.color = _OutLineColor;
|
|
return o;
|
|
}
|
|
|
|
half4 frag(Varyings i) : SV_Target
|
|
{
|
|
float4 col=Bur(i.uv);
|
|
|
|
return col;
|
|
}
|
|
ENDHLSL
|
|
}
|
|
Pass
|
|
{
|
|
Name "2_Cut"
|
|
ZWrite Off
|
|
ZTest Always
|
|
Cull Off
|
|
Lighting Off
|
|
Stencil
|
|
{
|
|
Ref 2
|
|
Comp Equal
|
|
Pass Keep
|
|
ZFail Keep
|
|
}
|
|
HLSLPROGRAM
|
|
// Required to compile gles 2.0 with standard srp library
|
|
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#pragma multi_compile_fog
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
|
|
|
|
|
|
|
struct Attributes
|
|
{
|
|
float4 vertex : POSITION;
|
|
float3 normal : NORMAL;
|
|
float2 uv : TEXCOORD0;
|
|
};
|
|
|
|
struct Varyings
|
|
{
|
|
float4 position : SV_POSITION;
|
|
float2 uv:TEXCOORD0;
|
|
};
|
|
CBUFFER_START(UnityPerMaterial)
|
|
half4 _OutLineColor;
|
|
half _OutLineWide;
|
|
CBUFFER_END
|
|
|
|
TEXTURE2D(_MainTex);SAMPLER(sampler_MainTex);
|
|
|
|
|
|
|
|
Varyings vert(Attributes v)
|
|
{
|
|
Varyings o = (Varyings)0;
|
|
o.position = TransformObjectToHClip(v.vertex);
|
|
o.uv=v.uv;
|
|
|
|
return o;
|
|
}
|
|
|
|
half4 frag(Varyings i) : SV_Target
|
|
{
|
|
return float4(0,0,0,0);//SAMPLE_TEXTURE2D(_MainTex,sampler_MainTex,i.uv);
|
|
}
|
|
ENDHLSL
|
|
}
|
|
Pass
|
|
{
|
|
Name "3_Blend"
|
|
ZWrite Off
|
|
ZTest Always
|
|
Cull Off
|
|
Lighting Off
|
|
|
|
HLSLPROGRAM
|
|
// Required to compile gles 2.0 with standard srp library
|
|
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#pragma multi_compile_fog
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
|
//#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
|
|
|
|
|
|
struct Attributes
|
|
{
|
|
float4 vertex : POSITION;
|
|
float3 normal : NORMAL;
|
|
float2 uv : TEXCOORD0;
|
|
};
|
|
|
|
struct Varyings
|
|
{
|
|
float4 position : SV_POSITION;
|
|
float4 color : COLOR;
|
|
float2 uv:TEXCOORD0;
|
|
};
|
|
CBUFFER_START(UnityPerMaterial)
|
|
half4 _OutLineColor;
|
|
half _OutLineWide;
|
|
CBUFFER_END
|
|
float Remap(float x, float t1, float t2, float s1, float s2)
|
|
{
|
|
return (s2 - s1) / (t2 - t1) * (x - t1) + s1;
|
|
|
|
}
|
|
|
|
TEXTURE2D(_MainTex);SAMPLER(sampler_MainTex);
|
|
TEXTURE2D(_OutLineTex);SAMPLER(sampler_OutLineTex);
|
|
TEXTURE2D_X_FLOAT(_CameraDepthTexture);
|
|
SAMPLER(sampler_CameraDepthTexture);
|
|
Varyings vert(Attributes v)
|
|
{
|
|
Varyings o = (Varyings)0;
|
|
o.position = TransformObjectToHClip(v.vertex);
|
|
o.uv=v.uv;
|
|
return o;
|
|
}
|
|
|
|
half4 frag(Varyings i) : SV_Target
|
|
{
|
|
half4 mainColor=SAMPLE_TEXTURE2D(_MainTex,sampler_MainTex,i.uv);
|
|
half4 OutColor=SAMPLE_TEXTURE2D(_OutLineTex,sampler_OutLineTex,i.uv);
|
|
float a=pow(OutColor.a,0.5);
|
|
mainColor.rgb=(saturate((OutColor.rgb)*a*3+mainColor.rgb*pow((1-OutColor.a),3)));
|
|
return mainColor;
|
|
}
|
|
ENDHLSL
|
|
}
|
|
Pass
|
|
{
|
|
Name "4_Cut"
|
|
ZWrite Off
|
|
ZTest Always
|
|
Cull Off
|
|
Lighting Off
|
|
Stencil
|
|
{
|
|
Ref 2
|
|
Comp NotEqual
|
|
Pass Keep
|
|
ZFail Keep
|
|
}
|
|
HLSLPROGRAM
|
|
// Required to compile gles 2.0 with standard srp library
|
|
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#pragma multi_compile_fog
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
|
|
|
|
|
|
|
struct Attributes
|
|
{
|
|
float4 vertex : POSITION;
|
|
float3 normal : NORMAL;
|
|
float2 uv : TEXCOORD0;
|
|
};
|
|
|
|
struct Varyings
|
|
{
|
|
float4 position : SV_POSITION;
|
|
float2 uv:TEXCOORD0;
|
|
};
|
|
CBUFFER_START(UnityPerMaterial)
|
|
half4 _OutLineColor;
|
|
half _OutLineWide;
|
|
CBUFFER_END
|
|
|
|
TEXTURE2D(_MainTex);SAMPLER(sampler_MainTex);
|
|
|
|
|
|
|
|
Varyings vert(Attributes v)
|
|
{
|
|
Varyings o = (Varyings)0;
|
|
o.position = TransformObjectToHClip(v.vertex);
|
|
o.uv=v.uv;
|
|
|
|
return o;
|
|
}
|
|
|
|
half4 frag(Varyings i) : SV_Target
|
|
{
|
|
return SAMPLE_TEXTURE2D(_MainTex,sampler_MainTex,i.uv);
|
|
}
|
|
ENDHLSL
|
|
}
|
|
Pass
|
|
{
|
|
Name "5_BurH"
|
|
ZWrite Off
|
|
ZTest Always
|
|
Cull Off
|
|
Lighting Off
|
|
HLSLPROGRAM
|
|
// Required to compile gles 2.0 with standard srp library
|
|
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#pragma multi_compile_fog
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
|
|
|
|
|
|
|
struct Attributes
|
|
{
|
|
float4 vertex : POSITION;
|
|
float3 normal : NORMAL;
|
|
float2 uv : TEXCOORD0;
|
|
};
|
|
|
|
struct Varyings
|
|
{
|
|
float4 position : SV_POSITION;
|
|
float4 color : COLOR;
|
|
float2 uv:TEXCOORD0;
|
|
};
|
|
CBUFFER_START(UnityPerMaterial)
|
|
half4 _OutLineColor;
|
|
half _OutLineWide;
|
|
CBUFFER_END
|
|
|
|
TEXTURE2D(_MainTex);SAMPLER(sampler_MainTex);
|
|
float4 _MainTex_TexelSize;
|
|
float4 Bur(float2 uv)
|
|
{
|
|
float d=_MainTex_TexelSize.xy*1;
|
|
half4 col=SAMPLE_TEXTURE2D(_MainTex,sampler_MainTex,uv)*0.4;
|
|
//if(col.a<0.001) return float4(0,0,0,0);
|
|
|
|
col+=SAMPLE_TEXTURE2D(_MainTex,sampler_MainTex,uv+float2(1,0)*d)*0.25;
|
|
col+=SAMPLE_TEXTURE2D(_MainTex,sampler_MainTex,uv+float2(2,0)*d)*0.05;
|
|
col+=SAMPLE_TEXTURE2D(_MainTex,sampler_MainTex,uv+float2(-1,0)*d)*0.25;
|
|
col+=SAMPLE_TEXTURE2D(_MainTex,sampler_MainTex,uv+float2(-2,0)*d)*0.05;
|
|
return col;
|
|
}
|
|
Varyings vert(Attributes v)
|
|
{
|
|
Varyings o = (Varyings)0;
|
|
o.position = TransformObjectToHClip(v.vertex);
|
|
o.uv=v.uv;
|
|
o.color = _OutLineColor;
|
|
return o;
|
|
}
|
|
|
|
half4 frag(Varyings i) : SV_Target
|
|
{
|
|
return Bur(i.uv);
|
|
}
|
|
ENDHLSL
|
|
}
|
|
Pass
|
|
{
|
|
Name "6_BurV"
|
|
ZWrite Off
|
|
ZTest Always
|
|
Cull Off
|
|
Lighting Off
|
|
HLSLPROGRAM
|
|
// Required to compile gles 2.0 with standard srp library
|
|
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#pragma multi_compile_fog
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
|
|
|
|
|
|
|
struct Attributes
|
|
{
|
|
float4 vertex : POSITION;
|
|
float3 normal : NORMAL;
|
|
float2 uv : TEXCOORD0;
|
|
};
|
|
|
|
struct Varyings
|
|
{
|
|
float4 position : SV_POSITION;
|
|
float4 color : COLOR;
|
|
float2 uv:TEXCOORD0;
|
|
};
|
|
CBUFFER_START(UnityPerMaterial)
|
|
half4 _OutLineColor;
|
|
half _OutLineWide;
|
|
CBUFFER_END
|
|
|
|
TEXTURE2D(_MainTex);SAMPLER(sampler_MainTex);
|
|
float4 _MainTex_TexelSize;
|
|
float4 Bur(float2 uv)
|
|
{
|
|
float d=_MainTex_TexelSize.xy*1;
|
|
half4 col=SAMPLE_TEXTURE2D(_MainTex,sampler_MainTex,uv)*0.4;
|
|
//if(col.a<0.001) return float4(0,0,0,0);
|
|
col+=SAMPLE_TEXTURE2D(_MainTex,sampler_MainTex,uv+float2(0,1)*d)*0.25;
|
|
col+=SAMPLE_TEXTURE2D(_MainTex,sampler_MainTex,uv+float2(0,2)*d)*0.05;
|
|
col+=SAMPLE_TEXTURE2D(_MainTex,sampler_MainTex,uv+float2(0,-1)*d)*0.25;
|
|
col+=SAMPLE_TEXTURE2D(_MainTex,sampler_MainTex,uv+float2(0,-2)*d)*0.05;
|
|
return col;
|
|
}
|
|
Varyings vert(Attributes v)
|
|
{
|
|
Varyings o = (Varyings)0;
|
|
o.position = TransformObjectToHClip(v.vertex);
|
|
o.uv=v.uv;
|
|
o.color = _OutLineColor;
|
|
|
|
return o;
|
|
}
|
|
|
|
half4 frag(Varyings i) : SV_Target
|
|
{
|
|
return Bur(i.uv);
|
|
}
|
|
ENDHLSL
|
|
}
|
|
Pass
|
|
{
|
|
Name "1_Bur"
|
|
ZWrite Off
|
|
ZTest Always
|
|
Cull Off
|
|
Lighting Off
|
|
HLSLPROGRAM
|
|
// Required to compile gles 2.0 with standard srp library
|
|
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#pragma multi_compile_fog
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
|
|
|
|
|
|
|
struct Attributes
|
|
{
|
|
float4 vertex : POSITION;
|
|
float3 normal : NORMAL;
|
|
float2 uv : TEXCOORD0;
|
|
};
|
|
|
|
struct Varyings
|
|
{
|
|
float4 position : SV_POSITION;
|
|
float4 color : COLOR;
|
|
float2 uv:TEXCOORD0;
|
|
};
|
|
CBUFFER_START(UnityPerMaterial)
|
|
half4 _OutLineColor;
|
|
half _OutLineWide;
|
|
CBUFFER_END
|
|
float _BurStength;
|
|
TEXTURE2D(_Temp);SAMPLER(sampler_Temp);
|
|
TEXTURE2D(_MainTex);SAMPLER(sampler_MainTex);
|
|
float4 _MainTex_TexelSize;
|
|
float4 Bur(float2 uv)
|
|
{
|
|
float d=_MainTex_TexelSize.xy*_BurStength;
|
|
half4 col=SAMPLE_TEXTURE2D(_MainTex,sampler_MainTex,uv+float2(0,1)*d);
|
|
|
|
col+=SAMPLE_TEXTURE2D(_MainTex,sampler_MainTex,uv+float2(-1,0)*d);
|
|
col+=SAMPLE_TEXTURE2D(_MainTex,sampler_MainTex,uv+float2(0,-1)*d);
|
|
col+=SAMPLE_TEXTURE2D(_MainTex,sampler_MainTex,uv+float2(1,0)*d);
|
|
return col*0.25;
|
|
}
|
|
Varyings vert(Attributes v)
|
|
{
|
|
Varyings o = (Varyings)0;
|
|
o.position = TransformObjectToHClip(v.vertex);
|
|
o.uv=v.uv;
|
|
o.color = _OutLineColor;
|
|
return o;
|
|
}
|
|
|
|
half4 frag(Varyings i) : SV_Target
|
|
{
|
|
float4 col=Bur(i.uv);
|
|
float4 tempColor=SAMPLE_TEXTURE2D(_Temp,sampler_Temp,i.uv);
|
|
col.rgb=col.rgb+tempColor.rgb;
|
|
return col;
|
|
}
|
|
ENDHLSL
|
|
}
|
|
}
|
|
} |