Blender  V2.93
Classes | Macros | Typedefs | Enumerations | 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_ghash.h"
#include "BLI_listbase.h"
#include "BLI_math.h"
#include "BLI_string.h"
#include "BLI_string_utils.h"
#include "BLI_utildefines.h"
#include "BKE_main.h"
#include "BKE_material.h"
#include "BKE_node.h"
#include "BKE_scene.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"

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 GAUSS_TRUNCATE   12.46f
 
#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
 

Enumerations

enum  { GPU_USE_SURFACE_OUTPUT = (1 << 0) , GPU_USE_VOLUME_OUTPUT = (1 << 1) }
 

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)
 
SceneGPU_material_scene (GPUMaterial *material)
 
GPUPassGPU_material_get_pass (GPUMaterial *material)
 
GPUShaderGPU_material_get_shader (GPUMaterial *material)
 
MaterialGPU_material_get_material (GPUMaterial *material)
 
GPUUniformBufGPU_material_uniform_buffer_get (GPUMaterial *material)
 
void GPU_material_uniform_buffer_create (GPUMaterial *material, ListBase *inputs)
 
static void sss_calculate_offsets (GPUSssKernelData *kd, int count, float exponent)
 
static float gaussian_profile (float r, float radius)
 
static float burley_profile (float r, float d)
 
static float cubic_profile (float r, float radius, float sharpness)
 
static float eval_profile (float r, short falloff_type, float sharpness, float param)
 
static float eval_integral (float x0, float x1, short falloff_type, float sharpness, float param)
 
static void compute_sss_kernel (GPUSssKernelData *kd, const float radii[3], int sample_len, int falloff_type, float sharpness)
 
static void compute_sss_translucence_kernel (const GPUSssKernelData *kd, int resolution, short falloff_type, float sharpness, float **output)
 
void GPU_material_sss_profile_create (GPUMaterial *material, float radii[3], const short *falloff_type, const float *sharpness)
 
struct GPUUniformBufGPU_material_sss_profile_get (GPUMaterial *material, int sample_len, GPUTexture **tex_profile)
 
struct GPUUniformBufGPU_material_create_sss_profile_ubo (void)
 
ListBase GPU_material_attributes (GPUMaterial *material)
 
ListBase GPU_material_textures (GPUMaterial *material)
 
ListBase GPU_material_volume_grids (GPUMaterial *material)
 
GPUUniformAttrListGPU_material_uniform_attributes (GPUMaterial *material)
 
void GPU_material_output_link (GPUMaterial *material, GPUNodeLink *link)
 
void GPU_material_add_output_link_aov (GPUMaterial *material, GPUNodeLink *link, int hash)
 
GPUNodeGraphgpu_material_node_graph (GPUMaterial *material)
 
GSetgpu_material_used_libraries (GPUMaterial *material)
 
eGPUMaterialStatus GPU_material_status (GPUMaterial *mat)
 
bool GPU_material_has_surface_output (GPUMaterial *mat)
 
bool GPU_material_has_volume_output (GPUMaterial *mat)
 
bool GPU_material_is_volume_shader (GPUMaterial *mat)
 
void GPU_material_flag_set (GPUMaterial *mat, eGPUMatFlag flag)
 
bool GPU_material_flag_get (GPUMaterial *mat, eGPUMatFlag flag)
 
GPUMaterialGPU_material_from_nodetree_find (ListBase *gpumaterials, const void *engine_type, int options)
 
GPUMaterialGPU_material_from_nodetree (Scene *scene, struct Material *ma, struct bNodeTree *ntree, ListBase *gpumaterials, const void *engine_type, const int options, const bool is_volume_shader, const char *vert_code, const char *geom_code, const char *frag_lib, const char *defines, const char *name, GPUMaterialEvalCallbackFn callback)
 
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 281 of file gpu_material.c.

◆ BURLEY_TRUNCATE_CDF

#define BURLEY_TRUNCATE_CDF   0.9963790093708328f

Definition at line 282 of file gpu_material.c.

◆ GAUSS_TRUNCATE

#define GAUSS_TRUNCATE   12.46f

Definition at line 269 of file gpu_material.c.

◆ INTEGRAL_RESOLUTION [1/2]

#define INTEGRAL_RESOLUTION   32

Definition at line 439 of file gpu_material.c.

◆ INTEGRAL_RESOLUTION [2/2]

#define INTEGRAL_RESOLUTION   512

Definition at line 439 of file gpu_material.c.

◆ MAX_COLOR_BAND

#define MAX_COLOR_BAND   128

Definition at line 58 of file gpu_material.c.

◆ SSS_EXPONENT

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

Definition at line 247 of file gpu_material.c.

◆ SSS_SAMPLES

#define SSS_SAMPLES   65

Definition at line 246 of file gpu_material.c.

Typedef Documentation

◆ GPUColorBandBuilder

◆ GPUSssKernelData

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
GPU_USE_SURFACE_OUTPUT 
GPU_USE_VOLUME_OUTPUT 

