[Unity Shader]溶解效果
来源:互联网 发布:nvidia windows xp 编辑:程序博客网 时间:2024/04/28 00:03
一、效果
二、BurnToFadeOut.shader
Shader "BurnToFadeOut" {Properties { _StartColor ("Start Color", Color) = (1,1,1,1) _EndColor ("End Color", Color) = (1,1,1,1) _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {} _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5 _Emit ("Emit level", Range(1,100)) = 0 _Range ("Range", Range(0,1)) = 0}SubShader { Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"} LOD 100 Lighting Off Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" struct appdata_t { float4 vertex : POSITION; float2 texcoord : TEXCOORD0; }; struct v2f { float4 vertex : SV_POSITION; half2 texcoord : TEXCOORD0; }; sampler2D _MainTex; float4 _MainTex_ST; fixed4 _StartColor; fixed4 _EndColor; fixed _Cutoff; half _Emit; half _Range; v2f vert (appdata_t v) { v2f o; o.vertex = mul(UNITY_MATRIX_MVP, v.vertex); o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex); return o; } fixed4 frag (v2f i) : COLOR { fixed4 col = tex2D(_MainTex, i.texcoord); fixed a = dot(col.xyz, fixed3(0.3, 0.59, 0.11)); col.a = a; clip(a - _Cutoff); if(a < _Cutoff + _Range) col.xyz = lerp(_StartColor.xyz, _EndColor.xyz, (saturate(a - _Cutoff) / _Range)) * _Emit; return col; } ENDCG }}SubShader { Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"} LOD 100 Pass { Lighting Off Alphatest Greater [_Cutoff] SetTexture [_MainTex] { combine texture } }}}
三、使用
光晕效果需要把摄像机HDR打开并挂上这个脚本(Pro版导入Standard Asset里的)
@script ExecuteInEditMode@script RequireComponent (Camera)@script AddComponentMenu ("Image Effects/Bloom and Glow/Bloom (Optimized)")class FastBloom extends PostEffectsBase { public enum Resolution { Low = 0, High = 1, } public enum BlurType { Standard = 0, Sgx = 1, } @Range(0.0f, 1.5f) public var threshhold : float = 0.25f; @Range(0.0f, 2.5f) public var intensity : float = 0.75f; @Range(0.25f, 5.5f) public var blurSize : float = 1.0f; var resolution : Resolution = Resolution.Low; @Range(1, 4) public var blurIterations : int = 1; public var blurType = BlurType.Standard; public var fastBloomShader : Shader; private var fastBloomMaterial : Material = null; function CheckResources () : boolean { CheckSupport (false); fastBloomMaterial = CheckShaderAndCreateMaterial (fastBloomShader, fastBloomMaterial); if(!isSupported) ReportAutoDisable (); return isSupported; } function OnDisable() { if(fastBloomMaterial) DestroyImmediate (fastBloomMaterial); } function OnRenderImage (source : RenderTexture, destination : RenderTexture) { if(CheckResources() == false) { Graphics.Blit (source, destination); return; } var divider : int = resolution == Resolution.Low ? 4 : 2; var widthMod : float = resolution == Resolution.Low ? 0.5f : 1.0f; fastBloomMaterial.SetVector ("_Parameter", Vector4 (blurSize * widthMod, 0.0f, threshhold, intensity)); source.filterMode = FilterMode.Bilinear; var rtW = source.width/divider; var rtH = source.height/divider; // downsample var rt : RenderTexture = RenderTexture.GetTemporary (rtW, rtH, 0, source.format); rt.filterMode = FilterMode.Bilinear; Graphics.Blit (source, rt, fastBloomMaterial, 1); var passOffs = blurType == BlurType.Standard ? 0 : 2; for(var i : int = 0; i < blurIterations; i++) { fastBloomMaterial.SetVector ("_Parameter", Vector4 (blurSize * widthMod + (i*1.0f), 0.0f, threshhold, intensity)); // vertical blur var rt2 : RenderTexture = RenderTexture.GetTemporary (rtW, rtH, 0, source.format); rt2.filterMode = FilterMode.Bilinear; Graphics.Blit (rt, rt2, fastBloomMaterial, 2 + passOffs); RenderTexture.ReleaseTemporary (rt); rt = rt2; // horizontal blur rt2 = RenderTexture.GetTemporary (rtW, rtH, 0, source.format); rt2.filterMode = FilterMode.Bilinear; Graphics.Blit (rt, rt2, fastBloomMaterial, 3 + passOffs); RenderTexture.ReleaseTemporary (rt); rt = rt2; } fastBloomMaterial.SetTexture ("_Bloom", rt); Graphics.Blit (source, destination, fastBloomMaterial, 0); RenderTexture.ReleaseTemporary (rt); } }
0 0
- [Unity Shader]溶解效果
- Unity Shader-死亡溶解效果
- Unity Shader-死亡溶解效果
- Unity Shader Example 7 (溶解)
- shader实例溶解,燃烧效果
- Shader forge 屏幕效果、溶解
- Unity Shader-非主流纹理采样研究(流光,溶解,隐身效果)
- Shader 做mesh简单的溶解效果
- 【UE4 shader】溶解shader
- 溶解效果
- 溶解效果
- 溶解效果
- Unity Shader 效果学习
- unity shader 流光效果
- Unity Shader 扰动效果
- unity Shader 扭曲效果
- shader溶解特效
- Unity Shader-遮挡处理(X-Ray,遮挡描边,遮挡半透,遮挡溶解)
- Java线程_(二)线程同步与锁
- 微信小程序_石头剪刀布
- 中医文化
- python中scipy学习——随机稀疏矩阵及操作
- (四)剑指offer之重建二叉树
- [Unity Shader]溶解效果
- Unable to read XML
- Struts2上传文件报错:Unable to find'struts.multipart.saveDir'property setting
- log4j.properties 详解
- POJ-1065 Wooden Sticks,排序+最长单减子序列!
- 算法提高 数组输出
- 重装系统的第一天之配置环境
- 使用gcc工具链进行Linux环境下的stm32开发
- 试玩