溶解效果
来源:互联网 发布:韩国美颜软件 编辑:程序博客网 时间:2024/04/28 02:53
原理
实现图像溶解效果,实现机制是用一张纹理图作为溶解的过程。因为每个像素存储的数据不一样就像一个不平的地面,数值比较小的就想隐藏掉,数值比较大的就后隐藏。这个就完成了一个消融的过程。
如图按照数值比较小的数先一个一个隐藏,这里就产生了消融的过程。
第一个是像素的纹理,第二个我用的一个噪声纹理由他来控制消融过程
效果图
关键代码
fixed4 frag (v2f i) : SV_Target{ // sample the texture fixed4 col = tex2D(_MainTex, i.uv); fixed4 noise = tex2D(_NoiseTex,i.uv);//获取消融控制的纹理 float noiseA = noise.r-_NoiseTime;//减去一随着时间变化的变量得到消融的动画过程 clip(noiseA); return col;}
完整代码
Shader "Unlit/dissolution"{ Properties { _MainTex ("Texture", 2D) = "white" {} _NoiseTex("NoiseTexture",2D) = "white"{} _NoiseTime("NoiseTime",Range(0,1)) = 0 } SubShader { Tags { "RenderType"="Opaque" } LOD 100 Cull Off 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; }; sampler2D _MainTex; float4 _MainTex_ST; sampler2D _NoiseTex; float _NoiseTime; v2f vert (appdata v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); o.uv = TRANSFORM_TEX(v.uv, _MainTex); return o; } fixed4 frag (v2f i) : SV_Target { // sample the texture fixed4 col = tex2D(_MainTex, i.uv); fixed4 noise = tex2D(_NoiseTex,i.uv);//获取消融控制的纹理 float noiseA = noise.r-_NoiseTime;//减去一随着时间变化的变量得到消融的动画过程 clip(noiseA); return col; } ENDCG } }}
- 上面的那个要调_NoiseTime变量才能出效果。这里让他支持unity粒子组件,让Color over Lifetime的alpha控制消融过程
- 还要为溶解的边缘加上一个颜色值来凸显消融过程
效果图
关键代码
v2f vert (appdata v){ v2f o; o.vertex = UnityObjectToClipPos(v.vertex); o.uv = TRANSFORM_TEX(v.uv, _MainTex); o.color = v.color;//这个就是Color over Lifetime控制的顶点变量的颜色值 return o;}fixed4 frag (v2f i) : SV_Target{ // sample the texture fixed4 col = tex2D(_MainTex, i.uv); fixed4 noise = tex2D(_NoiseTex,i.uv); float noiseA = noise.r- i.color.a; clip(noiseA); //这里是控制消融的边缘颜色代码 col.rgb = lerp(col.rgb,_EdgeColor,(1-noiseA)*step(noiseA,_LineWidth)); return col;}
完整代码
Shader "Particles/Dissolution"{ Properties { _MainTex ("Texture", 2D) = "white" {} _NoiseTex("NoiseTexture",2D) = "white"{} _EdgeColor ("EdgeColor", Color) = (0.5,0.5,0.5,1) _LineWidth ("LineWidth",Range(0,0.1)) = 0.02 } SubShader { Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" } LOD 100 Cull Off Lighting Off ZWrite Off Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" struct appdata { float4 vertex : POSITION; fixed4 color : COLOR; float2 uv : TEXCOORD0; }; struct v2f { float2 uv : TEXCOORD0; fixed4 color : COLOR; float4 vertex : SV_POSITION; }; sampler2D _MainTex; float4 _MainTex_ST; sampler2D _NoiseTex; float4 _EdgeColor; fixed _LineWidth; v2f vert (appdata v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); o.uv = TRANSFORM_TEX(v.uv, _MainTex); o.color = v.color; return o; } fixed4 frag (v2f i) : SV_Target { // sample the texture fixed4 col = tex2D(_MainTex, i.uv); fixed4 noise = tex2D(_NoiseTex,i.uv); float noiseA = noise.r- i.color.a; clip(noiseA); col.rgb = lerp(col.rgb,_EdgeColor,(1-noiseA)*step(noiseA,_LineWidth)); return col; } ENDCG } }}
相关阅读
这里使用了lerp,step等内置函数,msdn上面有完整的内置函数列表及说明
msdn HLSL 内置函数列表
阅读全文
0 0
- 溶解效果
- 溶解效果
- 溶解效果
- 图片溶解渐显效果
- 溶解(Dissolve)效果
- [Unity Shader]溶解效果
- [UnityShader3]溶解与重现效果
- shader实例溶解,燃烧效果
- Unity Shader-死亡溶解效果
- Unity Shader-死亡溶解效果
- Shader forge 屏幕效果、溶解
- AS3.0实现像素的溶解效果
- Shader 做mesh简单的溶解效果
- Unity Shader-非主流纹理采样研究(流光,溶解,隐身效果)
- shader溶解特效
- 溶解与重现
- unity 溶解贴花编辑器
- 【UE4 shader】溶解shader
- also的位置情况总结(基于材料:“老托福听力93篇”)
- Python学习 第一天任务 (三:Python不止基础学习 继续安装爬虫环境的配置)
- 为了生活,找了工作没时间更
- HDU-5983(大模拟)
- 日常开发中关于mapreduce调优策略
- 溶解效果
- <转载>:svn和git的区别,maven是什么
- java中getClass( )和class()的联系和区别
- mysql5.7 zip版本安装过程
- 复习八:java基础知识点、算法与编程、java Web部分
- 学习笔记_009
- vs2013提示需要加_s才能编译的解决办法
- Markdown 语法说明 (简体中文版)
- 子程序返回的三种方法