欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Unity Shader實(shí)現(xiàn)2D游戲迷霧

 更新時(shí)間:2020年04月29日 11:23:03   作者:Emmmwzh  
這篇文章主要為大家詳細(xì)介紹了Unity Shader實(shí)現(xiàn)2D游戲迷霧,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Unity Shader實(shí)現(xiàn)2D游戲迷霧的具體代碼,供大家參考,具體內(nèi)容如下

先看效果吧。

我使用的是屏幕后處理效果,首先先去Photoshop做一張圖片如下,用畫筆點(diǎn)一個(gè)點(diǎn)就可以了,使用它來對攝像機(jī)截取的圖片進(jìn)行處理。

在攝像機(jī)上添加腳本文件

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class TestScript : MonoBehaviour
{
 [Range(0,3)]
 public float Lerp = 0;//使用它來調(diào)整可視區(qū)域的大小
 public Texture2D MaskTex;
 public Shader ScreanShader;
 public Material GetMaterial
 {
  get
  {
   if(_material ==null) _material = new Material(ScreanShader);
   return _material;
  }
 }
 private Material _material = null;
 //src是攝像機(jī)截取到的照片,dest是處理過的圖片
 void OnRenderImage(RenderTexture src, RenderTexture dest)
 {
  GetMaterial.SetTexture("_MainTex", src);
  GetMaterial.SetTexture("_MaskTex", MaskTex);
  GetMaterial.SetFloat("_Lerp", Lerp);
  Graphics.Blit(src, dest, GetMaterial);
 }
}

對應(yīng)的shader,思路就是把MaskTex的顏色翻轉(zhuǎn)一下然后直接乘上去就可以了,小數(shù)越乘越小,越小顏色越黑。

Shader "Wzhhh/MyShader2" {
 Properties{
 _MainTex("MainTex",2D) = "white"{}
 _MaskTex("MaskTex",2D) = "white"{}
 _Lerp("Lerp",Range(0,3)) = 1
 }
 SubShader{
 Pass{
 Tags{ "LightMode" = "ForwardBase" }
 
 CGPROGRAM
 #include "Lighting.cginc"
 #pragma vertex vert
 #pragma fragment frag
 sampler2D _MaskTex;
 sampler2D _MainTex;
 float4 _MainTex_ST;
 float _AlphaBase;
 float _Lerp;
 struct a2v {
 float4 vertex : POSITION;
 float2 texcoord : TEXCOORD0;
 };
 struct v2f {
 float4 pos : SV_POSITION;
 fixed2 uv : TEXCOORD0;
 };
 v2f vert(a2v i) {
 v2f o;
 o.pos = UnityObjectToClipPos(i.vertex);
 o.uv = TRANSFORM_TEX(i.texcoord, _MainTex);
 return o;
 }
 fixed4 frag(v2f o) :SV_TARGET{
 fixed4 color = tex2D(_MaskTex, o.uv);
 color.r = 1 - color.r;
 color.g = 1 - color.g;
 color.b = 1 - color.b;
 fixed4 color2 = tex2D(_MainTex, o.uv);
 color2.r *= color.r*_Lerp;
 color2.g *= color.g*_Lerp;
 color2.b *= color.b*_Lerp;
 return color2;
 }
 ENDCG
 }
 }
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論