当前位置:网站首页>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
边栏推荐
- First acquaintance with JUC - day01
- ImportError: cannot import name ‘process_pdf‘ from ‘pdfminer.pdfinterp‘错误完全解决
- Vulnhub靶机:BOREDHACKERBLOG: SOCIAL NETWORK
- 单片机STM32F103RB,BLDC直流电机控制器设计,原理图、源码和电路方案
- Chapter 4 line operation of canvas
- Smart pointer remarks
- L1-019 谁先倒 (15 分)
- [data update] Xunwei comprehensively upgraded NPU development data based on 3568 development board
- Atguigu---15- built in instruction
- Experience of Shenzhou computer
猜你喜欢

Oracle-高级SQL限定查询

First acquaintance with JUC - day01

Gossip: what happened to 3aC?

Vulnhub靶机:BOREDHACKERBLOG: SOCIAL NETWORK

Error:Kotlin: Module was compiled with an incompatible version of Kotlin. The binary version of its

The two most frequently asked locks in the interview

AWTK 最新动态:Grid 控件新用法

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

Graphmae ---- quick reading of papers

Chapter 3: drawing triangles
随机推荐
没有专业背景,还有机会成为机器学习工程师吗?
How to cancel the display of the return button at the uniapp uni app H5 end the autobackbutton does not take effect
[special session] SME growth plan - ECS special session
Configure your own free Internet domain name with ngrok
Free ICP domain name filing interface
Graphmae ---- quick reading of papers
快速读论文----AD-GCL:Adversarial Graph Augmentation to Improve Graph Contrastive Learning
调用Feign接口时指定ip
第 2 篇:绘制一个窗口
Open cooperation and win-win future | Fuxin Kunpeng joins Jinlan organization
IndexError: Target 7 is out of bounds.
慕思股份在深交所上市:毛利率持续下滑,2022年一季度营销失利
软件工程导论——第三章——需求分析
Introduction of model compression tool based on distiller
What is the lifecycle of automated testing?
Case examples of corpus data processing (cases related to sentence retrieval)
The two most frequently asked locks in the interview
Part 1: building OpenGL environment
语料库数据处理个案实例(句子检索相关个案)
[008] filter the table data row by row, jump out of the for cycle and skip this cycle VBA