当前位置:网站首页>简单的折射效果
简单的折射效果
2022-06-24 06:43:00 【Kenight_】
通过 GrabPass 实现
Shader "Unlit/Glass"
{
Properties
{
_BumpAmt ("Distortion", Range (0,100)) = 10
_TintAmt ("Tint Amount", Range(0,1)) = 0.1
_BlurAmt ("Blur Amount", Range (0,1)) = 0.1
_MainTex ("Texture", 2D) = "white" {}
_BumpMap ("Normal Map", 2D) = "bump" {}
}
SubShader
{
Tags { "Queue" = "Transparent" } // 重要:使用透明队列保障其他物体已绘制在屏幕上
GrabPass { "_GrabBlurTexture" }
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 uv : TEXCOORD0;
float4 grabPos : TEXCOORD1;
float4 vertex : SV_POSITION;
};
float _BumpAmt;
float _TintAmt;
float _BlurAmt;
sampler2D _MainTex, _BumpMap;
float4 _MainTex_ST, _BumpMap_ST;
sampler2D _GrabBlurTexture;
float4 _GrabBlurTexture_TexelSize; // texture size, x:1.0/width y:1.0/height z:width w:height
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv.xy = TRANSFORM_TEX(v.uv, _MainTex);
o.uv.zw = TRANSFORM_TEX(v.uv, _BumpMap);
o.grabPos = ComputeGrabScreenPos(o.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// 从 normalmap 中采样出凹凸值
float2 bump = UnpackNormal(tex2D(_BumpMap, i.uv.zw)).xy;
// 偏移量(*_TexelSize.xy 的意义是偏移值按抓取的纹理的单位像素进行缩放)
float2 offset = bump * _BumpAmt * _GrabBlurTexture_TexelSize.xy;
i.grabPos.xy = offset + i.grabPos.xy;
fixed4 col = tex2D(_GrabBlurTexture, i.grabPos.xy / i.grabPos.w); // 除以 w 后得到屏幕空间采样坐标
// blur (这是一个比较垃圾的模糊效果)
float blur = _BlurAmt / 100;
col += tex2D(_GrabBlurTexture, grabuv + float2(-blur, 0));
col += tex2D(_GrabBlurTexture, grabuv + float2(blur, 0));
col += tex2D(_GrabBlurTexture, grabuv + float2(0, blur));
col += tex2D(_GrabBlurTexture, grabuv + float2(0, -blur));
col = col / 5;
fixed4 tint = tex2D(_MainTex, i.uv.xy);
col = lerp (col, tint, _TintAmt);
return col;
}
ENDCG
}
}
}通过 Command Buffers 实现
// 使用 command buffer 来生成 RT
public class ComdBuf : MonoBehaviour
{
// 在摄像机渲染之前执行
void OnWillRenderObject()
{
var cam = Camera.current;
CommandBuffer buff = new CommandBuffer();
// 申请 RT
int rtID = Shader.PropertyToID("_GrabBlurTexture");
buff.GetTemporaryRT(rtID, -1, -1, 0, FilterMode.Bilinear); // -1 for camera pixel width or height
// blit 方法接受 RT 的标识符 RenderTargetIdentifier (即 rtID)
buff.Blit(BuiltinRenderTextureType.CurrentActive, rtID); // 将当前渲染 RT 复制给 rtID
// 通过该命令使在 shader 中可通过 sampler2D _GrabBlurTexture 取得该 RT
buff.SetGlobalTexture(rtID, rtID); // 第一个参数是 shader 中的变量名,第二个是名称所标识的 RT
// 执行时机
cam.AddCommandBuffer(CameraEvent.AfterSkybox, buff);
}
}接着可使用上面的 Shader 并去掉 GrabPass { “_GrabBlurTexture” } 即可达到一样的效果
边栏推荐
- [GUET-CTF2019]zips
- Tutorial on simple use of Modbus to BACnet gateway
- A summary of the posture of bouncing and forwarding around the firewall
- jarvisoj_ level2
- buuctf misc [UTCTF2020]docx
- Obtain the package name, application name, icon, etc. of the uninstalled APK through packagemanager. There is a small message
- Lend you a pair of insight, Frida native trace
- [WUSTCTF2020]alison_ likes_ jojo
- [pointnet] matlab simulation of 3D point cloud target classification and recognition based on pointnet
- 【WordPress建站】5. 设置代码高亮
猜你喜欢

get_started_3dsctf_2016

How to delete / select an input method on your computer

MaxCompute远程连接,上传、下载数据文件操作
![[pointnet] matlab simulation of 3D point cloud target classification and recognition based on pointnet](/img/86/5db689cdac2a927a23dff3fb9594b0.png)
[pointnet] matlab simulation of 3D point cloud target classification and recognition based on pointnet

bjdctf_2020_babystack

Description of module data serial number positioning area code positioning refers to GBK code

How can win11 set the CPU performance to be fully turned on? How does win11cpu set high performance mode?

Only two lines are displayed, and the excess part is displayed with Ellipsis

bjdctf_2020_babystack

Face pincher: a hot meta universe stylist
随机推荐
2.1.1 QML grammar foundation I
第三方软件测试公司如何选择?2022国内软件测试机构排名
How can win11 set the CPU performance to be fully turned on? How does win11cpu set high performance mode?
Deploy loglistener in tke container to collect logs to CLS
Global and Chinese market of basketball uniforms 2022-2028: Research Report on technology, participants, trends, market size and share
[wustctf2020] climb
Obtain the package name, application name, icon, etc. of the uninstalled APK through packagemanager. There is a small message
Combine with (& &) logic or (||), dynamic binding and ternary operation
[equalizer] bit error rate performance comparison simulation of LS equalizer, def equalizer and LMMSE equalizer
PCL calculates the area of a polygon
The fund management of London gold is more important than others
MySQL case: analysis of full-text indexing
Win10 build webservice
[cnpm] tutorial
The initial user names and passwords of Huawei devices are a large collection that engineers involved in Huawei business should keep in mind and collect!
二分专题训练
[DDCTF2018](╯°□°)╯︵ ┻━┻
Summary of 2022 blue team HW elementary interview questions
What is a CC attack? How to judge whether a website is attacked by CC? How to defend against CC attacks?
【TS】函数类型