~ubuntu-branches/ubuntu/trusty/blender/trusty-proposed

« back to all changes in this revision

Viewing changes to intern/cycles/kernel/kernel_random.h

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2013-08-14 10:43:49 UTC
  • mfrom: (14.2.19 sid)
  • Revision ID: package-import@ubuntu.com-20130814104349-t1d5mtwkphp12dyj
Tags: 2.68a-3
* Upload to unstable
* debian/: python3.3 Depends simplified
  - debian/control: python3.3 Depends dropped
    for blender-data package
  - 0001-blender_thumbnailer.patch refreshed
* debian/control: libavcodec b-dep versioning dropped

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
 */
18
18
 
 
19
#include "kernel_jitter.h"
 
20
 
19
21
CCL_NAMESPACE_BEGIN
20
22
 
21
23
typedef uint RNG;
100
102
        return index;
101
103
}
102
104
 
103
 
__device_inline float path_rng(KernelGlobals *kg, RNG *rng, int sample, int dimension)
 
105
__device_inline float path_rng_1D(KernelGlobals *kg, RNG *rng, int sample, int num_samples, int dimension)
104
106
{
 
107
#ifdef __CMJ__
 
108
        if(kernel_data.integrator.sampling_pattern == SAMPLING_PATTERN_CMJ) {
 
109
                /* correlated multi-jittered */
 
110
                int p = *rng + dimension;
 
111
                return cmj_sample_1D(sample, num_samples, p);
 
112
        }
 
113
#endif
 
114
 
105
115
#ifdef __SOBOL_FULL_SCREEN__
106
116
        uint result = sobol_dimension(kg, *rng, dimension);
107
117
        float r = (float)result * (1.0f/(float)0xFFFFFFFF);
115
125
        float shift;
116
126
 
117
127
        if(dimension & 1)
118
 
                shift = (*rng >> 16)/((float)0xFFFF);
 
128
                shift = (*rng >> 16) * (1.0f/(float)0xFFFF);
119
129
        else
120
 
                shift = (*rng & 0xFFFF)/((float)0xFFFF);
 
130
                shift = (*rng & 0xFFFF) * (1.0f/(float)0xFFFF);
121
131
 
122
132
        return r + shift - floorf(r + shift);
123
133
#endif
124
134
}
125
135
 
126
 
__device_inline void path_rng_init(KernelGlobals *kg, __global uint *rng_state, int sample, RNG *rng, int x, int y, float *fx, float *fy)
 
136
__device_inline void path_rng_2D(KernelGlobals *kg, RNG *rng, int sample, int num_samples, int dimension, float *fx, float *fy)
 
137
{
 
138
#ifdef __CMJ__
 
139
        if(kernel_data.integrator.sampling_pattern == SAMPLING_PATTERN_CMJ) {
 
140
                /* correlated multi-jittered */
 
141
                int p = *rng + dimension;
 
142
                cmj_sample_2D(sample, num_samples, p, fx, fy);
 
143
        }
 
144
#endif
 
145
 
 
146
        /* sobol */
 
147
        *fx = path_rng_1D(kg, rng, sample, num_samples, dimension);
 
148
        *fy = path_rng_1D(kg, rng, sample, num_samples, dimension + 1);
 
149
}
 
150
 
 
151
__device_inline void path_rng_init(KernelGlobals *kg, __global uint *rng_state, int sample, int num_samples, RNG *rng, int x, int y, float *fx, float *fy)
127
152
{
128
153
#ifdef __SOBOL_FULL_SCREEN__
129
154
        uint px, py;
153
178
                *fy = 0.5f;
154
179
        }
155
180
        else {
156
 
                *fx = path_rng(kg, rng, sample, PRNG_FILTER_U);
157
 
                *fy = path_rng(kg, rng, sample, PRNG_FILTER_V);
 
181
                path_rng_2D(kg, rng, sample, num_samples, PRNG_FILTER_U, fx, fy);
158
182
        }
159
183
#endif
160
184
}
168
192
 
169
193
/* Linear Congruential Generator */
170
194
 
171
 
__device float path_rng(KernelGlobals *kg, RNG *rng, int sample, int dimension)
 
195
__device float path_rng(KernelGlobals *kg, RNG& rng, int sample, int dimension)
 
196
{
 
197
}
 
198
 
 
199
__device_inline float path_rng_1D(KernelGlobals *kg, RNG& rng, int sample, int num_samples, int dimension)
172
200
{
173
201
        /* implicit mod 2^32 */
174
 
        *rng = (1103515245*(*rng) + 12345);
175
 
        return (float)*rng * (1.0f/(float)0xFFFFFFFF);
176
 
}
177
 
 
178
 
__device void path_rng_init(KernelGlobals *kg, __global uint *rng_state, int sample, RNG *rng, int x, int y, float *fx, float *fy)
 
202
        rng = (1103515245*(rng) + 12345);
 
203
        return (float)rng * (1.0f/(float)0xFFFFFFFF);
 
204
}
 
205
 
 
206
__device_inline void path_rng_2D(KernelGlobals *kg, RNG& rng, int sample, int num_samples, int dimension, float *fx, float *fy)
 
207
{
 
208
        *fx = path_rng_1D(kg, rng, sample, num_samples, dimension);
 
209
        *fy = path_rng_1D(kg, rng, sample, num_samples, dimension + 1);
 
210
}
 
211
 
 
212
__device void path_rng_init(KernelGlobals *kg, __global uint *rng_state, int sample, int num_samples, RNG *rng, int x, int y, float *fx, float *fy)
179
213
{
180
214
        /* load state */
181
215
        *rng = *rng_state;
187
221
                *fy = 0.5f;
188
222
        }
189
223
        else {
190
 
                *fx = path_rng(kg, rng, sample, PRNG_FILTER_U);
191
 
                *fy = path_rng(kg, rng, sample, PRNG_FILTER_V);
 
224
                path_rng_2D(kg, rng, sample, num_samples, PRNG_FILTER_U, fx, fy);
192
225
        }
193
226
}
194
227
 
200
233
 
201
234
#endif
202
235
 
 
236
__device float lcg_step(uint *rng)
 
237
{
 
238
        /* implicit mod 2^32 */
 
239
        *rng = (1103515245*(*rng) + 12345);
 
240
        return (float)*rng * (1.0f/(float)0xFFFFFFFF);
 
241
}
 
242
 
 
243
__device uint lcg_init(uint seed)
 
244
{
 
245
        uint rng = seed;
 
246
        lcg_step(&rng);
 
247
        return rng;
 
248
}
 
249
 
203
250
CCL_NAMESPACE_END
204
251