Blender  V3.3
Classes | Macros | Typedefs | Functions
gpu_material.c File Reference
#include <math.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "DNA_material_types.h"
#include "DNA_scene_types.h"
#include "DNA_world_types.h"
#include "BLI_listbase.h"
#include "BLI_math.h"
#include "BLI_string.h"
#include "BLI_utildefines.h"
#include "BKE_main.h"
#include "BKE_material.h"
#include "BKE_node.h"
#include "NOD_shader.h"
#include "GPU_material.h"
#include "GPU_shader.h"
#include "GPU_texture.h"
#include "GPU_uniform_buffer.h"
#include "DRW_engine.h"
#include "gpu_codegen.h"
#include "gpu_node_graph.h"
#include "atomic_ops.h"

Go to the source code of this file.

Classes

struct  GPUColorBandBuilder
 
struct  GPUMaterial
 
struct  GPUSssKernelData
 

Macros

#define MAX_COLOR_BAND   128
 
#define SSS_SAMPLES   65
 
#define SSS_EXPONENT   2.0f /* Importance sampling exponent */
 
#define BURLEY_TRUNCATE   16.0f
 
#define BURLEY_TRUNCATE_CDF   0.9963790093708328f
 
#define INTEGRAL_RESOLUTION   32
 
#define INTEGRAL_RESOLUTION   512
 

Typedefs

typedef struct GPUColorBandBuilder GPUColorBandBuilder
 
typedef struct GPUSssKernelData GPUSssKernelData
 

Functions

GPUTexture ** gpu_material_ramp_texture_row_set (GPUMaterial *mat, int size, float *pixels, float *row)
 
static void gpu_material_ramp_texture_build (GPUMaterial *mat)
 
static void gpu_material_free_single (GPUMaterial *material)
 
void GPU_material_free (ListBase *gpumaterial)
 
Scene * GPU_material_scene (GPUMaterial *material)
 
GPUPass * GPU_material_get_pass (GPUMaterial *material)
 
GPUShader * GPU_material_get_shader (GPUMaterial *material)
 
Material * GPU_material_get_material (GPUMaterial *material)
 
GPUUniformBuf * GPU_material_uniform_buffer_get (GPUMaterial *material)
 
void GPU_material_uniform_buffer_create (GPUMaterial *material, ListBase *inputs)
 
ListBase GPU_material_attributes (GPUMaterial *material)
 
ListBase GPU_material_textures (GPUMaterial *material)
 
GPUUniformAttrList * GPU_material_uniform_attributes (GPUMaterial *material)
 
static void sss_calculate_offsets (GPUSssKernelData *kd, int count, float exponent)
 
static float burley_profile (float r, float d)
 
static float eval_profile (float r, float param)
 
static float eval_integral (float x0, float x1, float param)
 
static void compute_sss_kernel (GPUSssKernelData *kd, const float radii[3], int sample_len)
 
static void compute_sss_translucence_kernel (const GPUSssKernelData *kd, int resolution, float **output)
 
bool GPU_material_sss_profile_create (GPUMaterial *material, float radii[3])
 
struct GPUUniformBuf * GPU_material_sss_profile_get (GPUMaterial *material, int sample_len, GPUTexture **tex_profile)
 
struct GPUUniformBuf * GPU_material_create_sss_profile_ubo (void)
 
void GPU_material_output_surface (GPUMaterial *material, GPUNodeLink *link)
 
void GPU_material_output_volume (GPUMaterial *material, GPUNodeLink *link)
 
void GPU_material_output_displacement (GPUMaterial *material, GPUNodeLink *link)
 
void GPU_material_output_thickness (GPUMaterial *material, GPUNodeLink *link)
 
void GPU_material_add_output_link_aov (GPUMaterial *material, GPUNodeLink *link, int hash)
 
char * GPU_material_split_sub_function (GPUMaterial *material, eGPUType return_type, GPUNodeLink **link)
 
GPUNodeGraph * gpu_material_node_graph (GPUMaterial *material)
 
eGPUMaterialStatus GPU_material_status (GPUMaterial *mat)
 
void GPU_material_status_set (GPUMaterial *mat, eGPUMaterialStatus status)
 
bool GPU_material_has_surface_output (GPUMaterial *mat)
 
bool GPU_material_has_volume_output (GPUMaterial *mat)
 
void GPU_material_flag_set (GPUMaterial *mat, eGPUMaterialFlag flag)
 
