当前位置:网站首页>[unity rendering] customized screen post-processing
[unity rendering] customized screen post-processing
2022-07-01 09:34:00 【True ghost 123】
Custom screen post-processing is not difficult , The steps are divided into two parts ,1. Set shaders and... For picture processing Shader;2. stay C# The code uses OnrenderImage Function to process the camera picture .
1. establish Shader And shaders
Use ImageEffect( Image effects ) Type of Shader.
Shader It should be named _MainTex Main texture of , For reception C# Method to pass in the screen image . Otherwise, it is impossible to perform post-processing .
What will be written shader Assign to the shader .
Here is a simple blur shader.
Shader "Hidden/Image_Fuzzy"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Offset("Offset", Range(0, 0.05)) = 0.02
}
SubShader
{
// No culling or depth
//Cull Off ZWrite Off ZTest Always
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
sampler2D _MainTex;
float _Offset;
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
// just invert the colors
//col.rgb = 1 - col.rgb;
fixed4 c1 = tex2D(_MainTex, i.uv - (_Offset, 0));
fixed4 c2 = tex2D(_MainTex, i.uv + (_Offset, 0));
fixed4 c3 = tex2D(_MainTex, i.uv + (0, _Offset));
fixed4 c4 = tex2D(_MainTex, i.uv - (0, _Offset));
return( col + c1 + c2 + c3 + c4) / 5;;
}
ENDCG
}
}
}
2. call C# in OnRenderImage Method
OnRenderImage Post processing effect . Called after all the rendering operations of the image have been completed .
This function allows you to process the final image using shader based filters , To modify the final image . source Render textures for incoming images .destination Texture the output result .
When the camera is attached with multiple image filters , They process the images in sequence according to the following methods : Pass the target of the first filter as the source to the next filter , And so on .
Material material;
void OnRenderImage(RenderTexture source, RenderTexture destination)
{
// Copy the source Render Texture to the destination,
// applying the material along the way.
Graphics.Blit(source, destination, material);
}
Graphics.Blit (Texture source, RenderTexture dest, Material mat, int pass= -1) function
Use shaders to copy the source texture to the target render texture .
source For the input image , Corresponding shader Medium _MainTex attribute , Fill in OnRenderImage Medium source that will do .
dest For the output image , Fill in OnRenderImage Medium destination that will do .
mat Materials used for post-treatment .
function Unity You can see the post-processing effect .
Be careful :1. with OnRenderImage Method , Need to hang to Camera Only on components can .
2.Shader It should be named _MainTex Main texture of , For reception C# Method to pass in the screen image . Otherwise, it is impossible to perform post-processing .
边栏推荐
- Solution of EPS image blur by latex insertion
- A 419 error occurred in the laravel postman submission form. July 6th, 2020 diary.
- Latex插入的eps图片模糊解决方法
- 【pytorch】nn.CrossEntropyLoss() 与 nn.NLLLoss()
- nacos服务配置和持久化配置
- 【pytorch学习】torch.device
- [ESP nanny level tutorial preview] crazy node JS server - Case: esp8266 + DHT11 +nodejs local service + MySQL database
- [ESP nanny level tutorial preview] crazy node JS server - Case: esp8266 + DS18B20 temperature sensor +nodejs local service + MySQL database
- Error org apache. catalina. core. StandardContext. FilterStart start filter exception
- Introduction to mt7628k eCos development
猜你喜欢

HMS Core音频编辑服务3D音频技术,助力打造沉浸式听觉盛宴

Simple load balancing with Nacos

Design and manufacture of simple digital display electronic scale
![delete和delete[]引发的问题](/img/d9/a1c3e5ce51ef1be366a973aa42d1f0.png)
delete和delete[]引发的问题

Construction of esp8266 FreeRTOS development environment

dotnet 控制台 使用 Microsoft.Maui.Graphics 配合 Skia 进行绘图入门
![[untitled]](/img/1a/e18918cc09db9b072759409a5f39a1.png)
[untitled]

队列的实现和应用

2.2 【pytorch】torchvision. transforms

【pytorch】softmax函数
随机推荐
【电赛训练】红外光通信装置 2013年电赛真题
电脑USB、HDMI、DP各种接口及速度
短路运算符惰性求值
[interview brush 101] linked list
【pytorch学习】torch.device
SQL学习笔记(02)——数据库表操作
谁拥有穿越周期的眼光?
2.3 [pytorch] data preprocessing torchvision datasets. ImageFolder
Mise en œuvre simple de l'équilibrage de la charge par nacos
Youqitong PE toolbox [vip] v3.7.2022.0106 official January 22 Edition
Microcomputer principle - bus and its formation
Reproduced Xray - cve-2017-7921 (unauthorized access by Hikvision)
[pytorch] softmax function
122. Thread class thread method summary; Why is the thread start method start () not run ()?
【ESP 保姆级教程 预告】疯狂Node.js服务器篇 ——案例:ESP8266 + MQ系列 + NodeJs本地服务 + MySql存储
SQL learning notes (02) - database table operation
队列的实现和应用
Implementation and application of queue
【pytorch】nn. Crossentropyloss() and nn NLLLoss()
集成积木报表报错 org.apache.catalina.core.StandardContext.filterStart 启动过滤器异常