Unity实现攻击后闪白效果
2019-09-20 17:11
337 查看
原文链接:https://www.geek-share.com/detail/2628525202.html
这里只需要一个Shader和一个脚本。
1、创建一个ShaderTest的脚本,代码如下,挂载在相机上。
[code] using UnityEngine; using System.Collections; //[ExecuteInEditMode] public class ShaderTest : MonoBehaviour { #region Variables public Shader curShader; private float speed = 0.5f; public float grayScaleAmount = 1.0f; private Material curMaterial; #endregion #region Properties public Material material { get { if (curMaterial == null) { curMaterial = new Material(curShader); curMaterial.hideFlags = HideFlags.HideAndDontSave; } return curMaterial; } } #endregion // Use this for initialization void Start() { if (SystemInfo.supportsImageEffects == false) { enabled = false; return; } if (curShader != null && curShader.isSupported == false) { enabled = false; } } void OnRenderImage(RenderTexture sourceTexture, RenderTexture destTexture) { if (curShader != null) { material.SetFloat("_LuminosityAmount", grayScaleAmount); Graphics.Blit(sourceTexture, destTexture, material); } else { Graphics.Blit(sourceTexture, destTexture); } } // Update is called once per frame void Update() { //grayScaleAmount = Mathf.Clamp(grayScaleAmount, 0.0f, 1.0f); if (grayScaleAmount <1) { grayScaleAmount += Time.deltaTime*speed; } } void OnDisable() { if (curMaterial != null) { DestroyImmediate(curMaterial); } } }
2、创建一个Shader,命名为imageTest。
Shader代码如下。
[code]Shader "Custom/imageTest" { Properties { _MainTex ("Base (RGB)", 2D) = "white" {} _LuminosityAmount ("GrayScale Amount", Range(0.0, 1.0)) = 1.0 } SubShader { Pass { CGPROGRAM #pragma vertex vert_img #pragma fragment frag #include "UnityCG.cginc" uniform sampler2D _MainTex; fixed _LuminosityAmount; fixed4 frag(v2f_img i) : COLOR { //Get the colors from the RenderTexture and the uv's //from the v2f_img struct fixed4 renderTex = tex2D(_MainTex, i.uv); //Apply the Luminosity values to our render texture float luminosity = 0.299 * renderTex.r + 0.587 * renderTex.g + 0.114 * renderTex.b; fixed4 finalColor = lerp(renderTex, luminosity, _LuminosityAmount); return finalColor; } ENDCG } } FallBack "Diffuse" }
相关文章推荐
- unity使用AnimationCurve实现RPG中攻击与受伤时的分数的动态效果ScoreFlash
- unity实现屏幕上写字效果
- 崩坏学园3里离摄像机近距离的头发透明效果在unity里的实现方法
- Unity游戏开发技巧集锦2.1.3实现效果
- 关于Unity中NGUI的Tab商城、Scrollview和打字机效果的实现
- 用Unity实现时间倒退效果
- unity实现按钮和攻击对象的选定
- Unity中放大镜效果的实现及实现细节。
- SVG实现攻击效果
- Unity实现UI渐变效果(UGUI)
- Unity 粒子海洋效果实现
- Unity_实现类似黑洞的效果__逻辑方面
- Unity 利用Coroutine实现跳动数字效果
- unity 使用shader加rendertexture实现刮刮乐效果
- Unity Flat Shading实现低多边形(low-poly)效果
- 【Unity开发】实现简易时钟效果
- 用unity实现动态粒子效果(上)【详细】
- 在Unity中如何实现重复循环效果?
- unity 实现流光效果
- unity 实现pageView翻页效果