Blender  V3.3
eevee_sampling.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2019 Blender Foundation. */
3 
8 #include "eevee_private.h"
9 
10 #include "BLI_rand.h"
11 
12 void EEVEE_sample_ball(int sample_ofs, float radius, float rsample[3])
13 {
14  double ht_point[3];
15  double ht_offset[3] = {0.0, 0.0, 0.0};
16  const uint ht_primes[3] = {2, 3, 7};
17 
18  BLI_halton_3d(ht_primes, ht_offset, sample_ofs, ht_point);
19 
20  /* De-correlate AA and shadow samples. (see T68594) */
21  ht_point[0] = fmod(ht_point[0] * 1151.0, 1.0);
22  ht_point[1] = fmod(ht_point[1] * 1069.0, 1.0);
23  ht_point[2] = fmod(ht_point[2] * 1151.0, 1.0);
24 
25  float omega = ht_point[1] * 2.0f * M_PI;
26 
27  rsample[2] = ht_point[0] * 2.0f - 1.0f; /* cos theta */
28 
29  float r = sqrtf(fmaxf(0.0f, 1.0f - rsample[2] * rsample[2])); /* sin theta */
30 
31  rsample[0] = r * cosf(omega);
32  rsample[1] = r * sinf(omega);
33 
34  radius *= sqrt(sqrt(ht_point[2]));
35  mul_v3_fl(rsample, radius);
36 }
37 
38 void EEVEE_sample_rectangle(int sample_ofs,
39  const float x_axis[3],
40  const float y_axis[3],
41  float size_x,
42  float size_y,
43  float rsample[3])
44 {
45  double ht_point[2];
46  double ht_offset[2] = {0.0, 0.0};
47  const uint ht_primes[2] = {2, 3};
48 
49  BLI_halton_2d(ht_primes, ht_offset, sample_ofs, ht_point);
50 
51  /* De-correlate AA and shadow samples. (see T68594) */
52  ht_point[0] = fmod(ht_point[0] * 1151.0, 1.0);
53  ht_point[1] = fmod(ht_point[1] * 1069.0, 1.0);
54 
55  /* Change distribution center to be 0,0 */
56  ht_point[0] = (ht_point[0] > 0.5f) ? ht_point[0] - 1.0f : ht_point[0];
57  ht_point[1] = (ht_point[1] > 0.5f) ? ht_point[1] - 1.0f : ht_point[1];
58 
59  zero_v3(rsample);
60  madd_v3_v3fl(rsample, x_axis, (ht_point[0] * 2.0f) * size_x);
61  madd_v3_v3fl(rsample, y_axis, (ht_point[1] * 2.0f) * size_y);
62 }
63 
64 void EEVEE_sample_ellipse(int sample_ofs,
65  const float x_axis[3],
66  const float y_axis[3],
67  float size_x,
68  float size_y,
69  float rsample[3])
70 {
71  double ht_point[2];
72  double ht_offset[2] = {0.0, 0.0};
73  const uint ht_primes[2] = {2, 3};
74 
75  BLI_halton_2d(ht_primes, ht_offset, sample_ofs, ht_point);
76 
77  /* Decorrelate AA and shadow samples. (see T68594) */
78 
79  ht_point[0] = fmod(ht_point[0] * 1151.0, 1.0);
80  ht_point[1] = fmod(ht_point[1] * 1069.0, 1.0);
81 
82  /* Uniform disc sampling. */
83  float omega = ht_point[1] * 2.0f * M_PI;
84  float r = sqrtf(ht_point[0]);
85  ht_point[0] = r * cosf(omega) * size_x;
86  ht_point[1] = r * sinf(omega) * size_y;
87 
88  zero_v3(rsample);
89  madd_v3_v3fl(rsample, x_axis, ht_point[0]);
90  madd_v3_v3fl(rsample, y_axis, ht_point[1]);
91 }
92 
93 void EEVEE_random_rotation_m4(int sample_ofs, float scale, float r_mat[4][4])
94 {
95  double ht_point[3];
96  double ht_offset[3] = {0.0, 0.0, 0.0};
97  const uint ht_primes[3] = {2, 3, 5};
98 
99  BLI_halton_3d(ht_primes, ht_offset, sample_ofs, ht_point);
100 
101  /* Decorrelate AA and shadow samples. (see T68594) */
102  ht_point[0] = fmod(ht_point[0] * 1151.0, 1.0);
103  ht_point[1] = fmod(ht_point[1] * 1069.0, 1.0);
104  ht_point[2] = fmod(ht_point[2] * 1151.0, 1.0);
105 
106  rotate_m4(r_mat, 'X', ht_point[0] * scale);
107  rotate_m4(r_mat, 'Y', ht_point[1] * scale);
108  rotate_m4(r_mat, 'Z', ht_point[2] * scale);
109 }
sqrt(x)+1/max(0
#define M_PI
Definition: BLI_math_base.h:20
void rotate_m4(float mat[4][4], char axis, float angle)
Definition: math_matrix.c:2325
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:311
void BLI_halton_2d(const unsigned int prime[2], double offset[2], int n, double *r)
Definition: rand.cc:298
unsigned int uint
Definition: BLI_sys_types.h:67
_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
#define sinf(x)
Definition: cuda/compat.h:102
#define cosf(x)
Definition: cuda/compat.h:101
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 fmaxf(x, y)
Definition: metal/compat.h:228
#define sqrtf(x)
Definition: metal/compat.h:243