43 #define MAX_COLOR_BAND 128
118 printf(
"Too many color band in shader! Remove some Curve, Black Body or Color Ramp Node.\n");
122 memcpy(dst, pixels,
sizeof(
float) * (
CM_TABLE + 1) * 4);
211 const char *name =
"Material";
236 # define SSS_SAMPLES 65
237 # define SSS_EXPONENT 2.0f
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;
256 kd->kernel[i][3] = ofs;
260 # define BURLEY_TRUNCATE 16.0f
261 # define BURLEY_TRUNCATE_CDF 0.9963790093708328f
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);
276 # define INTEGRAL_RESOLUTION 32
279 const float range = x1 - x0;
281 float integral = 0.0f;
286 integral +=
y * step;
291 # undef INTEGRAL_RESOLUTION
307 const float A = 1.0f;
308 const float s = 1.9f -
A + 3.5f * (
A - 0.8f) * (
A - 0.8f);
320 float sum[3] = {0.0f, 0.0f, 0.0f};
323 for (
int i = 0; i < sample_len; i++) {
333 if (i == sample_len - 1) {
334 x1 = kd->
kernel[sample_len - 1][3] +
353 for (
int i = 0; i < 3; i++) {
356 for (
int j = 0; j < sample_len; j++) {
362 kd->
kernel[sample_len / 2][i] = 1.0f;
369 for (
int i = sample_len / 2; i > 0; i--) {
377 # define INTEGRAL_RESOLUTION 512
383 texels =
MEM_callocN(
sizeof(
float[4]) * resolution,
"compute_sss_translucence_kernel");
384 *
output = (
float *)texels;
387 for (
int i = 0; i < resolution - 1; i++) {
395 float area_accum = 0.0f;
396 for (
float r = 0.0f;
r < r_fp;
r += r_step) {
399 float dist =
hypotf(
r + r_step * 0.5f, d);
408 float r_next =
r + r_step;
409 float disk_area = (
M_PI * r_next * r_next) - (
M_PI *
r *
r);
413 area_accum += disk_area;
416 mul_v3_fl(texels[i], 1.0f / (area_accum));
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;
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;
432 mul_v3_fl(texels[resolution - 2], 0.25f);
434 mul_v3_fl(texels[resolution - 4], 0.75f);
436 # undef INTEGRAL_RESOLUTION
472 float *translucence_profile;
480 "sss_tex_profile", 64, 1,
GPU_RGBA16F, translucence_profile);
488 if (tex_profile !=
NULL) {
489 *tex_profile =
material->sss_tex_profile;
505 if (!
material->graph.outlink_surface) {
506 material->graph.outlink_surface = link;
507 material->has_surface_output =
true;
513 if (!
material->graph.outlink_volume) {
514 material->graph.outlink_volume = link;
521 if (!
material->graph.outlink_displacement) {
522 material->graph.outlink_displacement = link;
528 if (!
material->graph.outlink_thickness) {
529 material->graph.outlink_thickness = link;
546 switch (return_type) {
566 return func_link->
name;
603 return (mat->
flag & flag) != 0;
630 bool is_volume_shader,
638 if (mat->
uuid == shader_uuid) {
646 mat->
uuid = shader_uuid;
typedef float(TangentPoint)[2]
General operations, lookup, etc. for materials.
void BKE_material_defaults_free_gpu(void)
#define BLI_STATIC_ASSERT_ALIGN(st, align)
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
bool BLI_ghashutil_ptrcmp(const void *a, const void *b)
#define LISTBASE_FOREACH(type, var, list)
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
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)
#define SNPRINTF(dst, format,...)
#define UNUSED_VARS_NDEBUG(...)
_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)
@ GPU_MATFLAG_LOOKDEV_HACK
bool GPU_link(GPUMaterial *mat, const char *name,...)
struct GPUShader GPUShader
GPUTexture * GPU_texture_create_1d_array(const char *name, int w, int h, int mip_len, eGPUTextureFormat format, const float *data)
GPUTexture * GPU_texture_create_1d(const char *name, int w, int mip_len, eGPUTextureFormat format, const float *data)
struct GPUTexture GPUTexture
void GPU_texture_free(GPUTexture *tex)
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
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
static T sum(const btAlignedObjectArray< T > &items)
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
GPUPass * GPU_generate_pass(GPUMaterial *material, GPUNodeGraph *graph, GPUCodegenCallbackFn finalize_source_cb, void *thunk)
void GPU_pass_release(GPUPass *pass)
bool GPU_pass_compile(GPUPass *pass, const char *shname)
GPUShader * GPU_pass_shader_get(GPUPass *pass)
uint64_t GPU_material_uuid_get(GPUMaterial *mat)
static void gpu_material_ramp_texture_build(GPUMaterial *mat)
static void gpu_material_free_single(GPUMaterial *material)
void GPU_material_acquire(GPUMaterial *mat)
GPUNodeGraph * gpu_material_node_graph(GPUMaterial *material)
GPUUniformAttrList * GPU_material_uniform_attributes(GPUMaterial *material)
void GPU_material_compile(GPUMaterial *mat)
void GPU_material_output_surface(GPUMaterial *material, GPUNodeLink *link)
bool GPU_material_has_surface_output(GPUMaterial *mat)
void GPU_material_status_set(GPUMaterial *mat, eGPUMaterialStatus status)
void GPU_materials_free(Main *bmain)
void GPU_material_free(ListBase *gpumaterial)
static float burley_profile(float r, float d)
void GPU_material_output_displacement(GPUMaterial *material, GPUNodeLink *link)
struct GPUColorBandBuilder GPUColorBandBuilder
void GPU_material_output_thickness(GPUMaterial *material, GPUNodeLink *link)
void GPU_material_add_output_link_aov(GPUMaterial *material, GPUNodeLink *link, int hash)
bool GPU_material_flag_get(const GPUMaterial *mat, eGPUMaterialFlag flag)
GPUShader * GPU_material_get_shader(GPUMaterial *material)
bool GPU_material_recalc_flag_get(GPUMaterial *mat)
ListBase GPU_material_textures(GPUMaterial *material)
char * GPU_material_split_sub_function(GPUMaterial *material, eGPUType return_type, GPUNodeLink **link)
GPUUniformBuf * GPU_material_uniform_buffer_get(GPUMaterial *material)
struct GPUUniformBuf * GPU_material_sss_profile_get(GPUMaterial *material, int sample_len, GPUTexture **tex_profile)
GPUTexture ** gpu_material_ramp_texture_row_set(GPUMaterial *mat, int size, float *pixels, float *row)
GPUPass * GPU_material_get_pass(GPUMaterial *material)
bool GPU_material_sss_profile_create(GPUMaterial *material, float radii[3])
#define BURLEY_TRUNCATE_CDF
void GPU_material_release(GPUMaterial *mat)
Scene * GPU_material_scene(GPUMaterial *material)
eGPUMaterialStatus GPU_material_status(GPUMaterial *mat)
static float eval_integral(float x0, float x1, float param)
void GPU_material_flag_set(GPUMaterial *mat, eGPUMaterialFlag flag)
struct GPUUniformBuf * GPU_material_create_sss_profile_ubo(void)
Material * GPU_material_get_material(GPUMaterial *material)
struct GPUSssKernelData GPUSssKernelData
static void compute_sss_kernel(GPUSssKernelData *kd, const float radii[3], int sample_len)
void GPU_material_output_volume(GPUMaterial *material, GPUNodeLink *link)
eGPUMaterialFlag GPU_material_flag(const GPUMaterial *mat)
ListBase GPU_material_attributes(GPUMaterial *material)
static float eval_profile(float r, float param)
static void sss_calculate_offsets(GPUSssKernelData *kd, int count, float exponent)
static void compute_sss_translucence_kernel(const GPUSssKernelData *kd, int resolution, float **output)
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)
#define INTEGRAL_RESOLUTION
void GPU_material_uniform_buffer_create(GPUMaterial *material, ListBase *inputs)
bool GPU_material_has_volume_output(GPUMaterial *mat)
void gpu_node_graph_free(GPUNodeGraph *graph)
void gpu_node_graph_free_nodes(GPUNodeGraph *graph)
void * ntreeFreeLocalTree
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)
void *(* MEM_callocN)(size_t len, const char *str)
void *(* MEM_mallocN)(size_t len, const char *str)
MutableSpan< float > radii
static bNodeSocketTemplate inputs[]
unsigned __int64 uint64_t
float pixels[MAX_COLOR_BAND][CM_TABLE+1][4]
int generated_function_len
GPUColorBandBuilder * coba_builder
GPUTexture * sss_tex_profile
GPUUniformBuf * sss_profile
eGPUMaterialStatus status
float kernel[SSS_SAMPLES][4]