Blender  V3.3
eevee_shader_shared.hh
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
9 #ifndef USE_GPU_SHADER_CREATE_INFO
10 # pragma once
11 
12 # include "BLI_memory_utils.hh"
13 # include "DRW_gpu_wrapper.hh"
14 
15 # include "eevee_defines.hh"
16 
17 # include "GPU_shader_shared.h"
18 
19 namespace blender::eevee {
20 
21 using draw::Framebuffer;
22 using draw::SwapChain;
23 using draw::Texture;
24 using draw::TextureFromPool;
25 
26 #endif
27 
28 #define UBO_MIN_MAX_SUPPORTED_SIZE 1 << 14
29 
30 /* -------------------------------------------------------------------- */
34 enum eSamplingDimension : uint32_t {
35  SAMPLING_FILTER_U = 0u,
36  SAMPLING_FILTER_V = 1u,
37  SAMPLING_LENS_U = 2u,
38  SAMPLING_LENS_V = 3u,
39  SAMPLING_TIME = 4u,
40  SAMPLING_SHADOW_U = 5u,
41  SAMPLING_SHADOW_V = 6u,
42  SAMPLING_SHADOW_W = 7u,
43  SAMPLING_SHADOW_X = 8u,
44  SAMPLING_SHADOW_Y = 9u,
45  SAMPLING_CLOSURE = 10u,
46  SAMPLING_LIGHTPROBE = 11u,
47  SAMPLING_TRANSPARENCY = 12u,
48  SAMPLING_SSS_U = 13u,
49  SAMPLING_SSS_V = 14u,
50  SAMPLING_RAYTRACE_U = 15u,
51  SAMPLING_RAYTRACE_V = 16u,
52  SAMPLING_RAYTRACE_W = 17u,
53  SAMPLING_RAYTRACE_X = 18u
54 };
55 
60 #define SAMPLING_DIMENSION_COUNT 20
61 
62 /* NOTE(@fclem): Needs to be used in #StorageBuffer because of arrays of scalar. */
63 struct SamplingData {
65  float dimensions[SAMPLING_DIMENSION_COUNT];
66 };
68 
69 /* Returns total sample count in a web pattern of the given size. */
70 static inline int sampling_web_sample_count_get(int web_density, int ring_count)
71 {
72  return ((ring_count * ring_count + ring_count) / 2) * web_density + 1;
73 }
74 
75 /* Returns lowest possible ring count that contains at least sample_count samples. */
76 static inline int sampling_web_ring_count_get(int web_density, int sample_count)
77 {
78  /* Inversion of web_sample_count_get(). */
79  float x = 2.0f * (float(sample_count) - 1.0f) / float(web_density);
80  /* Solving polynomial. We only search positive solution. */
81  float discriminant = 1.0f + 4.0f * x;
82  return int(ceilf(0.5f * (sqrtf(discriminant) - 1.0f)));
83 }
84 
87 /* -------------------------------------------------------------------- */
91 enum eCameraType : uint32_t {
92  CAMERA_PERSP = 0u,
93  CAMERA_ORTHO = 1u,
94  CAMERA_PANO_EQUIRECT = 2u,
95  CAMERA_PANO_EQUISOLID = 3u,
96  CAMERA_PANO_EQUIDISTANT = 4u,
97  CAMERA_PANO_MIRROR = 5u
98 };
99 
100 static inline bool is_panoramic(eCameraType type)
101 {
102  return type > CAMERA_ORTHO;
103 }
104 
105 struct CameraData {
106  /* View Matrices of the camera, not from any view! */
107  float4x4 persmat;
108  float4x4 persinv;
109  float4x4 viewmat;
110  float4x4 viewinv;
111  float4x4 winmat;
112  float4x4 wininv;
114  float2 uv_scale;
115  float2 uv_bias;
117  float2 equirect_scale;
118  float2 equirect_scale_inv;
119  float2 equirect_bias;
120  float fisheye_fov;
121  float fisheye_lens;
123  float clip_near;
124  float clip_far;
125  eCameraType type;
126 
127  bool initialized;
128 
129 #ifdef __cplusplus
130  /* Small constructor to allow detecting new buffers. */
131  CameraData() : initialized(false){};
132 #endif
133 };
135 
136 
138 /* -------------------------------------------------------------------- */
142 #define FILM_PRECOMP_SAMPLE_MAX 16
143 
144 struct FilmSample {
145  int2 texel;
146  float weight;
148  float weight_sum_inv;
149 };
150 BLI_STATIC_ASSERT_ALIGN(FilmSample, 16)
151 
152 struct FilmData {
154  int2 extent;
156  int2 offset;
158  int2 render_extent;
165  float2 subpixel_offset;
167  float2 extent_inv;
169  bool1 use_history;
171  bool1 use_reprojection;
173  bool1 has_data;
175  bool1 any_render_pass_1;
176  bool1 any_render_pass_2;
178  float background_opacity;
179  float _pad0;
181  int color_len, value_len;
183  int mist_id;
184  int normal_id;
185  int vector_id;
186  int diffuse_light_id;
187  int diffuse_color_id;
188  int specular_light_id;
189  int specular_color_id;
190  int volume_light_id;
191  int emission_id;
192  int environment_id;
193  int shadow_id;
194  int ambient_occlusion_id;
196  int depth_id;
197  int combined_id;
199  int display_id;
201  bool1 display_is_value;
203  bool1 display_only;
205  int aov_color_id, aov_color_len;
206  int aov_value_id, aov_value_len;
208  float mist_scale, mist_bias, mist_exponent;
210  float exposure_scale;
212  int scaling_factor;
214  float filter_radius;
216  int samples_len;
218  float samples_weight_total;
219  FilmSample samples[FILM_PRECOMP_SAMPLE_MAX];
220 };
221 BLI_STATIC_ASSERT_ALIGN(FilmData, 16)
222 
223 static inline float film_filter_weight(float filter_radius, float sample_distance_sqr)
224 {
225 #if 1 /* Faster */
226  /* Gaussian fitted to Blackman-Harris. */
227  float r = sample_distance_sqr / (filter_radius * filter_radius);
228  const float sigma = 0.284;
229  const float fac = -0.5 / (sigma * sigma);
230  float weight = expf(fac * r);
231 #else
232  /* Blackman-Harris filter. */
233  float r = M_2PI * saturate(0.5 + sqrtf(sample_distance_sqr) / (2.0 * filter_radius));
234  float weight = 0.35875 - 0.48829 * cosf(r) + 0.14128 * cosf(2.0 * r) - 0.01168 * cosf(3.0 * r);
235 #endif
236  return weight;
237 }
238 
241 /* -------------------------------------------------------------------- */
245 /* Theoretical max is 128 as we are using texture array and VRAM usage.
246  * However, the output_aov() function perform a linear search inside all the hashes.
247  * If we find a way to avoid this we could bump this number up. */
248 #define AOV_MAX 16
249 
250 /* NOTE(@fclem): Needs to be used in #StorageBuffer because of arrays of scalar. */
251 struct AOVsInfoData {
252  uint hash_value[AOV_MAX];
253  uint hash_color[AOV_MAX];
254  /* Length of used data. */
255  uint color_len;
256  uint value_len;
258  int display_id;
260  bool1 display_is_value;
261 };
263 
264 
266 /* -------------------------------------------------------------------- */
270 #define VELOCITY_INVALID 512.0
271 
272 enum eVelocityStep : uint32_t {
273  STEP_PREVIOUS = 0,
274  STEP_NEXT = 1,
275  STEP_CURRENT = 2,
276 };
277 
278 struct VelocityObjectIndex {
280  int3 ofs;
282  uint resource_id;
283 
284 #ifdef __cplusplus
285  VelocityObjectIndex() : ofs(-1, -1, -1), resource_id(-1){};
286 #endif
287 };
288 BLI_STATIC_ASSERT_ALIGN(VelocityObjectIndex, 16)
289 
290 struct VelocityGeometryIndex {
292  int3 ofs;
294  bool1 do_deform;
296  int3 len;
297 
298  int _pad0;
299 
300 #ifdef __cplusplus
301  VelocityGeometryIndex() : ofs(-1, -1, -1), do_deform(false), len(-1, -1, -1), _pad0(1){};
302 #endif
303 };
304 BLI_STATIC_ASSERT_ALIGN(VelocityGeometryIndex, 16)
305 
306 struct VelocityIndex {
307  VelocityObjectIndex obj;
308  VelocityGeometryIndex geo;
309 };
310 BLI_STATIC_ASSERT_ALIGN(VelocityGeometryIndex, 16)
311 
312 
314 /* -------------------------------------------------------------------- */
318 enum eClosureBits : uint32_t {
320  CLOSURE_DIFFUSE = (1u << 0u),
321  CLOSURE_SSS = (1u << 1u),
322  CLOSURE_REFLECTION = (1u << 2u),
323  CLOSURE_REFRACTION = (1u << 3u),
324  /* Non-stencil bits. */
325  CLOSURE_TRANSPARENCY = (1u << 8u),
326  CLOSURE_EMISSION = (1u << 9u),
327  CLOSURE_HOLDOUT = (1u << 10u),
328  CLOSURE_VOLUME = (1u << 11u),
329  CLOSURE_AMBIENT_OCCLUSION = (1u << 12u),
330 };
331 
334 /* -------------------------------------------------------------------- */
338 #define UTIL_TEX_SIZE 64
339 #define UTIL_BTDF_LAYER_COUNT 16
340 /* Scale and bias to avoid interpolation of the border pixel.
341  * Remap UVs to the border pixels centers. */
342 #define UTIL_TEX_UV_SCALE ((UTIL_TEX_SIZE - 1.0f) / UTIL_TEX_SIZE)
343 #define UTIL_TEX_UV_BIAS (0.5f / UTIL_TEX_SIZE)
344 
345 #define UTIL_BLUE_NOISE_LAYER 0
346 #define UTIL_LTC_MAT_LAYER 1
347 #define UTIL_LTC_MAG_LAYER 2
348 #define UTIL_BSDF_LAYER 2
349 #define UTIL_BTDF_LAYER 3
350 #define UTIL_DISK_INTEGRAL_LAYER 3
351 #define UTIL_DISK_INTEGRAL_COMP 2
352 
353 #ifndef __cplusplus
354 /* Fetch texel. Wrapping if above range. */
355 float4 utility_tx_fetch(sampler2DArray util_tx, float2 texel, float layer)
356 {
357  return texelFetch(util_tx, int3(int2(texel) % UTIL_TEX_SIZE, layer), 0);
358 }
359 
360 /* Sample at uv position. Filtered & Wrapping enabled. */
361 float4 utility_tx_sample(sampler2DArray util_tx, float2 uv, float layer)
362 {
363  return textureLod(util_tx, float3(uv, layer), 0.0);
364 }
365 #endif
366 
369 #ifdef __cplusplus
370 
371 using AOVsInfoDataBuf = draw::StorageBuffer<AOVsInfoData>;
372 using CameraDataBuf = draw::UniformBuffer<CameraData>;
373 using FilmDataBuf = draw::UniformBuffer<FilmData>;
374 using SamplingDataBuf = draw::StorageBuffer<SamplingData>;
375 using VelocityGeometryBuf = draw::StorageArrayBuffer<float4, 16, true>;
376 using VelocityIndexBuf = draw::StorageArrayBuffer<VelocityIndex, 16>;
377 using VelocityObjectBuf = draw::StorageArrayBuffer<float4x4, 16>;
378 
379 } // namespace blender::eevee
380 #endif
typedef float(TangentPoint)[2]
#define BLI_STATIC_ASSERT_ALIGN(st, align)
Definition: BLI_assert.h:86
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
_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 type
float float4x4[4][4]
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Texture
#define cosf(x)
Definition: cuda/compat.h:101
#define expf(x)
Definition: cuda/compat.h:106
int len
Definition: draw_manager.c:108
aov_color_img AOVsInfoData
#define AOV_MAX
#define FILM_PRECOMP_SAMPLE_MAX
#define SAMPLING_DIMENSION_COUNT
#define UTIL_TEX_SIZE
Frequency::PASS Frequency::PASS VelocityIndex
smooth(Type::VEC3, "prev") .smooth(Type CameraData
static bool initialized
Definition: gpu_init_exit.c:22
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
ccl_device_inline float3 saturate(float3 a)
Definition: math_float3.h:387
#define ceilf(x)
Definition: metal/compat.h:225
#define sqrtf(x)
Definition: metal/compat.h:243
vec_base< float, 3 > float3
vec_base< float, 4 > float4
vec_base< int32_t, 3 > int3
vec_base< int32_t, 2 > int2
StrongAnonymousAttributeID normal_id
unsigned int uint32_t
Definition: stdint.h:80