Definition at line 113 of file gpu_material.c.

Function Documentation

◆ burley_profile()

static float burley_profile ( float  r,
float  d 
)
static

Definition at line 283 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,
int  falloff_type,
float  sharpness 
)
static

◆ compute_sss_translucence_kernel()

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

◆ cubic_profile()

static float cubic_profile ( float  r,
float  radius,
float  sharpness 
)
static

Definition at line 290 of file gpu_material.c.

References M_PI, powf, r, and y.

Referenced by eval_profile().

◆ eval_integral()

static float eval_integral ( float  x0,
float  x1,
short  falloff_type,
float  sharpness,
float  param 
)
static

Definition at line 328 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,
short  falloff_type,
float  sharpness,
float  param 
)
static

◆ gaussian_profile()

static float gaussian_profile ( float  r,
float  radius 
)
static

Definition at line 270 of file gpu_material.c.

References expf, GAUSS_TRUNCATE, M_PI, r, sqrtf, and v.

Referenced by eval_profile().

◆ 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)

Definition at line 572 of file gpu_material.c.

References material.

Referenced by curve_cd_calc_used_gpu_layers(), and mesh_cd_calc_used_gpu_layers().

◆ 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 564 of file gpu_material.c.

References GPU_uniformbuf_create.

◆ GPU_material_flag_get()

bool GPU_material_flag_get ( GPUMaterial mat,
eGPUMatFlag  flag 
)

◆ GPU_material_flag_set()

void GPU_material_flag_set ( GPUMaterial mat,
eGPUMatFlag  flag 
)

◆ 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 ( Scene scene,
struct Material ma,
struct bNodeTree ntree,
ListBase gpumaterials,
const void *  engine_type,
const int  options,
const bool  is_volume_shader,
const char *  vert_code,
const char *  geom_code,
const char *  frag_lib,
const char *  defines,
const char *  name,
GPUMaterialEvalCallbackFn  callback 
)

◆ GPU_material_from_nodetree_find()

GPUMaterial* GPU_material_from_nodetree_find ( ListBase gpumaterials,
const void *  engine_type,
int  options 
)

◆ GPU_material_get_material()

Material* GPU_material_get_material ( GPUMaterial material)

Definition at line 218 of file gpu_material.c.

References material.

Referenced by node_shader_gpu_object_info(), and node_shader_gpu_output_material().

◆ GPU_material_get_pass()

GPUPass* GPU_material_get_pass ( GPUMaterial material)

Definition at line 207 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 626 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_is_volume_shader()

bool GPU_material_is_volume_shader ( GPUMaterial mat)

Definition at line 636 of file gpu_material.c.

References GPUMaterial::is_volume_shader.

Referenced by node_shader_gpu_attribute().

◆ gpu_material_node_graph()

GPUNodeGraph* gpu_material_node_graph ( GPUMaterial material)

◆ GPU_material_output_link()

void GPU_material_output_link ( GPUMaterial material,
GPUNodeLink link 
)

Definition at line 593 of file gpu_material.c.

References material.

Referenced by node_shader_gpu_output_material(), and node_shader_gpu_output_world().

◆ 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 ( GPUMaterial mat,
int  size,
float pixels,
float row 
)

◆ GPU_material_scene()

Scene* GPU_material_scene ( GPUMaterial material)

Definition at line 202 of file gpu_material.c.

References material.

Referenced by DRW_deferred_shader_remove().

◆ GPU_material_sss_profile_create()

void GPU_material_sss_profile_create ( GPUMaterial material,
float  radii[3],
const short *  falloff_type,
const float sharpness 
)

◆ 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)

◆ GPU_material_textures()

ListBase GPU_material_textures ( GPUMaterial material)

Definition at line 577 of file gpu_material.c.

References material.

Referenced by DRW_shgroup_add_material_resources().

◆ GPU_material_uniform_attributes()

GPUUniformAttrList* GPU_material_uniform_attributes ( GPUMaterial material)

Definition at line 587 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 233 of file gpu_material.c.

References GPU_uniformbuf_create_from_list(), inputs, and material.

Referenced by codegen_process_uniforms_functions().

◆ GPU_material_uniform_buffer_get()

GPUUniformBuf* GPU_material_uniform_buffer_get ( GPUMaterial material)

Definition at line 223 of file gpu_material.c.

References material.

Referenced by DRW_shgroup_add_material_resources().

◆ gpu_material_used_libraries()

GSet* gpu_material_used_libraries ( GPUMaterial material)

Definition at line 613 of file gpu_material.c.

References material.

Referenced by GPU_generate_pass(), GPU_link(), and GPU_stack_link().

◆ GPU_material_volume_grids()

ListBase GPU_material_volume_grids ( GPUMaterial material)

Definition at line 582 of file gpu_material.c.

References material.

Referenced by EEVEE_volumes_cache_init(), and EEVEE_volumes_cache_object_add().

◆ 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 258 of file gpu_material.c.

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

Referenced by compute_sss_kernel().