//------------------------------------------------------------------------------------------------ // VARIABLES //------------------------------------------------------------------------------------------------ // GLOBALS float fTime : TIME; float4x4 mtxReflect : GLOBAL; float fBumpOffset : GLOBAL; float fWaterTexScale : GLOBAL; float3 f3FogValues : GLOBAL; float4 f4AmbientColor : GLOBAL; // TRANSFORMATIONS float4x4 mtxWorld : WORLD; float4x4 mtxWorldViewProj : WORLDVIEWPROJECTION; //------------------------------------------------------------------------------------------------ // SAMPLERS //------------------------------------------------------------------------------------------------ texture ReflectionMap < string NTM = "shader"; int NTMIndex = 0; >; texture WaveDUDV < string NTM = "detail"; >; texture Water < string NTM = "base"; >; sampler WaveBumpSampler = sampler_state { Texture = (WaveDUDV); AddressU = WRAP; AddressV = WRAP; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; }; sampler ReflectionSampler = sampler_state { Texture = (ReflectionMap); AddressU = CLAMP; AddressV = CLAMP; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; }; sampler WaterSampler = sampler_state { Texture = (Water); AddressU = WRAP; AddressV = WRAP; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; }; sampler WaterSampler2 = sampler_state { Texture = (Water); AddressU = WRAP; AddressV = WRAP; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; }; //------------------------------------------------------------------------------------------------ // VERTEX OUTPUT FORMAT //------------------------------------------------------------------------------------------------ struct VS_OUTPUT { float4 f4Pos : POSITION; float2 f2BumpTexCoords : TEXCOORD0; float4 f4ReflectionCoords : TEXCOORD1; float2 f2ColorTexCoords : TEXCOORD2; float2 f2ColorTexCoords2 : TEXCOORD3; float fFog : FOG; float4 f4ModulateColor : COLOR0; }; //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ // VERTEX SHADER //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ VS_OUTPUT VS( float3 InPos : POSITION, float2 f2Tex : TEXCOORD, float4 f4Color : COLOR ) { VS_OUTPUT Out = (VS_OUTPUT)0; // Transform the point into world coordinates float3 f3Pos = mul( float4( InPos, 1 ), mtxWorld ); // Transform the vertex into screen space Out.f4Pos = mul( float4( InPos, 1 ), mtxWorldViewProj ); // Push the object coordinates into a reflected (0, 1) space Out.f4ReflectionCoords = mul( float4( f3Pos, 1 ), mtxReflect ); // JEROME - Change the 30.0f to a bigger number to reduce the size of the texture tiling f2Tex = fWaterTexScale * f2Tex * 45.0f; Out.f2BumpTexCoords = f2Tex; // JEROME - Change the 30.0f below to bigger numbers to slow down the scrolling. Smaller values will speed it up. Out.f2ColorTexCoords.x = f2Tex.x + (fTime % 45.0f)/45.0f; Out.f2ColorTexCoords.y = f2Tex.y; Out.f2ColorTexCoords2.x = (1.0f - f2Tex.x); Out.f2ColorTexCoords2.y = (1.0f - f2Tex.y) - (fTime % 45.0f)/45.0f; // Compute the fog values Out.fFog = saturate( ((Out.f4Pos.z / f3FogValues.x) - f3FogValues.y) / f3FogValues.z ); // Compute the modulation color (scale the ambient - we're not going to have any diffuse lighting) Out.f4ModulateColor = saturate( f4AmbientColor * 1.5 ); return Out; } //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ // PIXEL SHADER //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ PIXELSHADER PS = asm { ps_1_1 // JEROME - change the value below to set the opacity of the water def c0, 0.45, 0.45, 0.45, 0.45 def c1, 0, 0, 0, 0 def c2, 0.5, 0.5, 0.5, 0.5 tex t0 // DUDV Map texbem t1, t0 // EMBM Reflection Map tex t2 // Color Map tex t3 mul t2, t2, t3 lrp t2, v0, t2, v0 // Lerp between the water color and the ambient color lrp r0.rgb, c2, t1, t2 // Lerp between the reflection and the water texture +mov r0.a, c0.a }; //------------------------------------------------------------------------------------------------ // TECHNIQUES //------------------------------------------------------------------------------------------------ technique TOceanWaterEMBM_11 { pass P0 { // Enable depth writing ZEnable = TRUE; ZWriteEnable = FALSE; ZFunc = LESSEQUAL; // Disable lighting Lighting = FALSE; // Enable fog (but not ranged based fog). We're doing vertex shader fog, so we don't need to // set the start, end or mode FogEnable = TRUE; RangeFogEnable = FALSE; // Disable stenciling StencilEnable = false; CullMode = CW; // Enable alpha blending or testing AlphaBlendEnable = TRUE; SrcBlend = SRCALPHA; DestBlend = INVSRCALPHA; AlphaTestEnable = FALSE; // Allow the use of multiple texcoord indices TexCoordIndex[0] = 0; TexCoordIndex[1] = 1; TexCoordIndex[2] = 2; TexCoordIndex[3] = 3; // Set the samplers Sampler[0] = ; Sampler[1] = ; Sampler[2] = ; Sampler[3] = ; TextureTransformFlags[0] = 0; TextureTransformFlags[1] = PROJECTED; TextureTransformFlags[2] = 0; TextureTransformFlags[3] = 0; // The distortion matrix for the dependent texture read BumpEnvMat00[1] = ; BumpEnvMat01[1] = 0.0f; BumpEnvMat10[1] = 0.0f; BumpEnvMat11[1] = ; VertexShader = compile vs_1_1 VS(); PixelShader = ; } }