33 const uint32 samples_x,
34 const uint32 samples_y,
38 m_sample_xy.resize( samples_x * samples_y );
39 for (uint32 y = 0; y < samples_y; y++)
41 for (uint32 x = 0; x < samples_x; x++)
43 const size_t index = y * samples_x + x;
44 m_sample_xy[index].x = y;
45 m_sample_xy[index].y = x;
48 for (uint32 y = 0; y < samples_y; y++)
50 for (uint32 x = 0; x < samples_x-1; x++)
52 const float r = m_random.next();
53 const uint32 xx = std::min( uint32(
float(r) * (samples_x - x)) + x, samples_x-1u );
55 const size_t index1 = y * samples_x + x;
56 const size_t index2 = y * samples_x + xx;
58 std::swap( m_sample_xy[index1].y, m_sample_xy[index2].y );
61 for (uint32 x = 0; x < samples_x; x++)
63 for (uint32 y = 0; y < samples_y-1; y++)
65 const float r = m_random.next();
66 const uint32 yy = std::min( uint32(
float(r) * (samples_y - y)) + y, samples_y-1u );
68 const size_t index1 = y * samples_x + x;
69 const size_t index2 = yy * samples_x + x;
71 std::swap( m_sample_xy[index1].x, m_sample_xy[index2].x );
75 const uint32 num_samples = samples_x * samples_y;
76 const T inv = T(1.0) / T(num_samples);
77 for (uint32 y = 0; y < samples_y; y++)
79 for (uint32 x = 0; x < samples_x; x++)
81 const size_t index = y * samples_x + x;
82 samples[index][0] = min( (T(m_sample_xy[index].x + x * samples_y) + m_random.next()) * inv, T(1) );
83 samples[index][1] = min( (T(m_sample_xy[index].y + y * samples_x) + m_random.next()) * inv, T(1) );
86 if (ordering == kRandom)
88 for (uint32 i = 0; i < num_samples; i++)
90 const float r = m_random.next();
91 const uint32 j = std::min( uint32(
float(r) * (num_samples - i)) + i, num_samples-1u );
92 std::swap( samples[i], samples[j] );
101 const uint32 samples_x,
102 const uint32 samples_y,
105 m_sample_xy.resize( samples_x * samples_y );
106 for (uint32 y = 0; y < samples_y; y++)
108 for (uint32 x = 0; x < samples_x; x++)
110 const size_t index = y * samples_x + x;
111 m_sample_xy[index].x = y;
112 m_sample_xy[index].y = x;
115 for (uint32 y = 0; y < samples_y; y++)
117 for (uint32 x = 0; x < samples_x-1; x++)
119 const float r = m_random.next();
120 const uint32 xx = std::min( uint32(
float(r) * (samples_x - x)) + x, samples_x-1u );
122 const size_t index1 = y * samples_x + x;
123 const size_t index2 = y * samples_x + xx;
125 std::swap( m_sample_xy[index1].y, m_sample_xy[index2].y );
128 for (uint32 x = 0; x < samples_x; x++)
130 for (uint32 y = 0; y < samples_y-1; y++)
132 const float r = m_random.next();
133 const uint32 yy = std::min( uint32(
float(r) * (samples_y - y)) + y, samples_y-1u );
135 const size_t index1 = y * samples_x + x;
136 const size_t index2 = yy * samples_x + x;
138 std::swap( m_sample_xy[index1].x, m_sample_xy[index2].x );
142 const uint32 num_samples = samples_x * samples_y;
143 const T inv = T(1.0) / T(num_samples);
144 for (uint32 y = 0; y < samples_y; y++)
146 for (uint32 x = 0; x < samples_x; x++)
148 const size_t index = y * samples_x + x;
149 samples[index][0] = (T(m_sample_xy[index].x + x * samples_y) + m_random.next()) * inv;
150 samples[index][1] = (T(m_sample_xy[index].y + y * samples_x) + m_random.next()) * inv;
151 samples[index][2] = (T(index) + m_random.next()) * inv;
154 for (uint32 i = 0; i < num_samples; i++)
156 const float r = m_random.next();
157 const uint32 j = std::min( uint32(
float(r) * (num_samples - i)) + i, num_samples-1u );
158 std::swap( samples[i], samples[j] );
162 template <
typename T>
164 const uint32 samples_x,
165 const uint32 samples_y,
169 for (uint32 offset = 0; offset <= 2; offset += 2)
171 m_sample_xy.resize( samples_x * samples_y );
172 for (uint32 y = 0; y < samples_y; y++)
174 for (uint32 x = 0; x < samples_x; x++)
176 const size_t index = y * samples_x + x;
177 m_sample_xy[index].x = y;
178 m_sample_xy[index].y = x;
181 for (uint32 y = 0; y < samples_y; y++)
183 for (uint32 x = 0; x < samples_x-1; x++)
185 const float r = m_random.next();
186 const uint32 xx = std::min( uint32(
float(r) * (samples_x - x)) + x, samples_x-1u );
188 const size_t index1 = y * samples_x + x;
189 const size_t index2 = y * samples_x + xx;
191 std::swap( m_sample_xy[index1].y, m_sample_xy[index2].y );
194 for (uint32 x = 0; x < samples_x; x++)
196 for (uint32 y = 0; y < samples_y-1; y++)
198 const float r = m_random.next();
199 const uint32 yy = std::min( uint32(
float(r) * (samples_y - y)) + y, samples_y-1u );
201 const size_t index1 = y * samples_x + x;
202 const size_t index2 = yy * samples_x + x;
204 std::swap( m_sample_xy[index1].x, m_sample_xy[index2].x );
208 const uint32 num_samples = samples_x * samples_y;
209 const T inv = T(1.0) / T(num_samples);
210 for (uint32 y = 0; y < samples_y; y++)
212 for (uint32 x = 0; x < samples_x; x++)
214 const size_t index = y * samples_x + x;
215 samples[index][offset+0] = (T(m_sample_xy[index].x + x * samples_y) + m_random.next()) * inv;
216 samples[index][offset+1] = (T(m_sample_xy[index].y + y * samples_x) + m_random.next()) * inv;
219 if (ordering == kRandom)
221 const uint32 num_samples = samples_x * samples_y;
222 for (uint32 i = 0; i < num_samples; i++)
224 const float r = m_random.next();
225 const uint32 j = std::min( uint32(
float(r) * (num_samples - i)) + i, num_samples-1u );
226 std::swap( samples[i][offset+0], samples[j][offset+0] );
227 std::swap( samples[i][offset+1], samples[j][offset+1] );
void sample(const uint32 samples_x, const uint32 samples_y, Vector< T, 2 > *samples, Ordering ordering=kRandom)
Definition: multijitter_inline.h:32
Define a vector_view POD type and plain_view() for std::vector.
Definition: diff.h:38