// Upgrade NOTE: replaced 'PositionFog()' with multiply of UNITY_MATRIX_MVP by position
// Upgrade NOTE: replaced 'V2F_POS_FOG' with 'float4 pos : SV_POSITION'
// Upgrade NOTE: replaced 'defined HAS_REFLECTION' with 'defined (HAS_REFLECTION)'
// Upgrade NOTE: replaced 'defined HAS_REFRACTION' with 'defined (HAS_REFRACTION)'
// Upgrade NOTE: replaced 'defined WATER_REFLECTIVE' with 'defined (WATER_REFLECTIVE)'
// Upgrade NOTE: replaced 'defined WATER_REFRACTIVE' with 'defined (WATER_REFRACTIVE)'
// Upgrade NOTE: replaced 'defined WATER_SIMPLE' with 'defined (WATER_SIMPLE)' Shader "FX/Water" { Properties { _WaveScale ("Wave scale", Range (0.02,0.15)) = 0.063 _ReflDistort ("Reflection distort", Range (,1.5)) = 0.44 _RefrDistort ("Refraction distort", Range (,1.5)) = 0.40 _RefrColor ("Refraction color", COLOR) = ( ., ., ., ) _Fresnel ("Fresnel (A) ", 2D) = "gray" {} _BumpMap ("Bumpmap (RGB) ", 2D) = "bump" {} WaveSpeed ("Wave speed (map1 x,y; map2 x,y)", Vector) = (,,-,-) _ReflectiveColor ("Reflective color (RGB) fresnel (A) ", 2D) = "" {} _ReflectiveColorCube ("Reflective color cube (RGB) fresnel (A)", Cube) = "" { TexGen CubeReflect } _HorizonColor ("Simple water horizon color", COLOR) = ( ., ., ., ) _MainTex ("Fallback texture", 2D) = "" {} _ReflectionTex ("Internal Reflection", 2D) = "" {} _RefractionTex ("Internal Refraction", 2D) = "" {} } // ----------------------------------------------------------- // Fragment program cards Subshader { Tags { "WaterMode"="Refractive" "RenderType"="Opaque" } Pass { CGPROGRAM
// Upgrade NOTE: excluded shader from OpenGL ES 2.0 because it uses non-square matrices
#pragma exclude_renderers gles
// Upgrade NOTE: excluded shader from DX11 and Xbox360; has structs without semantics (struct v2f members ref,bumpuv,viewDir)
#pragma exclude_renderers d3d11 xbox360 #pragma vertex vert #pragma fragment frag #pragma fragmentoption ARB_precision_hint_fastest #pragma fragmentoption ARB_fog_exp2 #pragma multi_compile WATER_REFRACTIVE WATER_REFLECTIVE WATER_SIMPLE #if defined (WATER_REFLECTIVE) || defined (WATER_REFRACTIVE) #define HAS_REFLECTION 1 #endif #if defined (WATER_REFRACTIVE) #define HAS_REFRACTION 1 #endif #include "UnityCG.cginc" uniform float4 _WaveScale4; uniform float4 _WaveOffset; #ifdef HAS_REFLECTION uniform float _ReflDistort; #endif #ifdef HAS_REFRACTION uniform float _RefrDistort; #endif struct appdata { float4 vertex : POSITION; float3 normal : NORMAL; }; struct v2f { float4 pos : SV_POSITION; #if defined (HAS_REFLECTION) || defined (HAS_REFRACTION) float3 ref; #endif float2 bumpuv[]; float3 viewDir; }; v2f vert(appdata v) { v2f o; o.pos = mul (UNITY_MATRIX_MVP, v.vertex); // scroll bump waves float4 temp; temp.xyzw = v.vertex.xzxz * _WaveScale4 + _WaveOffset; o.bumpuv[] = temp.xy; o.bumpuv[] = temp.wz; // object space view direction (will normalize per pixel) o.viewDir.xzy = ObjSpaceViewDir(v.vertex); #if defined (HAS_REFLECTION) || defined (HAS_REFRACTION) // calculate the reflection vector float3x4 mat = float3x4 ( 0.5, , , 0.5, , 0.5 * _ProjectionParams.x, , 0.5, , , , ); o.ref = mul (mat, o.pos); #endif return o; } #if defined (WATER_REFLECTIVE) || defined (WATER_REFRACTIVE) sampler2D _ReflectionTex; #endif #if defined (WATER_REFLECTIVE) || defined (WATER_SIMPLE) sampler2D _ReflectiveColor; #endif #if defined (WATER_REFRACTIVE) sampler2D _Fresnel; sampler2D _RefractionTex; uniform float4 _RefrColor; #endif #if defined (WATER_SIMPLE) uniform float4 _HorizonColor; #endif sampler2D _BumpMap; half4 frag( v2f i ) : COLOR { i.viewDir = normalize(i.viewDir); // combine two scrolling bumpmaps into one half3 bump1 = tex2D( _BumpMap, i.bumpuv[] ).rgb; half3 bump2 = tex2D( _BumpMap, i.bumpuv[] ).rgb; half3 bump = bump1 + bump2 - ; // fresnel factor half fresnelFac = dot( i.viewDir, bump ); // perturb reflection/refraction UVs by bumpmap, and lookup colors #ifdef HAS_REFLECTION float3 uv1 = i.ref; uv1.xy += bump * _ReflDistort; half4 refl = tex2Dproj( _ReflectionTex, uv1 ); #endif #ifdef HAS_REFRACTION float3 uv2 = i.ref; uv2.xy -= bump * _RefrDistort; half4 refr = tex2Dproj( _RefractionTex, uv2 ) * _RefrColor; #endif // final color is between refracted and reflected based on fresnel half4 color; #ifdef WATER_REFRACTIVE half fresnel = tex2D( _Fresnel, float2(fresnelFac,fresnelFac) ).a; color = lerp( refr, refl, fresnel ); #endif #ifdef WATER_REFLECTIVE half4 water = tex2D( _ReflectiveColor, float2(fresnelFac,fresnelFac) ); color.rgb = lerp( water.rgb, refl.rgb, water.a ); color.a = refl.a * water.a; #endif #ifdef WATER_SIMPLE half4 water = tex2D( _ReflectiveColor, float2(fresnelFac,fresnelFac) ); color.rgb = lerp( water.rgb, _HorizonColor.rgb, water.a ); color.a = _HorizonColor.a; #endif return color; } ENDCG } } // ----------------------------------------------------------- // Radeon 9000 cards #warning Upgrade NOTE: SubShader commented out because of manual shader assembly
/*Subshader { Tags { "WaterMode"="Reflective" "RenderType"="Opaque" } Pass { CGPROGRAM
// Upgrade NOTE: excluded shader from OpenGL ES 2.0 because it does not contain a surface program or both vertex and fragment programs.
#pragma exclude_renderers gles #pragma vertex vert #include "UnityCG.cginc" uniform float4 _WaveScale4; uniform float4 _WaveOffset; uniform float _ReflDistort; struct appdata { float4 vertex : POSITION; float3 normal : NORMAL; }; struct v2f { float4 pos : SV_POSITION; float2 bumpuv[2] : TEXCOORD0; float3 viewDir : TEXCOORD2; float4 ref : TEXCOORD3; }; v2f vert(appdata v) { v2f o; o.pos = mul (UNITY_MATRIX_MVP, v.vertex); // scroll bump waves float4 temp; temp.xyzw = v.vertex.xzxz * _WaveScale4 + _WaveOffset; o.bumpuv[0] = temp.xy; o.bumpuv[1] = temp.wz; // object space view direction o.viewDir.xzy = normalize( ObjSpaceViewDir(v.vertex) ); // calculate the reflection vector float4x4 mat = float4x4 ( .5, 0, 0,.5, 0,.5 * _ProjectionParams.x, 0,.5, 0, 0,.5,.5, 0, 0, 0, 1 ); o.ref = mul (mat, o.pos); return o; } //Unity3D教程手册:www.unitymanual.com ENDCG Program "" { SubProgram { Keywords { "WATER_REFLECTIVE" "WATER_REFRACTIVE" } SetTexture [_BumpMap] { 2D } SetTexture [_BumpMap] { 2D } SetTexture [_ReflectiveColor] { 2D } SetTexture [_ReflectionTex] { 2D } Local 0, ([_ReflDistort],0,0,0) "!!ATIfs1.0 StartConstants; CONSTANT c0 = program.local[0]; EndConstants; StartPrelimPass; PassTexCoord r3, t3.stq_dq; # reflection vector SampleMap r0, t0.str; # bump1 SampleMap r1, t1.str; # bump2 PassTexCoord r2, t2.str; ADD r1.half, r0.bias, r1.bias; # bump = bump1 + bump2 - 1 DOT3 r2, r1.2x, r2; # fresnel: dot (bump, viewer-pos) # add less offset because it's purely screenspace; big ones look bad MAD r3.rg, r1, c0.r, r3; # uv += bump * strength; add less because it's not perspective EndPass; StartOutputPass; SampleMap r3, r3.str; # reflection color SampleMap r2, r2.str; # water color/fresnel LERP r0.rgb, r2.a, r3, r2; # between water and reflected based on fresnel MUL r0.a, r3.a, r2.a; EndPass; " } SubProgram { Keywords { "WATER_SIMPLE" } SetTexture [_BumpMap] { 2D } SetTexture [_BumpMap] { 2D } SetTexture [_ReflectiveColor] { 2D } Local 0, [_HorizonColor] "!!ATIfs1.0 StartConstants; CONSTANT c0 = program.local[0]; EndConstants; StartPrelimPass; SampleMap r0, t0.str; SampleMap r1, t1.str; PassTexCoord r2, t2.str; ADD r1, r0.bias, r1.bias; # bump = bump1 + bump2 - 1 DOT3 r2, r1, r2; # fresnel: dot (bump, viewer-pos) EndPass; StartOutputPass; SampleMap r2, r2.str; LERP r0.rgb, r2.a, c0, r2; # fade in reflection MOV r0.a, c0.a; EndPass; " } } } }*/ // ----------------------------------------------------------- // Old cards // three texture, cubemaps Subshader { Tags { "WaterMode"="Simple" "RenderType"="Opaque" } Pass { Color (0.5,0.5,0.5,0.5) SetTexture [_MainTex] { Matrix [_WaveMatrix] combine texture * primary } SetTexture [_MainTex] { Matrix [_WaveMatrix2] combine texture * primary + previous } SetTexture [_ReflectiveColorCube] { combine texture +- previous, primary Matrix [_Reflection] } } //Unity3D教程:www.unitymanual.com } // dual texture, cubemaps Subshader { Tags { "WaterMode"="Simple" "RenderType"="Opaque" } Pass { Color (0.5,0.5,0.5,0.5) SetTexture [_MainTex] { Matrix [_WaveMatrix] combine texture } SetTexture [_ReflectiveColorCube] { combine texture +- previous, primary Matrix [_Reflection] } } } // single texture Subshader { Tags { "WaterMode"="Simple" "RenderType"="Opaque" } Pass { Color (0.5,0.5,0.5,) SetTexture [_MainTex] { Matrix [_WaveMatrix] combine texture, primary } } } }

