当前位置:网站首页>Simple refraction effect
Simple refraction effect
2022-06-24 08:04:00 【Kenight_】
adopt GrabPass Realization
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" } // important : Use transparent queues to ensure that other objects are drawn on the screen
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
{
// from normalmap The bump value is sampled from
float2 bump = UnpackNormal(tex2D(_BumpMap, i.uv.zw)).xy;
// Offset (*_TexelSize.xy The offset value is scaled according to the unit pixel of the captured texture )
float2 offset = bump * _BumpAmt * _GrabBlurTexture_TexelSize.xy;
i.grabPos.xy = offset + i.grabPos.xy;
fixed4 col = tex2D(_GrabBlurTexture, i.grabPos.xy / i.grabPos.w); // Divide w The screen space sampling coordinates are obtained
// blur ( This is a more garbage blur effect )
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
}
}
}adopt Command Buffers Realization
// Use command buffer To generate RT
public class ComdBuf : MonoBehaviour
{
// Execute... Before camera rendering
void OnWillRenderObject()
{
var cam = Camera.current;
CommandBuffer buff = new CommandBuffer();
// apply RT
int rtID = Shader.PropertyToID("_GrabBlurTexture");
buff.GetTemporaryRT(rtID, -1, -1, 0, FilterMode.Bilinear); // -1 for camera pixel width or height
// blit Method acceptance RT Identifier RenderTargetIdentifier ( namely rtID)
buff.Blit(BuiltinRenderTextureType.CurrentActive, rtID); // Render the current RT Copy to rtID
// Use this command to make the shader Pass through sampler2D _GrabBlurTexture Get the right RT
buff.SetGlobalTexture(rtID, rtID); // The first parameter is shader Variable name in , The second is what the name identifies RT
// Execution opportunity
cam.AddCommandBuffer(CameraEvent.AfterSkybox, buff);
}
}You can then use the... Above Shader And get rid of it. GrabPass { “_GrabBlurTexture” } You can achieve the same effect
边栏推荐
- Chapitre 2: dessiner une fenêtre
- Vulnhub target: boredhackerblog: social network
- Practice of opengauss database on CentOS, configuration
- GraphMAE----论文快速阅读
- Any remarks
- Chapter 1 overview of canvas
- 站在风暴中心:如何给飞奔中的腾讯更换引擎
- Case examples of corpus data processing (cases related to sentence retrieval)
- Using kubeconfig files to organize cluster access
- [test development] first knowledge of software testing
猜你喜欢

Graphmae - - lecture rapide des documents
![[data update] Xunwei comprehensively upgraded NPU development data based on 3568 development board](/img/10/6725b51120a6ae8b16d60f5b1ae904.jpg)
[data update] Xunwei comprehensively upgraded NPU development data based on 3568 development board

基于Distiller的模型压缩工具简介

解决错误: LNK2019 无法解析的外部符号

Signature analysis of app x-zse-96 in a Q & a community

Selenium IDE的安装以及使用

快速读论文----AD-GCL:Adversarial Graph Augmentation to Improve Graph Contrastive Learning

First acquaintance with JUC - day01

从 jsonpath 和 xpath 到 SPL

模型效果优化,试一下多种交叉验证的方法(系统实操)
随机推荐
Jenkins 太老了 试试它?云原生 CI/CD Tekton
Thread blocking
Random number remarks
Chapter 3 curve graph of canvas
What kind of experience is it when the Institute earns 20000 yuan a month!
Any remarks
Oracle advanced SQL qualified query
4-操作列表(循环结构)
面试中的最常被问到的两种锁
The describeregion interface of CVM is special and has two versions
毕业两年月薪36k,说难也不难吧
Hilbert Huang Transform
一文理解同步FIFO
L1-019 who goes first (15 points)
Basics of reptile B1 - scrapy (learning notes of station B)
保留一位小数和保留两位小数
语料库数据处理个案实例(读取多个文本文件、读取一个文件夹下面指定的多个文件、解码错误、读取多个子文件夹文本、多个文件批量改名)
POM configuration provided and test
How to cancel the display of the return button at the uniapp uni app H5 end the autobackbutton does not take effect
Part 1: building OpenGL environment