今天,学会怎么使用后处理来处理效果了。就像第一视角的迷雾效果,寂静岭那样满世界的白色雾气效果,可以简单的使用后处理的方式来实现一个。效果就如下面:

这里重点是我们如何使用后处理来打到这样的效果。简单点就是我们需要创建一个MonoBehaviour脚本,然后响应OnRenderImage方法
private void OnRenderImage(RenderTexture source, RenderTexture destination)
第一个参数是当前屏幕的纹理,就是自动会输入进来的参数,第二个参数是我们需要进过一些列处理只会输出的纹理。后处理的过程就是处理source的过程。其中我们能使用Graphics.Blit函数使用一个材质去处理这个纹理。
Graphics.Blit(source, destination, mat);
材质中就是我们自己写的Shader来进行处理了。
private void OnRenderImage(RenderTexture source, RenderTexture destination)
{
if(mat != null)
{
mat.SetColor("_Color", color);
mat.SetFloat("_Depth", depth);
mat.SetFloat("_Mul", mul);
Graphics.Blit(source, destination, mat);
}
else
{
Graphics.Blit(source, destination);
}
}
这里生成迷雾的效果是使用了深度纹理,当深度纹理大于一个阈值就会混合一个颜色,深度越大,混合的颜色透明度就越高。下面是简单的Shader:
Shader "Custom/PostFogDepth"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Color("Color",Color) = (1,1,1,1)
_Depth("Depth",Range(0,1)) = 0.5
_Mul ("Mul",Float) = 1
}
SubShader
{
//Cull Off ZWrite On ZTest Always
Tags { "RenderType" = "Opaque" }
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;
sampler2D _CameraDepthTexture;
fixed _Depth;
fixed4 _Color;
half _Mul;
fixed4 frag(v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
//fixed4 col = fixed4(0,0,0,1);
fixed d = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.uv));
fixed f = max(d - _Depth, 0);
if (f > 0)
{
col.rgb = col.rgb*(1 - min(f * _Mul,1)) + _Color.rgb * min(f* _Mul,1);
}
return col;
}
ENDCG
}
}
}
由于摄像机的Far很远,所以深度的变化很细微,所以我这里使用了一个_Mul的参数,目的就是扩大这细微的变化。但是应该有更好的变化曲线,我这里只是简单的学习,简单的倍放已经足够了。
附上完整的CS代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PostFog : MonoBehaviour
{
public Material mat;
public Color color;
public float depth;
public float mul;
// Start is called before the first frame update
void Start()
{
GetComponent<Camera>().depthTextureMode = DepthTextureMode.Depth;
}
private void OnRenderImage(RenderTexture source, RenderTexture destination)
{
if(mat != null)
{
mat.SetColor("_Color", color);
mat.SetFloat("_Depth", depth);
mat.SetFloat("_Mul", mul);
Graphics.Blit(source, destination, mat);
}
else
{
Graphics.Blit(source, destination);
}
}
}
zmozeroteriloren
I truly appreciate this post. I?¦ve been looking everywhere for this! Thank goodness I found it on Bing. You’ve made my day! Thanks again
Kwivsibly
hi opp ggeis 2022 ert go fi
zmozeroteriloren
Hi! Do you know if they make any plugins to protect against hackers? I’m kinda paranoid about losing everything I’ve worked hard on. Any suggestions?
enviple
letrozole vs clomid 1996; 13 4 283 93
joyboanny
Results showed that mRNA levels of MAFbx also known as Atrogin 1 and MUSA1, but not MuRF1 or Nedd4, were significantly increased in the skeletal muscle of Tak1 mKO mice compared with Tak1 fl fl mice Figure 3I does a higher dose of viagra work better Let s just take one study an example, whose abstract concluded that
actiole
I m really posting all this for anyone who comes along with the same issue I have nolvadex Transvaginal US is now considered the primary imaging modality for the diagnosis of adenomyosis, and thus radiologists should be familiar with its sonographic appearance
imPetly
Ważne jest, aby gracz w pełni spełnił wymagania dotyczące premii przed utworzeniem żądania wypłaty, w przeciwnym razie konto może podlegać różnym sankcjom ze strony kasyna. Należy również wziąć pod uwagę, że niektóre kasyna ograniczają metody wypłaty środków poprzez metody, za pomocą których dokonano wpłaty. Uwaga: to pierwsza na świecie ruletka z wygraną! W końcu bez względu na to, jaki zakład postawisz, bez względu na to, jak krupier rzuci ciężką, krnąbrną piłkę, jednym słowem, bez względu na okoliczności, w każdym razie otrzymasz główną nagrodę – kieliszek doskonałego trunku. I tak cały wieczór, podczas gdy przynajmniej ktoś inny jest w stanie stanąć na nogach! Uwaga: to pierwsza na świecie ruletka z wygraną! Wszakże bez względu na to, jaki zakład postawisz, bez względu na to, jak krupier rzuci ciężką, krnąbrną piłkę, jednym słowem, bez względu na to, jak rozwiną się okoliczności, w każdym razie otrzymasz główną nagrodę – kieliszek doskonałego trunku. I tak cały wieczór, póki przynajmniej ktoś inny jest w stanie stanąć na nogach! https://beauqoha109875.oblogation.com/16407840/tychy-kasyno Popularne godziny na podstawie wizyt w tym miejscu RozwińUkryj Osoby, które są zainteresowane pracą na stanowisku infobrokera, muszą się do tego zawodu odpowiednio przygotować. Czy możliwe jest zdobycie wyższego wykształcenia w tym zawodzie? Jak najbardziej. Na II stopniu kierunku Informacji Naukowej i Bibliotekoznawstwa/Bibliologii nierzadko otwierane są specjalizacje, które przygotowują do wykonywania zawodu brokera informacji. Dodatkowo kształcić się można także na kierunkach studiów podyplomowych. Historia krzewienia się hazardu w Polsce sięga początku XX wieku, albowiem pierwsze kasyno hazardowe zostało założone w 1920 roku w Sopocie. Swoją siedzibę miało w hotelu Grand, a funkcjonuje ono po dziś dzień. Owo kasyno do wybuchu II Wojny Światowej było jednym z najpopularniejszych w kraju i w Europie. Niestety, ale wybuch wojny przerwał dobre prosperity dla branży hazardowej w Polsce.
fountee
can you get accutane in canada In late 2009, there was a firestorm over an independent panel s recommendation now very much contested that women in their forties should stop having mammograms, and women fifty to seventy four should have one only every other year
How to Write a Business Plan for a Collars For Men And Boys Business
Hello my family member! I wish to say that this post is awesome, nice written and include almost all vital infos. I¦d like to look more posts like this .
Cicaimb
domestic conditions were the most important factor in the decision propecia for sale in usa
Beginners Guide Book to See List of Japanese martial arts (Learning Martial Arts - Volume 1)
My coder is trying to convince me to move to .net from PHP. I have always disliked the idea because of the costs. But he’s tryiong none the less. I’ve been using Movable-type on various websites for about a year and am anxious about switching to another platform. I have heard good things about blogengine.net. Is there a way I can transfer all my wordpress content into it? Any kind of help would be really appreciated!
The Best Places to Take Photos in Yangon (Myanmar)
Do you have a spam problem on this website; I also am a blogger, and I was wondering your situation; we have developed some nice procedures and we are looking to swap strategies with others, be sure to shoot me an e-mail if interested.
Top Places to own a Vacation Home in Xiaogan (China)
Hi, i think that i saw you visited my web site so i came to “return the favor”.I’m attempting to find things to improve my website!I suppose its ok to use a few of your ideas!!
Top Places to See in Yerevan (Armenia)
Your place is valueble for me. Thanks!…
How to Write a Business Plan for a Polish Business
F*ckin¦ awesome things here. I am very glad to look your article. Thanks so much and i am having a look forward to touch you. Will you kindly drop me a mail?
Top Places to Honeymoon in Oran (Algeria)
I¦ll right away seize your rss feed as I can not to find your e-mail subscription hyperlink or e-newsletter service. Do you’ve any? Please let me recognise in order that I may just subscribe. Thanks.
The Best Neighbourhoods to live in Ulaanbaatar (Mongolia)
Very wonderful info can be found on web site.
Ultimate Music Guide to Death Metal/Black Metal
you’re really a good webmaster. The web site loading velocity is amazing. It seems that you’re doing any distinctive trick. Moreover, The contents are masterpiece. you’ve done a wonderful process on this subject!
Learning and Understanding about AIDS dysmorphic syndrome Disease (Volume 1)
I¦ve recently started a blog, the info you offer on this site has helped me greatly. Thank you for all of your time & work.
Vincze Andrea fodrász Nyíregyháza
Wow, amazing blog layout! How long have you been blogging for? you make blogging look easy. The overall look of your website is wonderful, as well as the content!
How to Start a Post-harvest Crop Business (Beginners Guide)
I’m still learning from you, but I’m trying to achieve my goals. I definitely enjoy reading everything that is posted on your site.Keep the posts coming. I liked it!
The Best Places to Study in Lichuan (China)
It¦s actually a nice and useful piece of information. I am happy that you shared this helpful info with us. Please keep us up to date like this. Thank you for sharing.
The Best Places to Retire in Qingdao (China)
Would you be enthusiastic about exchanging hyperlinks?
Handbook Guide to a Lloyd - 650 (Classic Handbook Car Guide)
Hiya very nice blog!! Man .. Excellent .. Amazing .. I’ll bookmark your web site and take the feeds also…I am glad to search out so many useful info here within the publish, we’d like work out more strategies on this regard, thank you for sharing.
Learning and Understanding about Myopathy, desmin storage Disease (Volume 1)
I view something genuinely special in this internet site.
Learning and Understanding about Gigantism partial, nevi, hemihypertrophy, macrocephaly Disease (Volume 1)
I like what you guys are up also. Such intelligent work and reporting! Keep up the excellent works guys I?¦ve incorporated you guys to my blogroll. I think it’ll improve the value of my website 🙂
How to Become a Stock Sheets Cleaner-inspector
you may have an incredible weblog here! would you prefer to make some invite posts on my weblog?
https://g.co/kgs/Vq96zj
I don’t usually comment but I gotta tell regards for the post on this amazing one : D.
Jrnaquamilip
cialis para que sirve cialis deliver next day does tadalafil work
Knnfsibly
buy cialis toronto tadalafil blood pressure cheap cialis canadian
QuuMaype
how long does tadalafil take to work tadalafil 5 mg brands in india overnight pharmacy 4u cialis
Wooladoms
viagra fast shipping buying viagra from canada viagra online united states
Jdnsadoms
cialis canadian pharmacy ezzz generic cialis from india us online cialis
TnntMaype
how fast does cialis work cialis ads cialis side effects forum
EbxdMaype
sildenafil cost india viagra paypal online canadian pharmacy prescription viagra
AvxeGlync
viagra tablets in india online sildenafil 100mg price usa viagra pills online south africa
Jbqaquamilip
allegra pharmacy prices top rated online canadian pharmacies voltaren canadian pharmacies
Woroladoms
publix pharmacy augmentin levitra coupons pharmacy cheapest pharmacy for vicodin
TujMaype
which online pharmacy is the best costco pharmacy finasteride forum online pharmacy viagra
Jnebadoms
which pharmacy has green xanax best online pharmacy for viagra review oxycodone mexican pharmacy
GADLELO
A consistent gauge length was used throughout the test buy generic lasix online
Trounse
8 billion of debt in the first threequarters of the year, with newcomer Build America MutualAssurance Co priligy equivalent Weight Regul
smiccaday
buy accutane from canada Ask for the minimum you need to meet your goal, plus 10 to 20 more for unforeseen expenses
Jemtaquamilip
the effects that viagra and cialis have on women were can i buy cialis cialis cheap
Kensibly
sildenafil otc uk online real viagra viagra online prescription canada
fiehymn
buy cialis generic The initial dose for all subjects was 1 tablet per day continued through day 2 of the next cycle
EexdMaype
canada pharmacy delivery tesco pharmacy doxycycline victoza canadian pharmacy
AmvtGlync
viagra from lloyds pharmacy best drugstore face moisturizer canadian prescriptions
Wmgladoms
buy sildenafil with paypal sildenafil generic 100 mg best pharmacy prices for viagra
Dribiosse
Veins Histology comprare cialis online de; CRC 1080 and the Gatsby Charitable Foundation www
pippeferi
And that daytime shooting star is 219 high for blood sugar was also a guide given by control your blood sugar and be stars killed in plane crashes the gods to Zhao Ling buy zithromax 500mg
Jmeuadoms
viagra generic without prescription over the counter viagra in us sildenafil 20 mg tablet cost
TnfxMaype
sanofi cialis where can i buy cialis in singapore can you take cialis and viagra at the same time
Emereaw
Why do doctors prescribe Flomax cialis generic de Jesus Leite MAF, Puga GM, Arantes FJ, Oliveira CJF, Cunha LM, Bortolini MJS, Penha Silva N
QnwrMaype
cheapest cialis 20 mg tadalafil pills order cialis from canada
Knrsibly
can you take viagra and cialis together cialis generico splitting cialis
Jrnxaquamilip
generic tadalafil tablet or pill photo or shape 20 mg tadalafil tadalafil discounts
EhdMaype
buy viagra mastercard buy sildenafil online cheap viagra price in india online
Wdbladoms
new york cialis sildenafil viagra vardenafil levitra and tadalafil cialis tadalafil pills online
Jdnvadoms
when to take tadalafil cialis for entertainment purposes costco cialis
TmrbMaype
cialis tabs how long does tadalafil take to work best price cialis supper active
QjerMaype
what is better viagra or cialis where to get generic cialis without prescription cheap cialis pills
ThwMaype
cialis otc usa cialis overnight online tadalafil on a urinalysis
AmrbGlync
how much is viagra australia canadian pharmacy viagra 100 mg price of 50 mg viagra
EhdMaype
order viagra online us viagra generic sale buy viagra us pharmacy
Wdbladoms
cheapest generic cialis australia viagra vs cialis reviews what is cialis taken for
Jdnvadoms
tadalafil generic 5mg cialis for sale online in canada cialis sale online
pippeferi
a pathologist, who examines biopsy samples and conducts special tests on cancer tissue to determine the cancer s characteristics, such as its hormone receptor status and HER2 status purchase stromectol online