给几种不同的unity 扫光shader的代码
时间: 2023-11-17 18:08:20 浏览: 134
以下是几种不同的Unity扫光Shader的代码:
1. Radial Light Shader:
```
Shader "Custom/RadialLightShader" {
Properties {
_MainTex ("Texture", 2D) = "white" {}
_Color ("Color", Color) = (1,1,1,1)
_Radius ("Radius", Range(0,1)) = 0.5
_Power ("Power", Range(0,10)) = 1
}
SubShader {
Tags {"Queue"="Transparent" "RenderType"="Transparent"}
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata {
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f {
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float4 _Color;
float _Radius;
float _Power;
v2f vert (appdata v) {
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target {
float4 col = tex2D(_MainTex, i.uv) * _Color;
float dist = distance(i.uv, 0.5);
float falloff = smoothstep(_Radius, _Radius + 0.01, dist);
col.rgb *= pow(falloff, _Power);
return col;
}
ENDCG
}
}
FallBack "Diffuse"
}
```
2. Lens Flare Shader:
```
Shader "Custom/LensFlareShader" {
Properties {
_MainTex ("Texture", 2D) = "white" {}
_Color ("Color", Color) = (1,1,1,1)
_Threshold ("Threshold", Range(0,1)) = 0.5
_Brightness ("Brightness", Range(0,10)) = 1
_HaloSize ("Halo Size", Range(0,1)) = 0.5
_HaloSoftness ("Halo Softness", Range(0,1)) = 0.5
_Distortion ("Distortion", Range(-1,1)) = 0.1
}
SubShader {
Tags {"Queue"="Transparent" "RenderType"="Transparent"}
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata {
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f {
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float4 _Color;
float _Threshold;
float _Brightness;
float _HaloSize;
float _HaloSoftness;
float _Distortion;
v2f vert (appdata v) {
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target {
float4 col = tex2D(_MainTex, i.uv) * _Color;
float dist = distance(i.uv, 0.5);
float falloff = smoothstep(_Threshold, _Threshold + 0.01, dist);
col.rgb *= pow(falloff, _Brightness);
float halo = smoothstep(_HaloSize, _HaloSize + _HaloSoftness, dist);
col.rgb += halo * _Color.rgb;
float2 distortion = i.uv - 0.5;
distortion *= 1.0 + _Distortion;
col.rgb = tex2D(_MainTex, i.uv + distortion * halo).rgb;
return col;
}
ENDCG
}
}
FallBack "Diffuse"
}
```
3. Bloom Shader:
```
Shader "Custom/BloomShader" {
Properties {
_MainTex ("Texture", 2D) = "white" {}
_Threshold ("Threshold", Range(0,1)) = 0.5
_Intensity ("Intensity", Range(0,10)) = 1
}
SubShader {
Tags {"Queue"="Transparent" "RenderType"="Transparent"}
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata {
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f {
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float _Threshold;
float _Intensity;
v2f vert (appdata v) {
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target {
float4 col = tex2D(_MainTex, i.uv);
if (col.r > _Threshold || col.g > _Threshold || col.b > _Threshold) {
col.rgb *= _Intensity;
}
return col;
}
ENDCG
}
}
FallBack "Diffuse"
}
```
4. Light Shaft Shader:
```
Shader "Custom/LightShaftShader" {
Properties {
_MainTex ("Texture", 2D) = "white" {}
_Color ("Color", Color) = (1,1,1,1)
_LightPos ("Light Position", Vector) = (0,0,0,0)
_Attenuation ("Attenuation", Range(0,1)) = 0.5
_Spread ("Spread", Range(0,1)) = 0.5
_Intensity ("Intensity", Range(0,10)) = 1
}
SubShader {
Tags {"Queue"="Transparent" "RenderType"="Transparent"}
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata {
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f {
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
float3 worldPos : TEXCOORD1;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float4 _Color;
float4 _LightPos;
float _Attenuation;
float _Spread;
float _Intensity;
v2f vert (appdata v) {
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
return o;
}
fixed4 frag (v2f i) : SV_Target {
float3 ray = normalize(_LightPos.xyz - i.worldPos);
float3 tangent = normalize(cross(ray, float3(0,1,0)));
float3 bitangent = normalize(cross(ray, tangent));
float3 spread = tangent * (_Spread * 2 - 1) + bitangent * (_Spread * 2 - 1);
float dist = distance(_LightPos.xyz, i.worldPos);
float attenuation = 1.0 / pow(dist, _Attenuation);
float falloff = pow(dot(ray, normalize(spread)), 4);
float4 col = tex2D(_MainTex, i.uv) * _Color;
col.rgb *= attenuation * falloff * _Intensity;
return col;
}
ENDCG
}
}
FallBack "Diffuse"
}
```
5. Anamorphic Lens Flare Shader:
```
Shader "Custom/AnamorphicLensFlareShader" {
Properties {
_MainTex ("Texture", 2D) = "white" {}
_Color ("Color", Color) = (1,1,1,1)
_Threshold ("Threshold", Range(0,1)) = 0.5
_Brightness ("Brightness", Range(0,10)) = 1
_HaloSize ("Halo Size", Range(0,1)) = 0.5
_HaloSoftness ("Halo Softness", Range(0,1)) = 0.5
_Distortion ("Distortion", Range(-1,1)) = 0.1
_Anamorphism ("Anamorphism", Range(0,1)) = 0.5
}
SubShader {
Tags {"Queue"="Transparent" "RenderType"="Transparent"}
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata {
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f {
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float4 _Color;
float _Threshold;
float _Brightness;
float _HaloSize;
float _HaloSoftness;
float _Distortion;
float _Anamorphism;
v2f vert (appdata v) {
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target {
float4 col = tex2D(_MainTex, i.uv) * _Color;
float dist = distance(i.uv, float2(0.5,0.5));
float falloff = smoothstep(_Threshold, _Threshold + 0.01, dist);
col.rgb *= pow(falloff, _Brightness);
float2 distortion = i.uv - float2(0.5,0.5);
distortion *= float2(1.0 + _Distortion * falloff, 1.0 + _Distortion * falloff * _Anamorphism);
col.rgb = tex2D(_MainTex, i.uv + distortion * _HaloSize * falloff).rgb;
float halo = smoothstep(_HaloSize, _HaloSize + _HaloSoftness, dist);
col.rgb += halo * _Color.rgb;
return col;
}
ENDCG
}
}
FallBack "Diffuse"
}
```
阅读全文