// 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. 启动tomcat时 错误: 代理抛出异常 : java.rmi.server.ExportException: Port already in use: 1099的解决办法

    一.问题描述 今天一来公司,在IntelliJ IDEA 中启动Tomcat服务器时就出现了如下图所示的错误:

  2. phpexcel操作

    <?php include './PHPExcel/PHPExcel.php'; include './PHPExcel/PHPExcel/Writer/Excel2007.php'; //或者 ...

  3. easyUI validatebox设置值和获取值,以及属性和方法

    一:表单元素使用easyui时,textbox和validatebox设置值和获取值的方式不一样[转] 1.为text-box设置值只能使用id选择器选择表单元素,只能使用textbox(" ...

  4. JavaScript学习笔记——节点

    javascript-节点属性详解 根据 DOM,HTML 文档中的每个成分都是一个节点. DOM 是这样规定的: 整个文档是一个文档节点 每个 HTML 标签是一个元素节点 包含在 HTML 元素中 ...

  5. 浏览器本地存储(browser-storage,HTML5-localStorage > IE-UserData > Cookie)

    https://www.baidufe.com/component/browser-storage/index.html BrowserStorage是浏览器本地存储的一个解决方案,存储优先级依次为: ...

  6. LeetCode —— Invert Binary Tree

    struct TreeNode* invertTree(struct TreeNode* root) { if ( NULL == root ) { return NULL; } if ( NULL ...

  7. live555库中的testRTSPClient实例

    1.testRTSPClient简介 testRTSPClient是个简单的客户端实例,这个实例对rtsp数据交互作了详细的描述,其中涉及到rtsp会话的两个概念Source和Sink. Source ...

  8. EF 索引

    public class CustomerMap : EntityTypeConfiguration<Customer> { public CustomerMap() { this.Pro ...

  9. 获取SQLSERVER所有库 所有表 所有列 所有字段信息

    最近想起来做一个项目代码生成器,直接生成底层代码.. 这免不了要先行读取数据库已有的信息.. 废话不多说..开整.. SELECT NAME FROM MASTER..SYSDATABASES --读 ...

  10. Mysql InnoDB行锁实现方式(转)

    Mysql InnoDB行锁实现方式 InnoDB行锁是通过给索引上的索引项加锁来实现的,这一点MySQL与Oracle不同,后者是通过在数据块中对相应数据行加锁来实现的.InnoDB这种行锁实现特点 ...