| 40 | const int ReflectionSimulator::kRayBatchSize = 32; |
| 41 | |
| 42 | ReflectionSimulator::ReflectionSimulator(int maxNumRays, |
| 43 | int numDiffuseSamples, |
| 44 | float maxDuration, |
| 45 | int maxOrder, |
| 46 | int maxNumSources, |
| 47 | int numThreads) |
| 48 | : mMaxNumRays(maxNumRays) |
| 49 | , mNumDiffuseSamples(numDiffuseSamples) |
| 50 | , mMaxDuration(maxDuration) |
| 51 | , mMaxOrder(maxOrder) |
| 52 | , mMaxNumSources(maxNumSources) |
| 53 | , mNumThreads(numThreads) |
| 54 | , mNumSources(maxNumSources) |
| 55 | , mSources(nullptr) |
| 56 | , mListener(nullptr) |
| 57 | , mDirectivities(nullptr) |
| 58 | , mNumRays(maxNumRays) |
| 59 | , mNumBounces(0) |
| 60 | , mDuration(maxDuration) |
| 61 | , mOrder(maxOrder) |
| 62 | , mIrradianceMinDistance(1.0f) |
| 63 | , mListenerSamples(maxNumRays) |
| 64 | , mDiffuseSamples(numDiffuseSamples) |
| 65 | , mListenerCoeffs(maxNumRays, SphericalHarmonics::numCoeffsForOrder(maxOrder)) |
| 66 | , mThreadState(numThreads) |
| 67 | { |
| 68 | Sampling::generateSphereSamples(maxNumRays, mListenerSamples.data()); |
| 69 | Sampling::generateHemisphereSamples(numDiffuseSamples, mDiffuseSamples.data()); |
| 70 | |
| 71 | for (auto i = 0; i < maxNumRays; ++i) |
| 72 | { |
| 73 | for (auto l = 0, j = 0; l <= maxOrder; ++l) |
| 74 | { |
| 75 | for (auto m = -l; m <= l; ++m, ++j) |
| 76 | { |
| 77 | mListenerCoeffs[i][j] = SphericalHarmonics::evaluate(l, m, mListenerSamples[i]); |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | for (auto i = 0; i < numThreads; ++i) |
| 83 | { |
| 84 | mThreadState[i].energyFields.resize(maxNumSources); |
| 85 | for (auto j = 0; j < maxNumSources; ++j) |
| 86 | { |
| 87 | mThreadState[i].energyFields[j] = make_unique<EnergyField>(maxDuration, maxOrder); |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | void ReflectionSimulator::simulate(const IScene& scene, |
| 93 | int numSources, |