2025-12-02 16:04:23 +08:00

523 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;
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);
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
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 depth=SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture,sampler_CameraDepthTexture,i.position.xy/_ScreenParams.xy);
float lineDp=LinearEyeDepth(depth,_ZBufferParams);
float Dp01=saturate(lineDp/30);
mainColor.rgb=lerp(mainColor.rgb,(OutColor.rgb*lineDp*lineDp*_OutLineWide+OutColor.rgb*0.8),(OutColor.a+Dp01));
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*5;
half4 col=SAMPLE_TEXTURE2D(_MainTex,sampler_MainTex,uv)*0.4;
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*5;
half4 col=SAMPLE_TEXTURE2D(_MainTex,sampler_MainTex,uv)*0.4;
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);
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*1.5+tempColor.rgb*2;
return col;
}
ENDHLSL
}
}
}