bool GPU_material_flag_get (const GPUMaterial *mat, eGPUMaterialFlag flag)
 
eGPUMaterialFlag GPU_material_flag (const GPUMaterial *mat)
 
bool GPU_material_recalc_flag_get (GPUMaterial *mat)
 
uint64_t GPU_material_uuid_get (GPUMaterial *mat)
 
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)
 
void GPU_material_acquire (GPUMaterial *mat)
 
void GPU_material_release (GPUMaterial *mat)
 
void GPU_material_compile (GPUMaterial *mat)
 
void GPU_materials_free (Main *bmain)
 

Detailed Description

Manages materials, lights and textures.

Definition in file gpu_material.c.

Macro Definition Documentation

◆ BURLEY_TRUNCATE

#define BURLEY_TRUNCATE   16.0f

Definition at line 260 of file gpu_material.c.

◆ BURLEY_TRUNCATE_CDF

#define BURLEY_TRUNCATE_CDF   0.9963790093708328f

Definition at line 261 of file gpu_material.c.

◆ INTEGRAL_RESOLUTION [1/2]

#define INTEGRAL_RESOLUTION   32

Definition at line 377 of file gpu_material.c.

◆ INTEGRAL_RESOLUTION [2/2]

#define INTEGRAL_RESOLUTION   512

Definition at line 377 of file gpu_material.c.

◆ MAX_COLOR_BAND

#define MAX_COLOR_BAND   128

Definition at line 43 of file gpu_material.c.

◆ SSS_EXPONENT

#define SSS_EXPONENT   2.0f /* Importance sampling exponent */

Definition at line 237 of file gpu_material.c.

◆ SSS_SAMPLES

#define SSS_SAMPLES   65

Definition at line 236 of file gpu_material.c.

Typedef Documentation

◆ GPUColorBandBuilder

◆ GPUSssKernelData

Function Documentation

◆ burley_profile()

static float burley_profile ( float  r,
float  d 
)
static

Definition at line 262 of file gpu_material.c.

References expf, and r.

Referenced by eval_profile().

◆ compute_sss_kernel()

static void compute_sss_kernel ( GPUSssKernelData *  kd,
const float  radii[3],
int  sample_len 
)
static

◆ compute_sss_translucence_kernel()

static void compute_sss_translucence_kernel ( const GPUSssKernelData *  kd,
int  resolution,
float **  output 
)
static

◆ eval_integral()

static float eval_integral ( float  x0,
float  x1,
float  param 
)
static

Definition at line 277 of file gpu_material.c.

References eval_profile(), float(), INTEGRAL_RESOLUTION, x, and y.

Referenced by compute_sss_kernel().

◆ eval_profile()

static float eval_profile ( float  r,
float  param 
)
static

Definition at line 269 of file gpu_material.c.

References burley_profile(), BURLEY_TRUNCATE_CDF, fabsf, and r.

Referenced by compute_sss_translucence_kernel(), and eval_integral().

◆ GPU_material_acquire()

void GPU_material_acquire ( GPUMaterial *  mat)

◆ GPU_material_add_output_link_aov()

void GPU_material_add_output_link_aov ( GPUMaterial *  material,
GPUNodeLink *  link,
int  hash 
)

◆ GPU_material_attributes()

ListBase GPU_material_attributes ( GPUMaterial *  material)

◆ GPU_material_compile()

void GPU_material_compile ( GPUMaterial *  mat)

◆ GPU_material_create_sss_profile_ubo()

struct GPUUniformBuf* GPU_material_create_sss_profile_ubo ( void  )

Definition at line 494 of file gpu_material.c.

References GPU_uniformbuf_create.

◆ GPU_material_flag()

eGPUMaterialFlag GPU_material_flag ( const GPUMaterial *  mat)

Definition at line 606 of file gpu_material.c.

References GPUMaterial::flag.

Referenced by GPUCodegen::GPUCodegen().

◆ GPU_material_flag_get()

bool GPU_material_flag_get ( const GPUMaterial *  mat,
eGPUMaterialFlag  flag 
)

◆ GPU_material_flag_set()

void GPU_material_flag_set ( GPUMaterial *  mat,
eGPUMaterialFlag  flag 
)

Definition at line 596 of file gpu_material.c.

References GPUMaterial::flag.

