Class AliasTable
Synopsis
#include <Source/Falcor/Utils/Sampling/AliasTable.h>
class dlldecl AliasTable
Description
Implements the alias method for sampling from a discrete probability distribution.
Methods
create | Create an alias table | |
getCount | Get the number of weights in the table. | |
getWeightSum | Get the total sum of all weights in the table. | |
setShaderData | Bind the alias table data to a given shader var. |
Source
Lines 35-68 in Source/Falcor/Utils/Sampling/AliasTable.h.
class dlldecl AliasTable
{
public:
using SharedPtr = std::shared_ptr<AliasTable>;
/** Create an alias table.
The weights don't need to be normalized to sum up to 1.
\param[in] weights The weights we'd like to sample each entry proportional to.
\param[in] rng The random number generator to use when creating the table.
\returns The alias table.
*/
static SharedPtr create(std::vector<float> weights, std::mt19937& rng);
/** Bind the alias table data to a given shader var.
\param[in] var The shader variable to set the data into.
*/
void setShaderData(const ShaderVar& var) const;
/** Get the number of weights in the table.
*/
uint32_t getCount() const { return mCount; }
/** Get the total sum of all weights in the table.
*/
double getWeightSum() const { return mWeightSum; }
private:
AliasTable(std::vector<float> weights, std::mt19937& rng);
uint32_t mCount; ///< Number of items in the alias table.
double mWeightSum; ///< Total weight of all elements used to create the alias table.
Buffer::SharedPtr mpItems; ///< Buffer containing table items.
Buffer::SharedPtr mpWeights; ///< Buffer containing item weights.
};