// 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. Dijkstra最短路径算法实例

    #include <stdio.h>#include <stdlib.h>/* Dijkstra算法 */#define VNUM 5#define MV 65536int P ...

  2. Linux学习笔记(二)2015.4.14

    笔记2.1 Q:登陆命令  A:刚开始登陆的是安装Linux时设置的普通用户,如lin,输入su - root后,成为root用户 笔记2.2 Q:切换控制台  A:ctrl+alt+F1-F7可以切 ...

  3. Tomcat web.xml中定义了文件扩展名到MIME类型的对应关系

    Tomcat在返回静态资源时,会根据资源文件的扩展名产生对应的content-type头(也即MIME类型)添加到response header中. 在Tomcat的web.xml规定了扩展名及相应M ...

  4. Numerical Optimization: Understanding L-BFGS

    http://aria42.com/blog/2014/12/understanding-lbfgs/ Numerical optimization is at the core of much of ...

  5. JavaBean简单示例

    本示例说明: 从Login.jsp中输入用户名和密码,提交,在NewFile.jsp中显示信息. ----- 类要放在一个包中!!! UserB 类文件 package model; public c ...

  6. VBO, VAO, Generic Vertex Attribute

    VBO - 用于存储顶点数据的Buffer Object. VAO - 用于组织VBO的对象. Generic Vertex Attribute - 通用顶点属性. For example, the ...

  7. BuildingAssetBundles in 5.x

    http://docs.unity3d.com/Manual/BuildingAssetBundles5x.html

  8. Spring与Quartz的整合实现定时任务调度 以及crontab的用法

    最近在研究Spring中的定时任务功能,最好的办法当然是使用Quartz来实现.对于一个新手来说,花了我不少时间,这里我写个笔记,给大家参考. 我使用的是Maven来管理项目,需要的Jar包我给大家贴 ...

  9. 解决umount.nfs: /data: device is busy 问题

    有时候我们需要umount某个挂载目录时会遇到如下问题: [root@localhost /]# umount /data/ umount.nfs: /data: device is busy 通过这 ...

  10. JAVA日期加减运算

    1.用java.util.Calender来实现 Calendar calendar=Calendar.getInstance();      calendar.setTime(new Date()) ...