134 lines
4.2 KiB
Plaintext
134 lines
4.2 KiB
Plaintext
|
|
Shader "Unlit URP Shader/Bur"
|
||
|
|
{
|
||
|
|
Properties
|
||
|
|
{
|
||
|
|
_BaseColor("Base Color",color) = (1,1,1,1)
|
||
|
|
//_BaseMap("BaseMap", 2D) = "white" {}
|
||
|
|
_MainTex("MainTex",2d)="white"{}
|
||
|
|
//_Value("Value", Float) = 3
|
||
|
|
}
|
||
|
|
HLSLINCLUDE
|
||
|
|
#pragma multi_compile _ LIGHTMAP_ON
|
||
|
|
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS //接受主光源阴影
|
||
|
|
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE //投射主光源的阴影
|
||
|
|
#pragma multi_compile _ _SHADOWS_SOFT //软阴影
|
||
|
|
#pragma multi_compile _ _ADDITIONAL_LIGHTS //附加光源
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
struct Attributes
|
||
|
|
{
|
||
|
|
float4 positionOS : POSITION;
|
||
|
|
float2 uv : TEXCOORD0;
|
||
|
|
float3 normal:NORMAL;
|
||
|
|
};
|
||
|
|
|
||
|
|
struct Varyings
|
||
|
|
{
|
||
|
|
float4 positionCS : SV_POSITION;
|
||
|
|
float2 uv : TEXCOORD0;
|
||
|
|
float3 Wnormal : TEXCOORD1;
|
||
|
|
float3 Wpos:TEXCOORD2;
|
||
|
|
};
|
||
|
|
|
||
|
|
CBUFFER_START(UnityPerMaterial)
|
||
|
|
half4 _BaseColor;
|
||
|
|
float4 _MainTex_TexelSize;
|
||
|
|
float4 _BaseMap_ST;
|
||
|
|
float _Value;
|
||
|
|
float2 HorV;
|
||
|
|
CBUFFER_END
|
||
|
|
TEXTURE2D (_MainTex);SAMPLER(sampler_MainTex);
|
||
|
|
//TEXTURE2D (_CameraOpaqueTexture);SAMPLER(sampler_CameraOpaqueTexture);
|
||
|
|
|
||
|
|
Varyings vert(Attributes v)
|
||
|
|
{
|
||
|
|
Varyings o = (Varyings)0;
|
||
|
|
|
||
|
|
o.positionCS = TransformObjectToHClip(v.positionOS.xyz);
|
||
|
|
o.uv = TRANSFORM_TEX(v.uv, _BaseMap);
|
||
|
|
o.Wpos = TransformObjectToWorld(v.positionOS);
|
||
|
|
o.Wnormal=TransformObjectToWorldNormal(v.normal);
|
||
|
|
|
||
|
|
return o;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
half4 fragHorV(Varyings i) : SV_Target
|
||
|
|
{
|
||
|
|
float2 offset=_MainTex_TexelSize.xy;
|
||
|
|
half4 c;
|
||
|
|
float2 uv=i.positionCS.xy/_ScreenParams.xy;
|
||
|
|
|
||
|
|
half4 baseMap = 0.4*SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex,uv);
|
||
|
|
c = baseMap ;//* _BaseColor;
|
||
|
|
{
|
||
|
|
c+= 0.15*SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex,uv+offset*1*_Value*HorV);
|
||
|
|
c+= 0.15*SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex,uv+offset*-2*_Value*HorV);
|
||
|
|
c+= 0.10 *SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex,uv+offset*2*_Value*HorV);
|
||
|
|
c+= 0.10 *SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex,uv+offset*-2*_Value*HorV);
|
||
|
|
c+= 0.05 *SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex,uv+offset*3*_Value*HorV);
|
||
|
|
c+= 0.05 *SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex,uv+offset*-3*_Value*HorV);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
return c;
|
||
|
|
}
|
||
|
|
half4 fragBur(Varyings i) : SV_Target
|
||
|
|
{
|
||
|
|
float2 offset=_MainTex_TexelSize.xy;
|
||
|
|
|
||
|
|
half4 c=half4(0,0,0,0);
|
||
|
|
float2 uv=i.positionCS.xy/_ScreenParams.xy;
|
||
|
|
//c = baseMap ;//* _BaseColor;
|
||
|
|
{
|
||
|
|
float f=0.4;
|
||
|
|
c+= SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex,uv+offset*float2(1,1)*_Value*f);
|
||
|
|
c+= SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex,uv+offset*float2(-1,1)*_Value*f);
|
||
|
|
c+= SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex,uv+offset*float2(1,-1)*_Value*f);
|
||
|
|
c+= SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex,uv+offset*float2(-1,-1)*_Value*f);
|
||
|
|
|
||
|
|
c+= SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex,uv+offset*float2(2,2)*_Value*f);
|
||
|
|
c+= SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex,uv+offset*float2(-2,2)*_Value*f);
|
||
|
|
c+= SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex,uv+offset*float2(2,-2)*_Value*f);
|
||
|
|
c+= SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex,uv+offset*float2(-2,-2)*_Value*f);
|
||
|
|
c/=8;
|
||
|
|
}
|
||
|
|
|
||
|
|
return c;
|
||
|
|
}
|
||
|
|
|
||
|
|
ENDHLSL
|
||
|
|
SubShader
|
||
|
|
{
|
||
|
|
Tags { "Queue"="Transparent" "RenderType" = "Transparent" "RenderPipeline" = "UniversalPipeline" }
|
||
|
|
ZTest Always
|
||
|
|
Cull Off
|
||
|
|
LOD 100
|
||
|
|
//高斯模糊
|
||
|
|
Pass
|
||
|
|
{
|
||
|
|
Tags {"LightMode" = "UniversalForward"}
|
||
|
|
HLSLPROGRAM
|
||
|
|
#pragma vertex vert
|
||
|
|
#pragma fragment fragHorV
|
||
|
|
ENDHLSL
|
||
|
|
}
|
||
|
|
//快速模糊
|
||
|
|
Pass
|
||
|
|
{
|
||
|
|
Tags {"LightMode" = "UniversalForward"}
|
||
|
|
HLSLPROGRAM
|
||
|
|
#pragma vertex vert
|
||
|
|
#pragma fragment fragBur
|
||
|
|
|
||
|
|
ENDHLSL
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|