SAIMA/Assets//Shader/模糊/GaussianBlur.shader
GrassTE 159cfd8881 制作部分特效
1.创建了个人文件夹,复制了部分场景。
2.编写了URP的屏幕后特效框架。
3.制作了一个场景内模拟树叶飘落的粒子,增加一些场景内的动感。

4.制作了几个Shader
1)利用2D的顶点着色器制作了一个边缘扭曲的Shader可以用在飘落树叶上,模拟3D树叶翻飞的感觉。
2)制作了溶解的Shader,建议用在可破坏的障碍上。
3)制作了一个闪光的Shader,可以用在障碍物上突出障碍物,但是Shader还需修改,现在太违和了。

TODO:做了一半昼夜交替的效果,这也是忘了哪个老师的建议说可以加入一个太阳在运动,效果大概可以用灯光来做,目前测试的颜色变化是B先减弱15%,G减弱20%,然后B回升R减弱。

ps:我的拓展坞不见了接不了手柄,需要等明天到货后开发动起来的特效,这个键盘操作太脑檀了,我不认为普通人可以顺畅的两只手同方向依次按键还不会乱。

建议:
建议为可破坏的障碍物添加提前消失的机制,现在如果冲撞力度不大,碎块只会破碎不会分离,但碰撞体会关闭,很奇怪,建议使用Shader让其破碎后消失。(但是溶解消失的shader与游戏风格不搭,也可以给碎块一个右的力,做一个击飞效果)
2022-08-21 03:44:34 +08:00

115 lines
5.2 KiB
GLSL
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Shader "Unlit/GaussianBlur"
{
//
//                                                   
//                                      
//                
//                                  
//                            
//                           
//                                     
//                         
//                           
//                             
//                                    
//                            
//                                       
//                                                                                                                      
Properties
{
_MainTex ("Texture", 2D) = "white" {} //基础贴图
_BlurRadius ("BlurRadius", Range(2, 15)) = 5 //模糊半径
_TextureSize ("TextureSize", Float) = 640
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
int _BlurRadius;
float _TextureSize;
float GetGaussWeight(float x, float y, float sigma)
{
float sigma2 = pow(sigma, 2.0f); //pow 次方公式 这里是平方
float left = 1 / (2 * sigma2 * 3.1415926f);
float right = exp(-(x*x+y*y)/(2*sigma2)); //e的指数幂
return left * right;
}
fixed4 GaussBlur(float2 uv) //高斯模糊 根据高斯公式计算出的颜色值
{
float sigma = (float)_BlurRadius / 3.0f;//权重
float4 col = float4(0, 0, 0, 0);
for (int x = - _BlurRadius; x <= _BlurRadius; ++x)
{
for (int y = - _BlurRadius; y <= _BlurRadius; ++y)
{
//获取周围像素的颜色
//转为uv上的坐标值
float4 color = tex2D(_MainTex, uv + float2(x / _TextureSize, y / _TextureSize));
//获取此像素的权重
float weight = GetGaussWeight(x, y, sigma);
//计算此点的最终颜色
col += color * weight; //颜色乘以权重
}
}
return col;
}
fixed4 SimpleBlur(float2 uv)
{
float4 col = float4(0, 0, 0, 0);
for (int x = - _BlurRadius; x <= _BlurRadius; ++x)
{
for (int y = - _BlurRadius; y <= _BlurRadius; ++y)
{
float4 color = tex2D(_MainTex, uv + float2(x / _TextureSize, y / _TextureSize));
col += color;
}
}
//取平均数,所取像素为边长为(半径*2+1)的矩阵
col = col / pow(_BlurRadius * 2 + 1, 2.0f);
return col;
}
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float4 col = SimpleBlur(i.uv);
return col;
}
ENDCG
}
}
}