当前位置:网站首页>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
边栏推荐
- 第 2 篇:繪制一個窗口
- Notes on the use of date and time base
- 火线,零线,地线,你知道这三根线的作用是什么吗?
- Inline element, block element, inline block element
- 云开发谁是卧底小程序源码
- Cloud development who is the source code of undercover applet
- 软件工程导论——第二章——可行性研究
- Jenkins is too old try it? Cloud native ci/cd Tekton
- Domain environment importing Tencent cloud considerations
- 宝塔面板安装php7.2安装phalcon3.3.2
猜你喜欢

Graphmae - - lecture rapide des documents

Svn actual measurement common operation record operation

【资料上新】迅为基于3568开发板的NPU开发资料全面升级

第 3 篇:绘制三角形

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

SVN实测常用操作-记录操作大全

2022 PMP project management examination agile knowledge points (1)

SCM stm32f103rb, BLDC DC motor controller design, schematic diagram, source code and circuit scheme

关于h5页面苹果手机使用fixed定位tabbar最底部时遮挡内容问题

Oracle advanced SQL qualified query
随机推荐
AWTK 最新动态:Grid 控件新用法
Thread considerations
Do you still have the opportunity to become a machine learning engineer without professional background?
BOM notes
The describeregion interface of CVM is special and has two versions
The monthly salary of two years after graduation is 36K. It's not difficult to say
Smart pointer remarks
Domain environment importing Tencent cloud considerations
Duilib display memory picture
Atguigu---15- built in instruction
Echart's experience (I): about y axis yaxis attribute
Error "computing failed in `stat\u summary\u hex() `"
Any remarks
2022 PMP project management examination agile knowledge points (1)
Thread blocking
Chapter 1 overview of canvas
10. Tencent cloud IOT device side learning - firmware upgrade
. No main manifest attribute in jar
Keep one decimal place and two decimal places
.jar中没有主清单属性