水shader效果.docx_第1页
水shader效果.docx_第2页
水shader效果.docx_第3页
水shader效果.docx_第4页
水shader效果.docx_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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 cardsSubshader 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.cgincuniform float4 _WaveScale4;uniform float4 _WaveOffset;#ifdef HAS_REFLECTIONuniform float _ReflDistort;#endif#ifdef HAS_REFRACTIONuniform float _RefrDistort;#endifstruct appdata float4 vertex : POSITION;float3 normal : NORMAL;struct v2f V2F_POS_FOG;#if defined HAS_REFLECTION | defined HAS_REFRACTIONfloat3 ref;#endiffloat2 bumpuv2;float3 viewDir;v2f vert(appdata v)v2f o;PositionFog( v.vertex, o.pos, o.fog );/ scroll bump wavesfloat4 temp;temp.xyzw = v.vertex.xzxz * _WaveScale4 + _WaveOffset;o.bumpuv0 = temp.xy;o.bumpuv1 = 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 vectorfloat3x4 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);#endifreturn o;#if defined WATER_REFLECTIVE | defined WATER_REFRACTIVEsampler2D _ReflectionTex;#endif#if defined WATER_REFLECTIVE | defined WATER_SIMPLEsampler2D _ReflectiveColor;#endif#if defined WATER_REFRACTIVEsampler2D _Fresnel;sampler2D _RefractionTex;uniform float4 _RefrColor;#endif#if defined WATER_SIMPLEuniform float4 _HorizonColor;#endifsampler2D _BumpMap;half4 frag( v2f i ) : COLORi.viewDir = normalize(i.viewDir);/ combine two scrolling bumpmaps into onehalf3 bump1 = tex2D( _BumpMap, i.bumpuv0 ).rgb;half3 bump2 = tex2D( _BumpMap, i.bumpuv1 ).rgb;half3 bump = bump1 + bump2 - 1;/ fresnel factorhalf fresnelFac = dot( i.viewDir, bump );/ perturb reflection/refraction UVs by bumpmap, and lookup colors#ifdef HAS_REFLECTIONfloat3 uv1 = i.ref; uv1.xy += bump * _ReflDistort;half4 refl = tex2Dproj( _ReflectionTex, uv1 );#endif#ifdef HAS_REFRACTIONfloat3 uv2 = i.ref; uv2.xy -= bump * _RefrDistort;half4 refr = tex2Dproj( _RefractionTex, uv2 ) * _RefrColor;#endif/ final color is between refracted and reflected based on fresnelhalf4 color;#ifdef WATER_REFRACTIVEhalf fresnel = tex2D( _Fresnel, float2(fresnelFac,fresnelFac) ).a;color = lerp( refr, refl, fresnel );#endif#ifdef WATER_REFLECTIVEhalf4 water = tex2D( _ReflectiveColor, float2(fresnelFac,fresnelFac) );color.rgb = lerp( water.rgb, refl.rgb, water.a );color.a = refl.a * water.a;#endif#ifdef WATER_SIMPLEhalf4 water = tex2D( _ReflectiveColor, float2(fresnelFac,fresnelFac) );color.rgb = lerp( water.rgb, _HorizonColor.rgb, water.a );color.a = _HorizonColor.a;#endifreturn color;ENDCG/ -/ Radeon 9000 cardsSubshader Tags WaterMode=Reflective RenderType=Opaque Pass CGPROGRAM#pragma vertex vert#include UnityCG.cgincuniform float4 _WaveScale4;uniform float4 _WaveOffset;uniform float _ReflDistort;struct appdata float4 vertex : POSITION;float3 normal : NORMAL;struct v2f V2F_POS_FOG;float2 bumpuv2 : TEXCOORD0;float3 viewDir : TEXCOORD2;float4 ref : TEXCOORD3;v2f vert(appdata v)v2f o;PositionFog( v.vertex, o.pos, o.fog );/ scroll bump wavesfloat4 temp;temp.xyzw = v.vertex.xzxz * _WaveScale4 + _WaveOffset;o.bumpuv0 = temp.xy;o.bumpuv1 = temp.wz;/ object space view directiono.viewDir.xzy = normalize( ObjSpaceViewDir(v.vertex) );/ calculate the reflection vectorfloat4x4 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教程手册:ENDCGProgram 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.0StartConstants;CONSTANT c0 = program.local0;EndConstants;StartPrelimPass;PassTexCoord r3, t3.stq_dq; # reflection vectorSampleMap r0, t0.str; # bump1SampleMap r1, t1.str; # bump2PassTexCoord r2, t2.str;ADD r1.half, r0.bias, r1.bias; # bump = bump1 + bump2 - 1DOT3 r2, r1.2x, r2; # fresnel: dot (bump, viewer-pos)# add less offset because its purely screenspace; big ones look badMAD r3.rg, r1, c0.r, r3; # uv += bump * strength; add less because its not perspectiveEndPass;StartOutputPass;SampleMap r3, r3.str; # reflection colorSampleMap r2, r2.str; # water color/fresnelLERP r0.rgb, r2.a, r3, r2; # between water and reflected based on fresnelMUL r0.a, r3.a, r2.a;EndPass;SubProgram Keywords WATER_SIMPLE SetTexture _BumpMap 2D SetTexture _BumpMap 2D SetTexture _ReflectiveColor 2D Local 0, _HorizonColor!ATIfs1.0StartConstants;CONSTANT c0 = program.local0;EndConstants;StartPrelimPass;SampleMap r0, t0.str;SampleMap r1, t1.str;PassTexCoord r2, t2.str;ADD r1, r0.bias, r1.bias; # bump = bump1 + bump2 - 1DOT3 r2, r1, r2; # fresnel: dot (bump, viewer-pos)EndPass;StartOutputPass;SampleMap r2, r2.str;LERP r0.rgb, r2.a, c0, r2; # fade in reflectionMOV r0.a, c0.a;EndPass;/ -/ Old cards/ three texture, cubemapsSubshader Tags WaterMode=Simple RenderType=Opaque Pass Color (0.5,0.5,0.5

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论