// 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. document.execCommand 常用的方法

    execCommand方法是执行一个对当前文档,当前选择或者给出范围的命令.处理Html数据时常用如下格式: document.execCommand(sCommand[,交互方式, 动态参数]) , ...

  2. uC/OS-II汇编代码

    ;*************************************************************************************************** ...

  3. ORACLE 错误:oralce record is locked by another user

     方法/步骤     打开PL/SQL客户端,然后修改表记录中的数据,提交修改,如下提示 步骤阅读 2 我们关闭异常警告窗口,在执行sql的窗口中输入如下命令:select t2.username,t ...

  4. 导出excel失败,提醒提示加载类型库/DDL出错

    导出excel失败,提醒提示加载类型库/DDL出错 www.MyException.Cn   发布于:2012-08-17 02:08:34   浏览:1538次   导出excel失败,提示提示加载 ...

  5. JavaScript学习笔记——对象基础

    javascript对象基础 一.名词解释: 1.基于对象 一切皆对象,以对象的概念来编程. 2.面向对象编程(oop Object oriented programming) A.对象 就是人们要研 ...

  6. Garbage Collection C++

    http://herbsutter.com/2011/10/25/garbage-collection-synopsis-and-c/ http://www.codeproject.com/Artic ...

  7. Apache配置--用户认证(针对目录访问)-update2015-05-02

    通过Apache配置可以限制用户对目录的访问,会弹出像phpadmin一样的登陆框. ========================================================= ...

  8. OC- @property @synthesize

    @property 1,在@interface中 2,自动生成setter和getter的声明 #import <Foundation/Foundation.h> @interface P ...

  9. C-全局变量与局部变量

  10. [Js/Jquery]table行转列

    摘要 在使用ews调用exhange的收件箱的并在h5页面显示邮件详情的时候,因为返回的每封邮件的内容都是htmlbody,没有textbody.每封邮件又没什么规律,用正则表达式来匹配内容并不合适, ...