水面shader 线性擦除的更多相关文章

  1. Cesium添加水面

    var viewer = new Cesium.Viewer('cesiumContainer');var waterPrimitive = new Cesium.Primitive({ //show ...

  2. vertex shader(1)

    Vertex shader Architecture: 所有在vertex shader中的数据都用128-bit的quad-floats表示(4x32-bit). vertex shader线性地执 ...

  3. cesium 水面、淹没 效果

    水面效果 参考: http://cesiumcn.org/topic/158.html http://api.rivermap.cn/cesium/rivermap/map.html https:// ...

  4. Android 画布绘图

    我们已经介绍了Canvas,在那里,已经学习了如何创建自己的View.在第7章中也使用了Canvas来为MapView标注覆盖. 画布(Canvas)是图形编程中一个很普通的概念,通常由三个基本的绘图 ...

  5. Android 滑动效果进阶篇(六)—— 倒影效果

    上篇介绍了使用Animation实现3D动画旋转翻页效果,现在介绍图片倒影实现,先看效果图 本示例主要通过自定义Gallery和ImageAdapter(继承自BaseAdapter)实现 1.倒影绘 ...

  6. Android 自定义Gallery浏览图片

    之前写的<Android ImageSwitcher和Gallery的使用>一文中提到我在教室一下午为实现那个效果找各种资料.期间在网上找了一个个人觉得比较不错的效果,现在贴图上来: 其实 ...

  7. Android Framework 其中A记录

    一个简短的引论 以往的研究太偏应用层的功能,实现了,原则上不进入非常理解,现在,研究人员framework该框架层. 创纪录的 1.下载源代码,文件夹例如以下: 2.Android系统的层次例如以下: ...

  8. Android Framework 学习和需要学习的内容

    1. 之前的研究太偏向应用层功能实现了,很多原理不了解没有深究,现在研究framework面存一些资料待有空查看. 2.Android系统的层次如下: 3.项目目录简单分析如下: 4.telphony ...

  9. Android Framework 简介

    Android Framework 简介 简介 之前的研究太偏向应用层功能实现了,很多原理不了解没有详记,结果被很多公司技术人员鄙视了,为了减少自己的短板,重新复习了一遍C++.java.Androi ...

随机推荐

  1. ios动态添加属性的几种方法

    http://blog.csdn.net/shengyumojian/article/details/44919695 在ios运行过程中,有几种方式能够动态的添加属性. 1-通过runtime动态关 ...

  2. MyISAM与InnoDB两者之间怎么选择

    1.MyISAM不支持事务,InnoDB是事务类型的存储引擎 当我们的表需要用到事务支持的时候,那肯定是不能选择MyISAM了. 2.MyISAM只支持表级锁,BDB支持页级锁和表级锁默认为页级锁,而 ...

  3. Java同步synchronized与死锁

    多个线程要操作同一资源时就有可能出现资源的同步问题. 同步就是指多个操作在同一个时间段内只能有一个线程进行,其他线程要等待此线程完成之后才可以继续执行. 解决资源共享的同步操作,可以使用同步代码块和同 ...

  4. $().index() 两种用法

    第一种:获得第一个 p 元素的名称和值: $(this).index() <script type="text/javascript"> $(document).rea ...

  5. My VA Snippet

    My VA snippet Visual Assist X 是一款比较好用的编码辅助工具, 这款工具可以大大提高程序员的编码速度和开发效率.同时在它的指引下可以有效避免低级Bug. 真正实现快速编码, ...

  6. Python之路【第二篇】:Python基础

    参考链接:老师 BLOG : http://www.cnblogs.com/wupeiqi/articles/4906230.html 入门拾遗 一.作用域 只要变量在内存中就能被调用!但是(函数的栈 ...

  7. jQuery 鼠标拖拽移动窗口

    拖拽移动需要注意的是:拖拽移动的窗口是如何定位的,如果"left"属性为"%" ,以"margin-left"来计算定位,如下实例,如果&q ...

  8. ASP.NET MVC5 Filter重定向问题

    ASP.NET MVC5 Filter重定向问题 一.问题描述 1.在Filter中使用直接filterContext.RequestContext.HttpContext.Response.Redi ...

  9. JSF的CommandXxx组件的update用法总结

    Update all forms 1 update="@(form)" Update first form 1 update="@(form:first)" U ...

  10. ls按时间排序输出文件列表

    文件转自:http://www.2cto.com/os/201303/197829.html ls按时间排序输出文件列表   首先,ls --help查看ls相关的与时间排序相关的参数:   > ...