Referenced by GPU_attribute(), blender::nodes::node_shader_normal_map_cc::gpu_shader_normal_map(), blender::nodes::node_shader_particle_info_cc::gpu_shader_particle_info(), blender::nodes::node_shader_ambient_occlusion_cc::node_shader_gpu_ambient_occlusion(), blender::nodes::node_shader_bsdf_anisotropic_cc::node_shader_gpu_bsdf_anisotropic(), blender::nodes::node_shader_bsdf_diffuse_cc::node_shader_gpu_bsdf_diffuse(), blender::nodes::node_shader_bsdf_glass_cc::node_shader_gpu_bsdf_glass(), blender::nodes::node_shader_bsdf_glossy_cc::node_shader_gpu_bsdf_glossy(), blender::nodes::node_shader_bsdf_principled_cc::node_shader_gpu_bsdf_principled(), blender::nodes::node_shader_bsdf_refraction_cc::node_shader_gpu_bsdf_refraction(), blender::nodes::node_shader_bsdf_toon_cc::node_shader_gpu_bsdf_toon(), blender::nodes::node_shader_bsdf_translucent_cc::node_shader_gpu_bsdf_translucent(), blender::nodes::node_shader_bsdf_transparent_cc::node_shader_gpu_bsdf_transparent(), blender::nodes::node_shader_bsdf_velvet_cc::node_shader_gpu_bsdf_velvet(), blender::nodes::node_shader_eevee_specular_cc::node_shader_gpu_eevee_specular(), blender::nodes::node_shader_emission_cc::node_shader_gpu_emission(), blender::nodes::node_shader_geometry_cc::node_shader_gpu_geometry(), blender::nodes::node_shader_object_info_cc::node_shader_gpu_object_info(), blender::nodes::node_shader_output_aov_cc::node_shader_gpu_output_aov(), blender::nodes::node_shader_shader_to_rgb_cc::node_shader_gpu_shadertorgb(), blender::nodes::node_shader_subsurface_scattering_cc::node_shader_gpu_subsurface_scattering(), and blender::nodes::node_shader_wireframe_cc::node_shader_gpu_wireframe().

◆ GPU_material_free()

void GPU_material_free ( ListBase *  gpumaterial)

◆ gpu_material_free_single()

static void gpu_material_free_single ( GPUMaterial *  material)
static

◆ GPU_material_from_nodetree()

GPUMaterial* GPU_material_from_nodetree ( struct Scene *  scene,
struct Material *  ma,
struct bNodeTree *  ntree,
struct ListBase *  gpumaterials,
const char *  name,
uint64_t  shader_uuid,
bool  is_volume_shader,
bool  is_lookdev,
GPUCodegenCallbackFn  callback,
void *  thunk 
)

◆ GPU_material_get_material()

Material* GPU_material_get_material ( GPUMaterial *  material)

Return can be NULL if it's a world material.

Definition at line 196 of file gpu_material.c.

References material.

Referenced by blender::nodes::node_shader_object_info_cc::node_shader_gpu_object_info().

◆ GPU_material_get_pass()

GPUPass* GPU_material_get_pass ( GPUMaterial *  material)

Definition at line 186 of file gpu_material.c.

References material.

Referenced by DRW_shgroup_material_create().

◆ GPU_material_get_shader()

GPUShader* GPU_material_get_shader ( GPUMaterial *  material)

◆ GPU_material_has_surface_output()

bool GPU_material_has_surface_output ( GPUMaterial *  mat)

Definition at line 586 of file gpu_material.c.

References GPUMaterial::has_surface_output.

Referenced by EEVEE_materials_cache_populate().

◆ GPU_material_has_volume_output()

bool GPU_material_has_volume_output ( GPUMaterial *  mat)

◆ gpu_material_node_graph()

GPUNodeGraph* gpu_material_node_graph ( GPUMaterial *  material)

◆ GPU_material_output_displacement()

void GPU_material_output_displacement ( GPUMaterial *  material,
GPUNodeLink *  link 
)

◆ GPU_material_output_surface()

void GPU_material_output_surface ( GPUMaterial *  material,
GPUNodeLink *  link 
)

◆ GPU_material_output_thickness()

void GPU_material_output_thickness ( GPUMaterial *  material,
GPUNodeLink *  link 
)

◆ GPU_material_output_volume()

void GPU_material_output_volume ( GPUMaterial *  material,
GPUNodeLink *  link 
)

◆ gpu_material_ramp_texture_build()

