-
Notifications
You must be signed in to change notification settings - Fork 3
/
sphere-sample.h
54 lines (43 loc) · 1.2 KB
/
sphere-sample.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// sphere-sample.h -- Sample a sphere
//
// Copyright (C) 2010, 2011 Miles Bader <miles@gnu.org>
//
// This source code is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 3, or (at
// your option) any later version. See the file COPYING for more details.
//
// Written by Miles Bader <miles@gnu.org>
//
#ifndef SNOGRAY_SPHERE_SAMPLE_H
#define SNOGRAY_SPHERE_SAMPLE_H
#include "cone-sample.h"
namespace snogray {
// Return a sample vector uniformly distributed over a unit-sphere.
// PARAM is the sample parameter.
//
static inline Vec
sphere_sample (const UV ¶m)
{
// Sampling an entire sphere is a special case of sampling a
// degenerate "cone", where the cone's angle is 2*PI (a rather wacky
// cone, but it works).
//
return cone_sample (-1, param);
}
// Return a parameter for which sample_sphere would return DIR.
//
static inline UV
sphere_sample_inverse (const Vec &dir)
{
return cone_sample_inverse (-1, dir);
}
// Return the PDF for a sphere sample.
//
static inline float
sphere_sample_pdf ()
{
return cone_sample_pdf (-1);
}
}
#endif // SNOGRAY_SPHERE_SAMPLE_H