[1777] | 1 | #ifndef WAVE_FX
|
---|
| 2 | #define float2 D3DXVECTOR2
|
---|
| 3 | #define float3 D3DXVECTOR3
|
---|
| 4 | #endif
|
---|
| 5 |
|
---|
| 6 | struct Wave
|
---|
| 7 | {
|
---|
| 8 | float wavelength;
|
---|
| 9 | float amplitude;
|
---|
| 10 | float2 direction;
|
---|
| 11 | float deformation;
|
---|
| 12 | };
|
---|
| 13 |
|
---|
| 14 | #define NWAVES 4
|
---|
| 15 | Wave wave[NWAVES] = { {1.0f, 1.1f, float2(0.98,0.17), 1.3f },
|
---|
| 16 | {1.5f, 2.1f, float2(0.98,-0.17), 1.3f },
|
---|
| 17 | {2.5f, 1.1f, float2(0.934,0.342), 1.2f },
|
---|
| 18 | {3.5f, 2.1f, float2(0.934,-0.342), 1.0f }
|
---|
| 19 | };
|
---|
| 20 |
|
---|
| 21 | //return the position difference
|
---|
| 22 | float3 evaluateWave(Wave w, float phase)
|
---|
| 23 | {
|
---|
| 24 |
|
---|
| 25 | float2 offset;
|
---|
| 26 | #ifdef WAVE_FX
|
---|
| 27 | sincos(phase, offset.x, offset.y);
|
---|
| 28 | #else
|
---|
| 29 | offset.x = sin(phase);
|
---|
| 30 | offset.y = cos(phase);
|
---|
| 31 | #endif
|
---|
| 32 | float2 tempPos = float2(0,0);
|
---|
| 33 | #ifdef WAVE_FX
|
---|
| 34 | tempPos.xy += offset * w.amplitude * float2(-1, 1);
|
---|
| 35 | #else
|
---|
| 36 | tempPos.x -= offset.x * w.amplitude;
|
---|
| 37 | tempPos.y += offset.y * w.amplitude;
|
---|
| 38 | #endif
|
---|
| 39 | tempPos.x -= tempPos.y * w.deformation;
|
---|
| 40 |
|
---|
| 41 | return float3(w.direction.x * tempPos.x, tempPos.y, w.direction.y * tempPos.x);
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | float3 evaluateWaveDerivative(Wave w, float phase)
|
---|
| 45 | {
|
---|
| 46 | float2 offset;
|
---|
| 47 | #ifdef WAVE_FX
|
---|
| 48 | sincos(phase, offset.x, offset.y);
|
---|
| 49 | #else
|
---|
| 50 | offset.x = sin(phase);
|
---|
| 51 | offset.y = cos(phase);
|
---|
| 52 | #endif
|
---|
| 53 |
|
---|
| 54 | float dxdp = - offset.y * w.amplitude * w.direction.x;
|
---|
| 55 | float dydp = - offset.x * w.amplitude;
|
---|
| 56 | float dzdp = - offset.y * w.amplitude * w.direction.y;
|
---|
| 57 |
|
---|
| 58 | return float3(dxdp - dydp * w.deformation, dydp, dzdp);
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | #ifndef WAVE_FX
|
---|
| 62 | #undef float2
|
---|
| 63 | #undef float3
|
---|
| 64 | #endif
|
---|