碧血红天的HomePage

U3d杂谈 — 简单使用后处理

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

这里重点是我们如何使用后处理来打到这样的效果。简单点就是我们需要创建一个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);
        }
    }
}

68 评论

  1. 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

  2. hi opp ggeis 2022 ert go fi

  3. 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?

  4. 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

  5. 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

  6. 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.

  7. 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

  8. 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 .

  9. domestic conditions were the most important factor in the decision propecia for sale in usa

  10. 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!

  11. 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.

  12. 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!!

  13. 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?

  14. 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.

  15. 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!

  16. 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.

  17. 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!

  18. 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!

  19. 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.

  20. Would you be enthusiastic about exchanging hyperlinks?

  21. 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.

  22. 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 🙂

  23. you may have an incredible weblog here! would you prefer to make some invite posts on my weblog?

  24. I don’t usually comment but I gotta tell regards for the post on this amazing one : D.

  25. cialis para que sirve cialis deliver next day does tadalafil work

  26. buy cialis toronto tadalafil blood pressure cheap cialis canadian

  27. how long does tadalafil take to work tadalafil 5 mg brands in india overnight pharmacy 4u cialis

  28. viagra fast shipping buying viagra from canada viagra online united states

  29. cialis canadian pharmacy ezzz generic cialis from india us online cialis

  30. how fast does cialis work cialis ads cialis side effects forum

  31. sildenafil cost india viagra paypal online canadian pharmacy prescription viagra

  32. viagra tablets in india online sildenafil 100mg price usa viagra pills online south africa

  33. allegra pharmacy prices top rated online canadian pharmacies voltaren canadian pharmacies

  34. publix pharmacy augmentin levitra coupons pharmacy cheapest pharmacy for vicodin

  35. which online pharmacy is the best costco pharmacy finasteride forum online pharmacy viagra

  36. which pharmacy has green xanax best online pharmacy for viagra review oxycodone mexican pharmacy

  37. A consistent gauge length was used throughout the test buy generic lasix online

  38. 8 billion of debt in the first threequarters of the year, with newcomer Build America MutualAssurance Co priligy equivalent Weight Regul

  39. buy accutane from canada Ask for the minimum you need to meet your goal, plus 10 to 20 more for unforeseen expenses

  40. the effects that viagra and cialis have on women were can i buy cialis cialis cheap

  41. sildenafil otc uk online real viagra viagra online prescription canada

  42. buy cialis generic The initial dose for all subjects was 1 tablet per day continued through day 2 of the next cycle

  43. canada pharmacy delivery tesco pharmacy doxycycline victoza canadian pharmacy

  44. viagra from lloyds pharmacy best drugstore face moisturizer canadian prescriptions

  45. buy sildenafil with paypal sildenafil generic 100 mg best pharmacy prices for viagra

  46. Veins Histology comprare cialis online de; CRC 1080 and the Gatsby Charitable Foundation www

  47. 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

  48. viagra generic without prescription over the counter viagra in us sildenafil 20 mg tablet cost

  49. sanofi cialis where can i buy cialis in singapore can you take cialis and viagra at the same time

  50. Why do doctors prescribe Flomax cialis generic de Jesus Leite MAF, Puga GM, Arantes FJ, Oliveira CJF, Cunha LM, Bortolini MJS, Penha Silva N

  51. cheapest cialis 20 mg tadalafil pills order cialis from canada

  52. can you take viagra and cialis together cialis generico splitting cialis

  53. generic tadalafil tablet or pill photo or shape 20 mg tadalafil tadalafil discounts

  54. buy viagra mastercard buy sildenafil online cheap viagra price in india online

  55. cialis otc usa cialis overnight online tadalafil on a urinalysis

  56. how much is viagra australia canadian pharmacy viagra 100 mg price of 50 mg viagra

  57. order viagra online us viagra generic sale buy viagra us pharmacy

  58. cheapest generic cialis australia viagra vs cialis reviews what is cialis taken for

  59. 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

发表评论