Blender  V3.3
gpu_material.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2006 Blender Foundation. All rights reserved. */
3 
10 #include <math.h>
11 #include <string.h>
12 
13 #include "MEM_guardedalloc.h"
14 
15 #include "DNA_material_types.h"
16 #include "DNA_scene_types.h"
17 #include "DNA_world_types.h"
18 
19 #include "BLI_listbase.h"
20 #include "BLI_math.h"
21 #include "BLI_string.h"
22 #include "BLI_utildefines.h"
23 
24 #include "BKE_main.h"
25 #include "BKE_material.h"
26 #include "BKE_node.h"
27 
28 #include "NOD_shader.h"
29 
30 #include "GPU_material.h"
31 #include "GPU_shader.h"
32 #include "GPU_texture.h"
33 #include "GPU_uniform_buffer.h"
34 
35 #include "DRW_engine.h"
36 
37 #include "gpu_codegen.h"
38 #include "gpu_node_graph.h"
39 
40 #include "atomic_ops.h"
41 
42 /* Structs */
43 #define MAX_COLOR_BAND 128
44 
45 typedef struct GPUColorBandBuilder {
46  float pixels[MAX_COLOR_BAND][CM_TABLE + 1][4];
49 
50 struct GPUMaterial {
51  /* Contains GPUShader and source code for deferred compilation.
52  * Can be shared between similar material (i.e: sharing same nodetree topology). */
60  /* Identify shader variations (shadow, probe, world background...).
61  * Should be unique even across render engines. */
63  /* Number of generated function. */
67 
76  /* Low level node graph(s). Also contains resources needed by the material. */
78 
83  GPUUniformBuf *sss_profile; /* UBO containing SSS profile. */
84  GPUTexture *sss_tex_profile; /* Texture containing SSS profile. */
86  float sss_radii[3];
88  bool sss_dirty;
89 
91 
92 #ifndef NDEBUG
93  char name[64];
94 #endif
95 };
96 
97 /* Functions */
98 
100  int size,
101  float *pixels,
102  float *row)
103 {
104  /* In order to put all the color-bands into one 1D array texture,
105  * we need them to be the same size. */
106  BLI_assert(size == CM_TABLE + 1);
108 
109  if (mat->coba_builder == NULL) {
110  mat->coba_builder = MEM_mallocN(sizeof(GPUColorBandBuilder), "GPUColorBandBuilder");
111  mat->coba_builder->current_layer = 0;
112  }
113 
114  int layer = mat->coba_builder->current_layer;
115  *row = (float)layer;
116 
117  if (*row == MAX_COLOR_BAND) {
118  printf("Too many color band in shader! Remove some Curve, Black Body or Color Ramp Node.\n");
119  }
120  else {
121  float *dst = (float *)mat->coba_builder->pixels[layer];
122  memcpy(dst, pixels, sizeof(float) * (CM_TABLE + 1) * 4);
123  mat->coba_builder->current_layer += 1;
124  }
125 
126  return &mat->coba_tex;
127 }
128 
130 {
131  if (mat->coba_builder == NULL) {
132  return;
133  }
134 
135  GPUColorBandBuilder *builder = mat->coba_builder;
136 
138  "mat_ramp", CM_TABLE + 1, builder->current_layer, 1, GPU_RGBA16F, (float *)builder->pixels);
139 
140  MEM_freeN(builder);
141  mat->coba_builder = NULL;
142 }
143 
145 {
146  bool do_free = atomic_sub_and_fetch_uint32(&material->refcount, 1) == 0;
147  if (!do_free) {
148  return;
149  }
150 
151  gpu_node_graph_free(&material->graph);
152 
153  if (material->pass != NULL) {
154  GPU_pass_release(material->pass);
155  }
156  if (material->ubo != NULL) {
158  }
159  if (material->coba_tex != NULL) {
160  GPU_texture_free(material->coba_tex);
161  }
162  if (material->sss_profile != NULL) {
163  GPU_uniformbuf_free(material->sss_profile);
164  }
165  if (material->sss_tex_profile != NULL) {
166  GPU_texture_free(material->sss_tex_profile);
167  }
169 }
170 
171 void GPU_material_free(ListBase *gpumaterial)
172 {
173  LISTBASE_FOREACH (LinkData *, link, gpumaterial) {
174  GPUMaterial *material = link->data;
177  }
178  BLI_freelistN(gpumaterial);
179 }
180 
182 {
183  return material->scene;
184 }
185 
187 {
188  return material->pass;
189 }
190 
192 {
193  return material->pass ? GPU_pass_shader_get(material->pass) : NULL;
194 }
195 
197 {
198  return material->ma;
199 }
200 
202 {
203  return material->ubo;
204 }
205 
207 {
208 #ifndef NDEBUG
209  const char *name = material->name;
210 #else
211  const char *name = "Material";
212 #endif
214 }
215 
217 {
218  return material->graph.attributes;
219 }
220 
222 {
223  return material->graph.textures;
224 }
225 
227 {
228  GPUUniformAttrList *attrs = &material->graph.uniform_attrs;
229  return attrs->count > 0 ? attrs : NULL;
230 }
231 
232 #if 1 /* End of life code. */
233 /* Eevee Subsurface scattering. */
234 /* Based on Separable SSS. by Jorge Jimenez and Diego Gutierrez */
235 
236 # define SSS_SAMPLES 65
237 # define SSS_EXPONENT 2.0f /* Importance sampling exponent */
238 
239 typedef struct GPUSssKernelData {
240  float kernel[SSS_SAMPLES][4];
241  float param[3], max_radius;
243  int samples;
244  int pad[2];
246 
248 
249 static void sss_calculate_offsets(GPUSssKernelData *kd, int count, float exponent)
250 {
251  float step = 2.0f / (float)(count - 1);
252  for (int i = 0; i < count; i++) {
253  float o = ((float)i) * step - 1.0f;
254  float sign = (o < 0.0f) ? -1.0f : 1.0f;
255  float ofs = sign * fabsf(powf(o, exponent));
256  kd->kernel[i][3] = ofs;
257  }
258 }
259 
260 # define BURLEY_TRUNCATE 16.0f
261 # define BURLEY_TRUNCATE_CDF 0.9963790093708328f // cdf(BURLEY_TRUNCATE)
262 static float burley_profile(float r, float d)
263 {
264  float exp_r_3_d = expf(-r / (3.0f * d));
265  float exp_r_d = exp_r_3_d * exp_r_3_d * exp_r_3_d;
266  return (exp_r_d + exp_r_3_d) / (4.0f * d);
267 }
268 
269 static float eval_profile(float r, float param)
270 {
271  r = fabsf(r);
272  return burley_profile(r, param) / BURLEY_TRUNCATE_CDF;
273 }
274 
275 /* Resolution for each sample of the precomputed kernel profile */
276 # define INTEGRAL_RESOLUTION 32
277 static float eval_integral(float x0, float x1, float param)
278 {
279  const float range = x1 - x0;
280  const float step = range / INTEGRAL_RESOLUTION;
281  float integral = 0.0f;
282 
283  for (int i = 0; i < INTEGRAL_RESOLUTION; i++) {
284  float x = x0 + range * ((float)i + 0.5f) / (float)INTEGRAL_RESOLUTION;
285  float y = eval_profile(x, param);
286  integral += y * step;
287  }
288 
289  return integral;
290 }
291 # undef INTEGRAL_RESOLUTION
292 
293 static void compute_sss_kernel(GPUSssKernelData *kd, const float radii[3], int sample_len)
294 {
295  float rad[3];
296  /* Minimum radius */
297  rad[0] = MAX2(radii[0], 1e-15f);
298  rad[1] = MAX2(radii[1], 1e-15f);
299  rad[2] = MAX2(radii[2], 1e-15f);
300 
301  kd->avg_inv_radius = 3.0f / (rad[0] + rad[1] + rad[2]);
302 
303  /* Christensen-Burley fitting */
304  float l[3], d[3];
305 
306  mul_v3_v3fl(l, rad, 0.25f * M_1_PI);
307  const float A = 1.0f;
308  const float s = 1.9f - A + 3.5f * (A - 0.8f) * (A - 0.8f);
309  /* XXX 0.6f Out of nowhere to match cycles! Empirical! Can be tweak better. */
310  mul_v3_v3fl(d, l, 0.6f / s);
311  mul_v3_v3fl(rad, d, BURLEY_TRUNCATE);
312  kd->max_radius = MAX3(rad[0], rad[1], rad[2]);
313 
314  copy_v3_v3(kd->param, d);
315 
316  /* Compute samples locations on the 1d kernel [-1..1] */
317  sss_calculate_offsets(kd, sample_len, SSS_EXPONENT);
318 
319  /* Weights sum for normalization */
320  float sum[3] = {0.0f, 0.0f, 0.0f};
321 
322  /* Compute integral of each sample footprint */
323  for (int i = 0; i < sample_len; i++) {
324  float x0, x1;
325 
326  if (i == 0) {
327  x0 = kd->kernel[0][3] - fabsf(kd->kernel[0][3] - kd->kernel[1][3]) / 2.0f;
328  }
329  else {
330  x0 = (kd->kernel[i - 1][3] + kd->kernel[i][3]) / 2.0f;
331  }
332 
333  if (i == sample_len - 1) {
334  x1 = kd->kernel[sample_len - 1][3] +
335  fabsf(kd->kernel[sample_len - 2][3] - kd->kernel[sample_len - 1][3]) / 2.0f;
336  }
337  else {
338  x1 = (kd->kernel[i][3] + kd->kernel[i + 1][3]) / 2.0f;
339  }
340 
341  x0 *= kd->max_radius;
342  x1 *= kd->max_radius;
343 
344  kd->kernel[i][0] = eval_integral(x0, x1, kd->param[0]);
345  kd->kernel[i][1] = eval_integral(x0, x1, kd->param[1]);
346  kd->kernel[i][2] = eval_integral(x0, x1, kd->param[2]);
347 
348  sum[0] += kd->kernel[i][0];
349  sum[1] += kd->kernel[i][1];
350  sum[2] += kd->kernel[i][2];
351  }
352 
353  for (int i = 0; i < 3; i++) {
354  if (sum[i] > 0.0f) {
355  /* Normalize */
356  for (int j = 0; j < sample_len; j++) {
357  kd->kernel[j][i] /= sum[i];
358  }
359  }
360  else {
361  /* Avoid 0 kernel sum. */
362  kd->kernel[sample_len / 2][i] = 1.0f;
363  }
364  }
365 
366  /* Put center sample at the start of the array (to sample first) */
367  float tmpv[4];
368  copy_v4_v4(tmpv, kd->kernel[sample_len / 2]);
369  for (int i = sample_len / 2; i > 0; i--) {
370  copy_v4_v4(kd->kernel[i], kd->kernel[i - 1]);
371  }
372  copy_v4_v4(kd->kernel[0], tmpv);
373 
374  kd->samples = sample_len;
375 }
376 
377 # define INTEGRAL_RESOLUTION 512
379  int resolution,
380  float **output)
381 {
382  float(*texels)[4];
383  texels = MEM_callocN(sizeof(float[4]) * resolution, "compute_sss_translucence_kernel");
384  *output = (float *)texels;
385 
386  /* Last texel should be black, hence the - 1. */
387  for (int i = 0; i < resolution - 1; i++) {
388  /* Distance from surface. */
389  float d = kd->max_radius * ((float)i + 0.00001f) / ((float)resolution);
390 
391  /* For each distance d we compute the radiance incoming from an hypothetical parallel plane. */
392  /* Compute radius of the footprint on the hypothetical plane. */
393  float r_fp = sqrtf(kd->max_radius * kd->max_radius - d * d);
394  float r_step = r_fp / INTEGRAL_RESOLUTION;
395  float area_accum = 0.0f;
396  for (float r = 0.0f; r < r_fp; r += r_step) {
397  /* Compute distance to the "shading" point through the medium. */
398  /* r_step * 0.5f to put sample between the area borders */
399  float dist = hypotf(r + r_step * 0.5f, d);
400 
401  float profile[3];
402  profile[0] = eval_profile(dist, kd->param[0]);
403  profile[1] = eval_profile(dist, kd->param[1]);
404  profile[2] = eval_profile(dist, kd->param[2]);
405 
406  /* Since the profile and configuration are radially symmetrical we
407  * can just evaluate it once and weight it accordingly */
408  float r_next = r + r_step;
409  float disk_area = (M_PI * r_next * r_next) - (M_PI * r * r);
410 
411  mul_v3_fl(profile, disk_area);
412  add_v3_v3(texels[i], profile);
413  area_accum += disk_area;
414  }
415  /* Normalize over the disk. */
416  mul_v3_fl(texels[i], 1.0f / (area_accum));
417  }
418 
419  /* Normalize */
420  for (int j = resolution - 2; j > 0; j--) {
421  texels[j][0] /= (texels[0][0] > 0.0f) ? texels[0][0] : 1.0f;
422  texels[j][1] /= (texels[0][1] > 0.0f) ? texels[0][1] : 1.0f;
423  texels[j][2] /= (texels[0][2] > 0.0f) ? texels[0][2] : 1.0f;
424  }
425 
426  /* First texel should be white */
427  texels[0][0] = (texels[0][0] > 0.0f) ? 1.0f : 0.0f;
428  texels[0][1] = (texels[0][1] > 0.0f) ? 1.0f : 0.0f;
429  texels[0][2] = (texels[0][2] > 0.0f) ? 1.0f : 0.0f;
430 
431  /* dim the last few texels for smoother transition */
432  mul_v3_fl(texels[resolution - 2], 0.25f);
433  mul_v3_fl(texels[resolution - 3], 0.5f);
434  mul_v3_fl(texels[resolution - 4], 0.75f);
435 }
436 # undef INTEGRAL_RESOLUTION
437 
439 {
440  /* Enable only once. */
441  if (material->sss_enabled) {
442  return false;
443  }
444  copy_v3_v3(material->sss_radii, radii);
445  material->sss_dirty = true;
446  material->sss_enabled = true;
447 
448  /* Update / Create UBO */
449  if (material->sss_profile == NULL) {
450  material->sss_profile = GPU_uniformbuf_create(sizeof(GPUSssKernelData));
451  }
452  return true;
453 }
454 
456  int sample_len,
457  GPUTexture **tex_profile)
458 {
459  if (!material->sss_enabled) {
460  return NULL;
461  }
462 
463  if (material->sss_dirty || (material->sss_samples != sample_len)) {
464  GPUSssKernelData kd;
465 
466  compute_sss_kernel(&kd, material->sss_radii, sample_len);
467 
468  /* Update / Create UBO */
469  GPU_uniformbuf_update(material->sss_profile, &kd);
470 
471  /* Update / Create Tex */
472  float *translucence_profile;
473  compute_sss_translucence_kernel(&kd, 64, &translucence_profile);
474 
475  if (material->sss_tex_profile != NULL) {
476  GPU_texture_free(material->sss_tex_profile);
477  }
478 
479  material->sss_tex_profile = GPU_texture_create_1d(
480  "sss_tex_profile", 64, 1, GPU_RGBA16F, translucence_profile);
481 
482  MEM_freeN(translucence_profile);
483 
484  material->sss_samples = sample_len;
485  material->sss_dirty = false;
486  }
487 
488  if (tex_profile != NULL) {
489  *tex_profile = material->sss_tex_profile;
490  }
491  return material->sss_profile;
492 }
493 
495 {
496  return GPU_uniformbuf_create(sizeof(GPUSssKernelData));
497 }
498 
499 # undef SSS_EXPONENT
500 # undef SSS_SAMPLES
501 #endif
502 
504 {
505  if (!material->graph.outlink_surface) {
506  material->graph.outlink_surface = link;
507  material->has_surface_output = true;
508  }
509 }
510 
512 {
513  if (!material->graph.outlink_volume) {
514  material->graph.outlink_volume = link;
515  material->has_volume_output = true;
516  }
517 }
518 
520 {
521  if (!material->graph.outlink_displacement) {
522  material->graph.outlink_displacement = link;
523  }
524 }
525 
527 {
528  if (!material->graph.outlink_thickness) {
529  material->graph.outlink_thickness = link;
530  }
531 }
532 
534 {
535  GPUNodeGraphOutputLink *aov_link = MEM_callocN(sizeof(GPUNodeGraphOutputLink), __func__);
536  aov_link->outlink = link;
537  aov_link->hash = hash;
538  BLI_addtail(&material->graph.outlink_aovs, aov_link);
539 }
540 
542  eGPUType return_type,
543  GPUNodeLink **link)
544 {
545  /* Force cast to return type. */
546  switch (return_type) {
547  case GPU_FLOAT:
548  GPU_link(material, "set_value", *link, link);
549  break;
550  case GPU_VEC3:
551  GPU_link(material, "set_rgb", *link, link);
552  break;
553  case GPU_VEC4:
554  GPU_link(material, "set_rgba", *link, link);
555  break;
556  default:
557  BLI_assert(0);
558  break;
559  }
560 
561  GPUNodeGraphFunctionLink *func_link = MEM_callocN(sizeof(GPUNodeGraphFunctionLink), __func__);
562  func_link->outlink = *link;
563  SNPRINTF(func_link->name, "ntree_fn%d", material->generated_function_len++);
564  BLI_addtail(&material->graph.material_functions, func_link);
565 
566  return func_link->name;
567 }
568 
570 {
571  return &material->graph;
572 }
573 
575 {
576  return mat->status;
577 }
578 
580 {
581  mat->status = status;
582 }
583 
584 /* Code generation */
585 
587 {
588  return mat->has_surface_output;
589 }
590 
592 {
593  return mat->has_volume_output;
594 }
595 
597 {
598  mat->flag |= flag;
599 }
600 
602 {
603  return (mat->flag & flag) != 0;
604 }
605 
607 {
608  return mat->flag;
609 }
610 
611 /* NOTE: Consumes the flags. */
613 {
614  bool updated = (mat->flag & GPU_MATFLAG_UPDATED) != 0;
615  mat->flag &= ~GPU_MATFLAG_UPDATED;
616  return updated;
617 }
618 
620 {
621  return mat->uuid;
622 }
623 
625  Material *ma,
626  bNodeTree *ntree,
627  ListBase *gpumaterials,
628  const char *name,
629  uint64_t shader_uuid,
630  bool is_volume_shader,
631  bool is_lookdev,
633  void *thunk)
634 {
635  /* Search if this material is not already compiled. */
636  LISTBASE_FOREACH (LinkData *, link, gpumaterials) {
637  GPUMaterial *mat = (GPUMaterial *)link->data;
638  if (mat->uuid == shader_uuid) {
639  return mat;
640  }
641  }
642 
643  GPUMaterial *mat = MEM_callocN(sizeof(GPUMaterial), "GPUMaterial");
644  mat->ma = ma;
645  mat->scene = scene;
646  mat->uuid = shader_uuid;
647  mat->flag = GPU_MATFLAG_UPDATED;
648  mat->status = GPU_MAT_CREATED;
649  mat->is_volume_shader = is_volume_shader;
651  BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "GPUNodeGraph.used_libraries");
652  mat->refcount = 1;
653 #ifndef NDEBUG
654  STRNCPY(mat->name, name);
655 #else
656  UNUSED_VARS(name);
657 #endif
658  if (is_lookdev) {
660  }
661 
662  /* Localize tree to create links for reroute and mute. */
663  bNodeTree *localtree = ntreeLocalize(ntree);
664  ntreeGPUMaterialNodes(localtree, mat);
665 
667 
668  {
669  /* Create source code and search pass cache for an already compiled version. */
670  mat->pass = GPU_generate_pass(mat, &mat->graph, callback, thunk);
671 
672  if (mat->pass == NULL) {
673  /* We had a cache hit and the shader has already failed to compile. */
674  mat->status = GPU_MAT_FAILED;
675  gpu_node_graph_free(&mat->graph);
676  }
677  else {
679  if (sh != NULL) {
680  /* We had a cache hit and the shader is already compiled. */
681  mat->status = GPU_MAT_SUCCESS;
683  }
684  }
685  }
686 
687  /* Only free after GPU_pass_shader_get where GPUUniformBuf read data from the local tree. */
688  ntreeFreeLocalTree(localtree);
689  BLI_assert(!localtree->id.py_instance); /* Or call #BKE_libblock_free_data_py. */
690  MEM_freeN(localtree);
691 
692  /* Note that even if building the shader fails in some way, we still keep
693  * it to avoid trying to compile again and again, and simply do not use
694  * the actual shader on drawing. */
695  LinkData *link = MEM_callocN(sizeof(LinkData), "GPUMaterialLink");
696  link->data = mat;
697  BLI_addtail(gpumaterials, link);
698 
699  return mat;
700 }
701 
703 {
705 }
706 
708 {
710 }
711 
713 {
714  bool success;
715 
717  BLI_assert(mat->pass);
718 
719  /* NOTE: The shader may have already been compiled here since we are
720  * sharing GPUShader across GPUMaterials. In this case it's a no-op. */
721 #ifndef NDEBUG
722  success = GPU_pass_compile(mat->pass, mat->name);
723 #else
724  success = GPU_pass_compile(mat->pass, __func__);
725 #endif
726 
727  mat->flag |= GPU_MATFLAG_UPDATED;
728 
729  if (success) {
731  if (sh != NULL) {
732  mat->status = GPU_MAT_SUCCESS;
734  }
735  else {
736  mat->status = GPU_MAT_FAILED;
737  }
738  }
739  else {
740  mat->status = GPU_MAT_FAILED;
741  GPU_pass_release(mat->pass);
742  mat->pass = NULL;
743  gpu_node_graph_free(&mat->graph);
744  }
745 }
746 
748 {
749  LISTBASE_FOREACH (Material *, ma, &bmain->materials) {
750  GPU_material_free(&ma->gpumaterial);
751  }
752 
753  LISTBASE_FOREACH (World *, wo, &bmain->worlds) {
754  GPU_material_free(&wo->gpumaterial);
755  }
756 
757  // BKE_world_defaults_free_gpu();
759 }
typedef float(TangentPoint)[2]
General operations, lookup, etc. for materials.
void BKE_material_defaults_free_gpu(void)
Definition: material.c:2066
#define BLI_assert(a)
Definition: BLI_assert.h:46
#define BLI_STATIC_ASSERT_ALIGN(st, align)
Definition: BLI_assert.h:86
unsigned int BLI_ghashutil_ptrhash(const void *key)
GSet * BLI_gset_new(GSetHashFP hashfp, GSetCmpFP cmpfp, const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition: BLI_ghash.c:947
bool BLI_ghashutil_ptrcmp(const void *a, const void *b)
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:336
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
Definition: listbase.c:466
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:80
#define M_1_PI
Definition: BLI_math_base.h:41
#define M_PI
Definition: BLI_math_base.h:20
MINLINE void copy_v4_v4(float r[4], const float a[4])
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
MINLINE void add_v3_v3(float r[3], const float a[3])
#define STRNCPY(dst, src)
Definition: BLI_string.h:483
#define SNPRINTF(dst, format,...)
Definition: BLI_string.h:485
#define MAX3(a, b, c)
#define UNUSED_VARS(...)
#define UNUSED_VARS_NDEBUG(...)
#define MAX2(a, b)
#define ELEM(...)
#define CM_TABLE
_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 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 y
void(* GPUCodegenCallbackFn)(void *thunk, GPUMaterial *mat, GPUCodegenOutput *codegen)
Definition: GPU_material.h:137
eGPUMaterialFlag
Definition: GPU_material.h:70
@ GPU_MATFLAG_UPDATED
Definition: GPU_material.h:95
@ GPU_MATFLAG_LOOKDEV_HACK
Definition: GPU_material.h:98
eGPUMaterialStatus
Definition: GPU_material.h:113
@ GPU_MAT_QUEUED
Definition: GPU_material.h:116
@ GPU_MAT_FAILED
Definition: GPU_material.h:114
@ GPU_MAT_SUCCESS
Definition: GPU_material.h:117
@ GPU_MAT_CREATED
Definition: GPU_material.h:115
eGPUType
Definition: GPU_material.h:45
@ GPU_VEC4
Definition: GPU_material.h:52
@ GPU_VEC3
Definition: GPU_material.h:51
@ GPU_FLOAT
Definition: GPU_material.h:49
bool GPU_link(GPUMaterial *mat, const char *name,...)
struct GPUShader GPUShader
Definition: GPU_shader.h:20
GPUTexture * GPU_texture_create_1d_array(const char *name, int w, int h, int mip_len, eGPUTextureFormat format, const float *data)
Definition: gpu_texture.cc:284
GPUTexture * GPU_texture_create_1d(const char *name, int w, int mip_len, eGPUTextureFormat format, const float *data)
Definition: gpu_texture.cc:278
struct GPUTexture GPUTexture
Definition: GPU_texture.h:17
void GPU_texture_free(GPUTexture *tex)
Definition: gpu_texture.cc:564
struct GPUUniformBuf GPUUniformBuf
#define GPU_uniformbuf_create(size)
GPUUniformBuf * GPU_uniformbuf_create_from_list(struct ListBase *inputs, const char *name)
void GPU_uniformbuf_update(GPUUniformBuf *ubo, const void *data)
void GPU_uniformbuf_free(GPUUniformBuf *ubo)
Read Guarded memory(de)allocation.
Provides wrapper around system-specific atomic primitives, and some extensions (faked-atomic operatio...
ATOMIC_INLINE uint32_t atomic_add_and_fetch_uint32(uint32_t *p, uint32_t x)
ATOMIC_INLINE uint32_t atomic_sub_and_fetch_uint32(uint32_t *p, uint32_t x)
ATTR_WARN_UNUSED_RESULT const BMLoop * l
#define A
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
static T sum(const btAlignedObjectArray< T > &items)
#define expf(x)
Definition: cuda/compat.h:106
#define powf(x, y)
Definition: cuda/compat.h:103
Scene scene
Material material
DEGForeachIDComponentCallback callback
depth_tx normal_tx diffuse_light_tx specular_light_tx volume_light_tx environment_tx ambient_occlusion_tx aov_value_tx in_weight_img GPU_RGBA16F
bNodeTree * ntree
GPUPass * GPU_generate_pass(GPUMaterial *material, GPUNodeGraph *graph, GPUCodegenCallbackFn finalize_source_cb, void *thunk)
Definition: gpu_codegen.cc:585
void GPU_pass_release(GPUPass *pass)
Definition: gpu_codegen.cc:738
bool GPU_pass_compile(GPUPass *pass, const char *shname)
Definition: gpu_codegen.cc:706
GPUShader * GPU_pass_shader_get(GPUPass *pass)
Definition: gpu_codegen.cc:733
#define SSS_EXPONENT
Definition: gpu_material.c:237
uint64_t GPU_material_uuid_get(GPUMaterial *mat)
Definition: gpu_material.c:619
static void gpu_material_ramp_texture_build(GPUMaterial *mat)
Definition: gpu_material.c:129
static void gpu_material_free_single(GPUMaterial *material)
Definition: gpu_material.c:144
void GPU_material_acquire(GPUMaterial *mat)
Definition: gpu_material.c:702
GPUNodeGraph * gpu_material_node_graph(GPUMaterial *material)
Definition: gpu_material.c:569
GPUUniformAttrList * GPU_material_uniform_attributes(GPUMaterial *material)
Definition: gpu_material.c:226
void GPU_material_compile(GPUMaterial *mat)
Definition: gpu_material.c:712
void GPU_material_output_surface(GPUMaterial *material, GPUNodeLink *link)
Definition: gpu_material.c:503
bool GPU_material_has_surface_output(GPUMaterial *mat)
Definition: gpu_material.c:586
void GPU_material_status_set(GPUMaterial *mat, eGPUMaterialStatus status)
Definition: gpu_material.c:579
void GPU_materials_free(Main *bmain)
Definition: gpu_material.c:747
void GPU_material_free(ListBase *gpumaterial)
Definition: gpu_material.c:171
static float burley_profile(float r, float d)
Definition: gpu_material.c:262
void GPU_material_output_displacement(GPUMaterial *material, GPUNodeLink *link)
Definition: gpu_material.c:519
struct GPUColorBandBuilder GPUColorBandBuilder
void GPU_material_output_thickness(GPUMaterial *material, GPUNodeLink *link)
Definition: gpu_material.c:526
void GPU_material_add_output_link_aov(GPUMaterial *material, GPUNodeLink *link, int hash)
Definition: gpu_material.c:533
bool GPU_material_flag_get(const GPUMaterial *mat, eGPUMaterialFlag flag)
Definition: gpu_material.c:601
GPUShader * GPU_material_get_shader(GPUMaterial *material)
Definition: gpu_material.c:191
bool GPU_material_recalc_flag_get(GPUMaterial *mat)
Definition: gpu_material.c:612
#define BURLEY_TRUNCATE
Definition: gpu_material.c:260
ListBase GPU_material_textures(GPUMaterial *material)
Definition: gpu_material.c:221
char * GPU_material_split_sub_function(GPUMaterial *material, eGPUType return_type, GPUNodeLink **link)
Definition: gpu_material.c:541
GPUUniformBuf * GPU_material_uniform_buffer_get(GPUMaterial *material)
Definition: gpu_material.c:201
struct GPUUniformBuf * GPU_material_sss_profile_get(GPUMaterial *material, int sample_len, GPUTexture **tex_profile)
Definition: gpu_material.c:455
GPUTexture ** gpu_material_ramp_texture_row_set(GPUMaterial *mat, int size, float *pixels, float *row)
Definition: gpu_material.c:99
GPUPass * GPU_material_get_pass(GPUMaterial *material)
Definition: gpu_material.c:186
bool GPU_material_sss_profile_create(GPUMaterial *material, float radii[3])
Definition: gpu_material.c:438
#define BURLEY_TRUNCATE_CDF
Definition: gpu_material.c:261
void GPU_material_release(GPUMaterial *mat)
Definition: gpu_material.c:707
Scene * GPU_material_scene(GPUMaterial *material)
Definition: gpu_material.c:181
eGPUMaterialStatus GPU_material_status(GPUMaterial *mat)
Definition: gpu_material.c:574
static float eval_integral(float x0, float x1, float param)
Definition: gpu_material.c:277
void GPU_material_flag_set(GPUMaterial *mat, eGPUMaterialFlag flag)
Definition: gpu_material.c:596
struct GPUUniformBuf * GPU_material_create_sss_profile_ubo(void)
Definition: gpu_material.c:494
Material * GPU_material_get_material(GPUMaterial *material)
Definition: gpu_material.c:196
struct GPUSssKernelData GPUSssKernelData
#define SSS_SAMPLES
Definition: gpu_material.c:236
static void compute_sss_kernel(GPUSssKernelData *kd, const float radii[3], int sample_len)
Definition: gpu_material.c:293
void GPU_material_output_volume(GPUMaterial *material, GPUNodeLink *link)
Definition: gpu_material.c:511
eGPUMaterialFlag GPU_material_flag(const GPUMaterial *mat)
Definition: gpu_material.c:606
ListBase GPU_material_attributes(GPUMaterial *material)
Definition: gpu_material.c:216
static float eval_profile(float r, float param)
Definition: gpu_material.c:269
static void sss_calculate_offsets(GPUSssKernelData *kd, int count, float exponent)
Definition: gpu_material.c:249
static void compute_sss_translucence_kernel(const GPUSssKernelData *kd, int resolution, float **output)
Definition: gpu_material.c:378
GPUMaterial * GPU_material_from_nodetree(Scene *scene, Material *ma, bNodeTree *ntree, ListBase *gpumaterials, const char *name, uint64_t shader_uuid, bool is_volume_shader, bool is_lookdev, GPUCodegenCallbackFn callback, void *thunk)
Definition: gpu_material.c:624
#define INTEGRAL_RESOLUTION
Definition: gpu_material.c:377
void GPU_material_uniform_buffer_create(GPUMaterial *material, ListBase *inputs)
Definition: gpu_material.c:206
#define MAX_COLOR_BAND
Definition: gpu_material.c:43
bool GPU_material_has_volume_output(GPUMaterial *mat)
Definition: gpu_material.c:591
void gpu_node_graph_free(GPUNodeGraph *graph)
void gpu_node_graph_free_nodes(GPUNodeGraph *graph)
int count
void * DRW_deferred_shader_remove
void * ntreeGPUMaterialNodes
ccl_global KernelShaderEvalInput ccl_global float * output
ccl_gpu_kernel_postfix ccl_global float int int int int sh
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:31
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:33
#define hypotf(x, y)
Definition: metal/compat.h:226
#define fabsf(x)
Definition: metal/compat.h:219
#define sqrtf(x)
Definition: metal/compat.h:243
double sign(double arg)
Definition: utility.h:250
MutableSpan< float > radii
static bNodeSocketTemplate inputs[]
#define hash
Definition: noise.c:153
unsigned int uint32_t
Definition: stdint.h:80
unsigned __int64 uint64_t
Definition: stdint.h:90
float pixels[MAX_COLOR_BAND][CM_TABLE+1][4]
Definition: gpu_material.c:46
GPUUniformBuf * ubo
Definition: gpu_material.c:55
int generated_function_len
Definition: gpu_material.c:64
GPUColorBandBuilder * coba_builder
Definition: gpu_material.c:75
Scene * scene
Definition: gpu_material.c:69
float sss_radii[3]
Definition: gpu_material.c:86
GPUTexture * sss_tex_profile
Definition: gpu_material.c:84
eGPUMaterialFlag flag
Definition: gpu_material.c:59
uint32_t refcount
Definition: gpu_material.c:90
GPUUniformBuf * sss_profile
Definition: gpu_material.c:83
bool has_volume_output
Definition: gpu_material.c:81
bool has_surface_output
Definition: gpu_material.c:80
bool sss_dirty
Definition: gpu_material.c:88
GPUTexture * coba_tex
Definition: gpu_material.c:73
Material * ma
Definition: gpu_material.c:71
uint64_t uuid
Definition: gpu_material.c:62
char name[64]
Definition: gpu_material.c:93
bool sss_enabled
Definition: gpu_material.c:85
GPUPass * pass
Definition: gpu_material.c:53
GPUNodeGraph graph
Definition: gpu_material.c:77
bool is_volume_shader
Definition: gpu_material.c:66
eGPUMaterialStatus status
Definition: gpu_material.c:57
GSet * used_libraries
float kernel[SSS_SAMPLES][4]
Definition: gpu_material.c:240
unsigned int count
Definition: GPU_material.h:321
void * py_instance
Definition: DNA_ID.h:435
void * data
Definition: DNA_listBase.h:26
Definition: BKE_main.h:121
ListBase materials
Definition: BKE_main.h:174
ListBase worlds
Definition: BKE_main.h:182