#ifndef WAVE_FX #define float2 D3DXVECTOR2 #define float3 D3DXVECTOR3 #endif struct Wave { float wavelength; float amplitude; float2 direction; float deformation; }; #define NWAVES 4 Wave wave[NWAVES] = { {1.0f, 1.1f, float2(0.98,0.17), 1.3f }, {1.5f, 2.1f, float2(0.98,-0.17), 1.3f }, {2.5f, 1.1f, float2(0.934,0.342), 1.2f }, {3.5f, 2.1f, float2(0.934,-0.342), 1.0f } }; //return the position difference float3 evaluateWave(Wave w, float phase) { float2 offset; #ifdef WAVE_FX sincos(phase, offset.x, offset.y); #else offset.x = sin(phase); offset.y = cos(phase); #endif float2 tempPos = float2(0,0); #ifdef WAVE_FX tempPos.xy += offset * w.amplitude * float2(-1, 1); #else tempPos.x -= offset.x * w.amplitude; tempPos.y += offset.y * w.amplitude; #endif tempPos.x -= tempPos.y * w.deformation; return float3(w.direction.x * tempPos.x, tempPos.y, w.direction.y * tempPos.x); } float3 evaluateWaveDerivative(Wave w, float phase) { float2 offset; #ifdef WAVE_FX sincos(phase, offset.x, offset.y); #else offset.x = sin(phase); offset.y = cos(phase); #endif float dxdp = - offset.y * w.amplitude * w.direction.x; float dydp = - offset.x * w.amplitude; float dzdp = - offset.y * w.amplitude * w.direction.y; return float3(dxdp - dydp * w.deformation, dydp, dzdp); } #ifndef WAVE_FX #undef float2 #undef float3 #endif