static void gpu_material_ramp_texture_build ( GPUMaterial *  mat)
static

◆ gpu_material_ramp_texture_row_set()

GPUTexture** gpu_material_ramp_texture_row_set ( struct GPUMaterial *  mat,
int  size,
float *  pixels,
float *  row 
)

◆ GPU_material_recalc_flag_get()

bool GPU_material_recalc_flag_get ( GPUMaterial *  mat)

Definition at line 612 of file gpu_material.c.

References GPUMaterial::flag, and GPU_MATFLAG_UPDATED.

◆ GPU_material_release()

void GPU_material_release ( GPUMaterial *  mat)

Definition at line 707 of file gpu_material.c.

References gpu_material_free_single().

Referenced by drw_deferred_shader_compilation_exec().

◆ GPU_material_scene()

Scene* GPU_material_scene ( GPUMaterial *  material)

Definition at line 181 of file gpu_material.c.

References material.

◆ GPU_material_split_sub_function()

char* GPU_material_split_sub_function ( GPUMaterial *  material,
eGPUType  return_type,
GPUNodeLink **  link 
)

Wrap a part of the material graph into a function. You need then need to call the function by using something like GPU_differentiate_float_function.

Note
This replace the link by a constant to break the link with the main graph.
Parameters
return_typesub function return type. Output is cast to this type.
linklink to use as the sub function output.
Returns
the name of the generated function.

Definition at line 541 of file gpu_material.c.

References BLI_addtail(), BLI_assert, GPU_FLOAT, GPU_link(), GPU_VEC3, GPU_VEC4, material, MEM_callocN, GPUNodeGraphFunctionLink::name, GPUNodeGraphFunctionLink::outlink, and SNPRINTF.

Referenced by blender::nodes::node_shader_bump_cc::gpu_shader_bump().

◆ GPU_material_sss_profile_create()

bool GPU_material_sss_profile_create ( GPUMaterial *  material,
float  radii[3] 
)

◆ GPU_material_sss_profile_get()

struct GPUUniformBuf* GPU_material_sss_profile_get ( GPUMaterial *  material,
int  sample_len,
GPUTexture **  tex_profile 
)

◆ GPU_material_status()

eGPUMaterialStatus GPU_material_status ( GPUMaterial *  mat)

Return true if the material compilation has not yet begin or begin.

Definition at line 574 of file gpu_material.c.

References GPUMaterial::status.

Referenced by drw_deferred_shader_add(), and EEVEE_material_get().

◆ GPU_material_status_set()

void GPU_material_status_set ( GPUMaterial *  mat,
eGPUMaterialStatus  status 
)

◆ GPU_material_textures()

ListBase GPU_material_textures ( GPUMaterial *  material)

Definition at line 221 of file gpu_material.c.

References material.

Referenced by DRW_shgroup_add_material_resources(), and image_walk_gpu_materials().

◆ GPU_material_uniform_attributes()

GPUUniformAttrList* GPU_material_uniform_attributes ( GPUMaterial *  material)

Definition at line 226 of file gpu_material.c.

References GPUUniformAttrList::count, material, and NULL.

Referenced by DRW_shgroup_add_material_resources().

◆ GPU_material_uniform_buffer_create()

void GPU_material_uniform_buffer_create ( GPUMaterial *  material,
ListBase *  inputs 
)

Create dynamic UBO from parameters

Parameters
inputsItems are LinkData, data is GPUInput (BLI_genericNodeN(GPUInput)).

Definition at line 206 of file gpu_material.c.

References GPU_uniformbuf_create_from_list(), inputs, and material.

Referenced by GPUCodegen::generate_uniform_buffer().

◆ GPU_material_uniform_buffer_get()

GPUUniformBuf* GPU_material_uniform_buffer_get ( GPUMaterial *  material)

Definition at line 201 of file gpu_material.c.

References material.

Referenced by DRW_shgroup_add_material_resources().

◆ GPU_material_uuid_get()

uint64_t GPU_material_uuid_get ( GPUMaterial *  mat)

◆ GPU_materials_free()

void GPU_materials_free ( Main *  bmain)

◆ sss_calculate_offsets()

static void sss_calculate_offsets ( GPUSssKernelData *  kd,
int  count,
float  exponent 
)
static

Definition at line 249 of file gpu_material.c.

References count, fabsf, float(), powf, and KDL::sign().

Referenced by compute_sss_kernel().