Blender  V2.93
eevee_sampling.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * Copyright 2019, Blender Foundation.
17  */
18 
23 #include "eevee_private.h"
24 
25 #include "BLI_rand.h"
26 
33 void EEVEE_sample_ball(int sample_ofs, float radius, float rsample[3])
34 {
35  double ht_point[3];
36  double ht_offset[3] = {0.0, 0.0, 0.0};
37  const uint ht_primes[3] = {2, 3, 7};
38 
39  BLI_halton_3d(ht_primes, ht_offset, sample_ofs, ht_point);
40 
41  /* De-correlate AA and shadow samples. (see T68594) */
42  ht_point[0] = fmod(ht_point[0] * 1151.0, 1.0);
43  ht_point[1] = fmod(ht_point[1] * 1069.0, 1.0);
44  ht_point[2] = fmod(ht_point[2] * 1151.0, 1.0);
45 
46  float omega = ht_point[1] * 2.0f * M_PI;
47 
48  rsample[2] = ht_point[0] * 2.0f - 1.0f; /* cos theta */
49 
50  float r = sqrtf(fmaxf(0.0f, 1.0f - rsample[2] * rsample[2])); /* sin theta */
51 
52  rsample[0] = r * cosf(omega);
53  rsample[1] = r * sinf(omega);
54 
55  radius *= sqrt(sqrt(ht_point[2]));
56  mul_v3_fl(rsample, radius);
57 }
58 
59 void EEVEE_sample_rectangle(int sample_ofs,
60  const float x_axis[3],
61  const float y_axis[3],
62  float size_x,
63  float size_y,
64  float rsample[3])
65 {
66  double ht_point[2];
67  double ht_offset[2] = {0.0, 0.0};
68  const uint ht_primes[2] = {2, 3};
69 
70  BLI_halton_2d(ht_primes, ht_offset, sample_ofs, ht_point);
71 
72  /* De-correlate AA and shadow samples. (see T68594) */
73  ht_point[0] = fmod(ht_point[0] * 1151.0, 1.0);
74  ht_point[1] = fmod(ht_point[1] * 1069.0, 1.0);
75 
76  /* Change distribution center to be 0,0 */
77  ht_point[0] = (ht_point[0] > 0.5f) ? ht_point[0] - 1.0f : ht_point[0];
78  ht_point[1] = (ht_point[1] > 0.5f) ? ht_point[1] - 1.0f : ht_point[1];
79 
80  zero_v3(rsample);
81  madd_v3_v3fl(rsample, x_axis, (ht_point[0] * 2.0f) * size_x);
82  madd_v3_v3fl(rsample, y_axis, (ht_point[1] * 2.0f) * size_y);
83 }
84 
85 void EEVEE_sample_ellipse(int sample_ofs,
86  const float x_axis[3],
87  const float y_axis[3],
88  float size_x,
89  float size_y,
90  float rsample[3])
91 {
92  double ht_point[2];
93  double ht_offset[2] = {0.0, 0.0};
94  const uint ht_primes[2] = {2, 3};
95 
96  BLI_halton_2d(ht_primes, ht_offset, sample_ofs, ht_point);
97 
98  /* Decorelate AA and shadow samples. (see T68594) */
99  ht_point[0] = fmod(ht_point[0] * 1151.0, 1.0);
100  ht_point[1] = fmod(ht_point[1] * 1069.0, 1.0);
101 
102  /* Uniform disc sampling. */
103  float omega = ht_point[1] * 2.0f * M_PI;
104  float r = sqrtf(ht_point[0]);
105  ht_point[0] = r * cosf(omega) * size_x;
106  ht_point[1] = r * sinf(omega) * size_y;
107 
108  zero_v3(rsample);
109  madd_v3_v3fl(rsample, x_axis, ht_point[0]);
110  madd_v3_v3fl(rsample, y_axis, ht_point[1]);
111 }
112 
113 void EEVEE_random_rotation_m4(int sample_ofs, float scale, float r_mat[4][4])
114 {
115  double ht_point[3];
116  double ht_offset[3] = {0.0, 0.0, 0.0};
117  const uint ht_primes[3] = {2, 3, 5};
118 
119  BLI_halton_3d(ht_primes, ht_offset, sample_ofs, ht_point);
120 
121  /* Decorelate AA and shadow samples. (see T68594) */
122  ht_point[0] = fmod(ht_point[0] * 1151.0, 1.0);
123  ht_point[1] = fmod(ht_point[1] * 1069.0, 1.0);
124  ht_point[2] = fmod(ht_point[2] * 1151.0, 1.0);
125 
126  rotate_m4(r_mat, 'X', ht_point[0] * scale);
127  rotate_m4(r_mat, 'Y', ht_point[1] * scale);
128  rotate_m4(r_mat, 'Z', ht_point[2] * scale);
129 }
sqrt(x)+1/max(0
#define M_PI
Definition: BLI_math_base.h:38
void rotate_m4(float mat[4][4], const char axis, const float angle)
Definition: math_matrix.c:2352
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void zero_v3(float r[3])
Random number functions.
void BLI_halton_3d(const unsigned int prime[3], double offset[3], int n, double *r)
Definition: rand.cc:323
void BLI_halton_2d(const unsigned int prime[2], double offset[2], int n, double *r)
Definition: rand.cc:310
unsigned int uint
Definition: BLI_sys_types.h:83
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble GLdouble r _GL_VOID_RET _GL_VOID GLfloat GLfloat r _GL_VOID_RET _GL_VOID GLint GLint r _GL_VOID_RET _GL_VOID GLshort GLshort r _GL_VOID_RET _GL_VOID GLdouble GLdouble r
void EEVEE_sample_ellipse(int sample_ofs, const float x_axis[3], const float y_axis[3], float size_x, float size_y, float rsample[3])
void EEVEE_random_rotation_m4(int sample_ofs, float scale, float r_mat[4][4])
void EEVEE_sample_ball(int sample_ofs, float radius, float rsample[3])
void EEVEE_sample_rectangle(int sample_ofs, const float x_axis[3], const float y_axis[3], float size_x, float size_y, float rsample[3])
#define sinf(x)
#define cosf(x)
#define fmaxf(x, y)
#define sqrtf(x)