234 lines
6.6 KiB
Plaintext
Raw Normal View History

2025-01-02 12:15:45 +08:00
Shader "Unlit URP Shader/OutLine2"
{
Properties
{
2025-04-02 14:37:35 +08:00
//_MainTex("MainTex",2d)="white"{}
2025-01-02 12:15:45 +08:00
//_OutLineColor("OutLineColor",color)=(1,1,1,1)
//_OutLineWide("OutLineWide",float)=1
}
2025-04-02 14:37:35 +08:00
HLSLINCLUDE
#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.core/Runtime/Utilities/Blit.hlsl"
CBUFFER_START(UnityPerMaterial)
half4 _OutLineColor;
half _OutLineWide;
CBUFFER_END
float Scale;
TEXTURE2D(_Temp);//SAMPLER(sampler_Temp);
TEXTURE2D(_Cut);SAMPLER(sampler_Cut);
//TEXTURE2D(_MainTex);SAMPLER(sampler_MainTex);
//SAMPLER(sampler_BlitTexture);
float4 _BlitTexture_TexelSize;
TEXTURE2D(_OutLineTex);SAMPLER(sampler_OutLineTex);
float Strength;
float2 HoV;
struct Attributes2
{
float4 vertex : POSITION;
float3 normal : NORMAL;
//float3 smoothNormal : TEXCOORD3;
float2 uv : TEXCOORD0;
};
struct Varyings2
{
float4 position : SV_POSITION;
float4 color : COLOR;
float2 uv : TEXCOORD0;
};
//圆形模糊
float4 Bur(float2 uv)
{
float2 d=_BlitTexture_TexelSize.xy*Scale;
half4 col=SAMPLE_TEXTURE2D(_BlitTexture,sampler_LinearClamp,uv+float2(0,1)*d);
col+=SAMPLE_TEXTURE2D(_BlitTexture,sampler_LinearClamp,uv+float2(-1,0)*d);
col+=SAMPLE_TEXTURE2D(_BlitTexture,sampler_LinearClamp,uv+float2(0,-1)*d);
col+=SAMPLE_TEXTURE2D(_BlitTexture,sampler_LinearClamp,uv+float2(1,0)*d);
col+=SAMPLE_TEXTURE2D(_BlitTexture,sampler_LinearClamp,uv+float2(-1,1)*d)*0.5;
col+=SAMPLE_TEXTURE2D(_BlitTexture,sampler_LinearClamp,uv+float2(1,-1)*d)*0.5;
col+=SAMPLE_TEXTURE2D(_BlitTexture,sampler_LinearClamp,uv+float2(-1,-1)*d)*0.5;
col+=SAMPLE_TEXTURE2D(_BlitTexture,sampler_LinearClamp,uv+float2(1,1)*d)*0.5;
return col*0.1666;
}
float4 BurHoV(float2 uv)
{
float2 d=_BlitTexture_TexelSize.xy*Scale*HoV;
half4 col=SAMPLE_TEXTURE2D(_BlitTexture,sampler_LinearClamp,uv)*0.4;
col+=SAMPLE_TEXTURE2D(_BlitTexture,sampler_LinearClamp,uv+1*d)*0.15;
col+=SAMPLE_TEXTURE2D(_BlitTexture,sampler_LinearClamp,uv+-1*d)*0.15;
col+=SAMPLE_TEXTURE2D(_BlitTexture,sampler_LinearClamp,uv+2*d)*0.10;
col+=SAMPLE_TEXTURE2D(_BlitTexture,sampler_LinearClamp,uv+-2*d)*0.10;
col+=SAMPLE_TEXTURE2D(_BlitTexture,sampler_LinearClamp,uv+3*d)*0.05;
col+=SAMPLE_TEXTURE2D(_BlitTexture,sampler_LinearClamp,uv+-3*d)*0.05;
return col;
}
float Remap(float x, float t1, float t2, float s1, float s2)
{
return (s2 - s1) / (t2 - t1) * (x - t1) + s1;
}
float3 ACESToneMapping(float3 color, float adapted_lum)
{
const float A = 2.51f;
const float B = 0.03f;
const float C = 2.43f;
const float D = 0.59f;
const float E = 0.14f;
color *= adapted_lum;
return (color * (A * color + B)) / (color * (C * color + D) + E);
}
Varyings2 vert(Attributes2 v)
{
Varyings2 o = (Varyings2)0;
o.position = TransformObjectToHClip(v.vertex);
o.uv=v.uv;
o.color = _OutLineColor;
return o;
}
float4 _HeightLightColor;
//填充颜色
float4 fragFill(Varyings2 i) : SV_Target
{
return _OutLineColor;
}
//降采样模糊
float4 fragDownBlur(Varyings i) : SV_Target
{
float4 col=Bur(i.texcoord);
return col;
}
//升采样模糊
half4 fragUpBlur(Varyings i) : SV_Target
{
float4 col=Bur(i.texcoord);
float4 tempColor=SAMPLE_TEXTURE2D(_Temp,sampler_LinearClamp,i.texcoord);
col.rgb=col.rgb+tempColor.rgb;
return col;
}
//高斯模糊
float4 fragHoV(Varyings i) : SV_Target
{
float4 col=BurHoV(i.texcoord);
return col;
}
//模板剔除
float4 fragCull(Varyings2 i) : SV_Target
{
//float4 mainColor=SAMPLE_TEXTURE2D(_MainTex,sampler_MainTex,i.texcoord);
//float4 mainColorC=SAMPLE_TEXTURE2D(_Cut,sampler_Cut,i.texcoord);
// mainColorC.rgb=ACESToneMapping(mainColorC.rgb,0.4);
return float4(0,0,0,0);
}
//模板剔除2
float4 fragCull2(Varyings i) : SV_Target
{
return float4(0,1,0,0);
}
//混合颜色
float4 fragBlend(Varyings i) : SV_Target
{
float4 mainColor=SAMPLE_TEXTURE2D(_BlitTexture,sampler_LinearClamp,i.texcoord);
mainColor.rgb*=Strength;
//mainColor.rgb=ACESToneMapping(mainColor.rgb,0.6);
return mainColor;
}
ENDHLSL
2025-01-02 12:15:45 +08:00
SubShader
{
Tags { "Queue"="Transparent" "RenderPipeline" = "UniversalPipeline" }
LOD 100
2025-04-02 14:37:35 +08:00
ZWrite Off
ZTest Always
Cull Off
Lighting Off
2025-01-02 12:15:45 +08:00
Pass
{
Name "0_Fill"
Stencil
{
2025-04-02 14:37:35 +08:00
Ref 3
2025-01-02 12:15:45 +08:00
Comp Always
Pass Replace
2025-04-02 14:37:35 +08:00
Fail Keep
2025-01-02 12:15:45 +08:00
}
2025-04-02 14:37:35 +08:00
//ZWrite On
2025-01-02 12:15:45 +08:00
HLSLPROGRAM
#pragma vertex vert
2025-04-02 14:37:35 +08:00
#pragma fragment fragFill
2025-01-02 12:15:45 +08:00
ENDHLSL
}
Pass
{
2025-04-02 14:37:35 +08:00
Name "1_DownBlur"
2025-01-02 12:15:45 +08:00
HLSLPROGRAM
2025-04-02 14:37:35 +08:00
#pragma vertex Vert
#pragma fragment fragDownBlur
2025-01-02 12:15:45 +08:00
ENDHLSL
}
Pass
{
2025-04-02 14:37:35 +08:00
Name "2_UpBlur"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment fragUpBlur
ENDHLSL
}
Pass
{
Name "3_Cut"
2025-01-02 12:15:45 +08:00
Stencil
{
Ref 2
Comp Equal
Pass Keep
2025-04-02 14:37:35 +08:00
Fail Keep
2025-01-02 12:15:45 +08:00
}
2025-04-02 14:37:35 +08:00
//ColorMask 0
//BlendOp RevSub
2025-01-02 12:15:45 +08:00
HLSLPROGRAM
2025-04-02 14:37:35 +08:00
#pragma vertex Vert
#pragma fragment fragCull
2025-01-02 12:15:45 +08:00
ENDHLSL
}
Pass
{
2025-04-02 14:37:35 +08:00
Name "4_Blend"
Blend One One
2025-01-02 12:15:45 +08:00
HLSLPROGRAM
2025-04-02 14:37:35 +08:00
#pragma vertex Vert
#pragma fragment fragBlend
2025-01-02 12:15:45 +08:00
ENDHLSL
}
2025-04-02 14:37:35 +08:00
Pass
2025-01-02 12:15:45 +08:00
{
2025-04-02 14:37:35 +08:00
Name "5_Cut"
2025-01-02 12:15:45 +08:00
Stencil
{
Ref 2
2025-04-02 14:37:35 +08:00
Comp Equal
2025-01-02 12:15:45 +08:00
Pass Keep
ZFail Keep
}
2025-04-02 14:37:35 +08:00
//BlendOp RevSub
2025-01-02 12:15:45 +08:00
HLSLPROGRAM
2025-04-02 14:37:35 +08:00
#pragma vertex Vert
#pragma fragment fragCull2
2025-01-02 12:15:45 +08:00
ENDHLSL
}
2025-04-02 14:37:35 +08:00
2025-01-02 12:15:45 +08:00
}
}