分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow
也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!
- Shader "FX/Water" {
- Properties {
- _WaveScale ("Wave scale", Range (0.02,0.15)) = 0.063
- _ReflDistort ("Reflection distort", Range (0,1.5)) = 0.44
- _RefrDistort ("Refraction distort", Range (0,1.5)) = 0.40
- _RefrColor ("Refraction color", COLOR) = ( .34, .85, .92, 1)
- _Fresnel ("Fresnel (A) ", 2D) = "gray" {}
- _BumpMap ("Bumpmap (RGB) ", 2D) = "bump" {}
- WaveSpeed ("Wave speed (map1 x,y; map2 x,y)", Vector) = (19,9,-16,-7)
- _ReflectiveColor ("Reflective color (RGB) fresnel (A) ", 2D) = "" {}
- _ReflectiveColorCube ("Reflective color cube (RGB) fresnel (A)", Cube) = "" { TexGen CubeReflect }
- _HorizonColor ("Simple water horizon color", COLOR) = ( .172, .463, .435, 1)
- _MainTex ("Fallback texture", 2D) = "" {}
- _ReflectionTex ("Internal Reflection", 2D) = "" {}
- _RefractionTex ("Internal Refraction", 2D) = "" {}
- }
- // -----------------------------------------------------------
- // Fragment program cards
- Subshader {
- Tags { "WaterMode"="Refractive" "RenderType"="Opaque" }
- Pass {
- CGPROGRAM
- #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 {
- V2F_POS_FOG;
- #if defined HAS_REFLECTION || defined HAS_REFRACTION
- float3 ref;
- #endif
- float2 bumpuv[2];
- float3 viewDir;
- };
- v2f vert(appdata v)
- {
- v2f o;
- PositionFog( v.vertex, o.pos, o.fog );
- // 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 (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, 0, 0.5,
- 0, 0.5 * _ProjectionParams.x, 0, 0.5,
- 0, 0, 0, 1
- );
- 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 </