Blender V5.0
gpu_material.cc File Reference
#include <cstring>
#include "BKE_lib_id.hh"
#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_vector.h"
#include "BLI_string.h"
#include "BLI_time.h"
#include "BLI_utildefines.h"
#include "BKE_main.hh"
#include "BKE_material.hh"
#include "BKE_node.hh"
#include "BKE_node_runtime.hh"
#include "NOD_shader.h"
#include "NOD_shader_nodes_inline.hh"
#include "GPU_material.hh"
#include "GPU_pass.hh"
#include "GPU_shader.hh"
#include "GPU_texture.hh"
#include "GPU_uniform_buffer.hh"
#include "DRW_engine.hh"
#include "gpu_node_graph.hh"
#include "atomic_ops.h"

Go to the source code of this file.

Classes

struct  GPUColorBandBuilder
struct  GPUSkyBuilder
struct  GPUMaterial

Macros

#define MAX_COLOR_BAND   128
#define MAX_GPU_SKIES   8

Functions

static void gpu_material_ramp_texture_build (GPUMaterial *mat)
static void gpu_material_sky_texture_build (GPUMaterial *mat)
GPUMaterialFromNodeTreeResult GPU_material_from_nodetree (Material *ma, bNodeTree *ntree, ListBase *gpumaterials, const char *name, eGPUMaterialEngine engine, uint64_t shader_uuid, bool deferred_compilation, GPUCodegenCallbackFn callback, void *thunk, GPUMaterialPassReplacementCallbackFn pass_replacement_cb)
GPUMaterialGPU_material_from_callbacks (eGPUMaterialEngine engine, ConstructGPUMaterialFn construct_function_cb, GPUCodegenCallbackFn generate_code_function_cb, void *thunk)
void GPU_material_free_single (GPUMaterial *material)
void GPU_material_free (ListBase *gpumaterial)
void GPU_materials_free (Main *bmain)
const char * GPU_material_get_name (GPUMaterial *material)
uint64_t GPU_material_uuid_get (GPUMaterial *mat)
MaterialGPU_material_get_material (GPUMaterial *material)
GPUPassGPU_material_get_pass (GPUMaterial *material)
blender::gpu::ShaderGPU_material_get_shader (GPUMaterial *material)
GPUMaterialStatus GPU_material_status (GPUMaterial *mat)
eGPUMaterialOptimizationStatus GPU_material_optimization_status (GPUMaterial *mat)
uint64_t GPU_material_compilation_timestamp (GPUMaterial *mat)
bool GPU_material_has_surface_output (GPUMaterial *mat)
bool GPU_material_has_volume_output (GPUMaterial *mat)
bool GPU_material_has_displacement_output (GPUMaterial *mat)
bool GPU_material_flag_get (const GPUMaterial *mat, eGPUMaterialFlag flag)
eGPUMaterialFlag GPU_material_flag (const GPUMaterial *mat)
void GPU_material_flag_set (GPUMaterial *mat, eGPUMaterialFlag flag)
void GPU_material_uniform_buffer_create (GPUMaterial *material, ListBase *inputs)
blender::gpu::UniformBufGPU_material_uniform_buffer_get (GPUMaterial *material)
ListBase GPU_material_attributes (const GPUMaterial *material)
ListBase GPU_material_textures (GPUMaterial *material)
const GPUUniformAttrListGPU_material_uniform_attributes (const GPUMaterial *material)
const ListBaseGPU_material_layer_attributes (const GPUMaterial *material)
GPUNodeGraphgpu_material_node_graph (GPUMaterial *material)
blender::gpu::Texture ** gpu_material_sky_texture_layer_set (GPUMaterial *mat, int width, int height, const float *pixels, float *row)
blender::gpu::Texture ** gpu_material_ramp_texture_row_set (GPUMaterial *mat, int size, const float *pixels, float *r_row)
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)
void GPU_material_add_output_link_composite (GPUMaterial *material, GPUNodeLink *link)
char * GPU_material_split_sub_function (GPUMaterial *material, GPUType return_type, GPUNodeLink **link)

Detailed Description

Manages materials, lights and textures.

Definition in file gpu/intern/gpu_material.cc.

Macro Definition Documentation

◆ MAX_COLOR_BAND

#define MAX_COLOR_BAND   128

Definition at line 50 of file gpu/intern/gpu_material.cc.

Referenced by gpu_material_ramp_texture_row_set().

◆ MAX_GPU_SKIES

#define MAX_GPU_SKIES   8

Definition at line 51 of file gpu/intern/gpu_material.cc.

Referenced by gpu_material_sky_texture_layer_set().

Function Documentation

◆ GPU_material_add_output_link_aov()

◆ GPU_material_add_output_link_composite()

void GPU_material_add_output_link_composite ( GPUMaterial * material,
GPUNodeLink * link )

◆ GPU_material_attributes()

◆ GPU_material_compilation_timestamp()

uint64_t GPU_material_compilation_timestamp ( GPUMaterial * mat)

◆ GPU_material_flag()

eGPUMaterialFlag GPU_material_flag ( const GPUMaterial * mat)

◆ GPU_material_flag_get()

◆ GPU_material_flag_set()

void GPU_material_flag_set ( GPUMaterial * mat,
eGPUMaterialFlag flag )

Definition at line 376 of file gpu/intern/gpu_material.cc.

References flag, GPUMaterial::flag, GPU_MATFLAG_COAT, and GPU_MATFLAG_GLOSSY.

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_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_hair_cc::node_shader_gpu_bsdf_hair(), blender::nodes::node_shader_bsdf_metallic_cc::node_shader_gpu_bsdf_metallic(), blender::nodes::node_shader_bsdf_principled_cc::node_shader_gpu_bsdf_principled(), blender::nodes::node_shader_bsdf_ray_portal_cc::node_shader_gpu_bsdf_ray_portal(), blender::nodes::node_shader_bsdf_refraction_cc::node_shader_gpu_bsdf_refraction(), blender::nodes::node_shader_bsdf_sheen_cc::node_shader_gpu_bsdf_sheen(), 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_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_bsdf_hair_principled_cc::node_shader_gpu_hair_principled(), 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(), blender::nodes::node_shader_volume_absorption_cc::node_shader_gpu_volume_absorption(), blender::nodes::node_shader_volume_coefficients_cc::node_shader_gpu_volume_coefficients(), blender::nodes::node_shader_volume_principled_cc::node_shader_gpu_volume_principled(), blender::nodes::node_shader_volume_scatter_cc::node_shader_gpu_volume_scatter(), and blender::nodes::node_shader_wireframe_cc::node_shader_gpu_wireframe().

◆ GPU_material_free()

◆ GPU_material_free_single()

void GPU_material_free_single ( GPUMaterial * material)

◆ GPU_material_from_callbacks()

◆ GPU_material_from_nodetree()

GPUMaterialFromNodeTreeResult GPU_material_from_nodetree ( Material * ma,
bNodeTree * ntree,
ListBase * gpumaterials,
const char * name,
eGPUMaterialEngine engine,
uint64_t shader_uuid,
bool deferred_compilation,
GPUCodegenCallbackFn callback,
void * thunk,
GPUMaterialPassReplacementCallbackFn pass_replacement_cb = nullptr )

◆ GPU_material_get_material()

◆ GPU_material_get_name()

◆ GPU_material_get_pass()

◆ GPU_material_get_shader()

blender::gpu::Shader * GPU_material_get_shader ( GPUMaterial * material)

Return the most optimal shader configuration for the given material.

Definition at line 312 of file gpu/intern/gpu_material.cc.

References GPU_material_get_pass(), and GPU_pass_shader_get().

Referenced by blender::compositor::ShaderOperation::execute(), and blender::eevee::ShaderKey::ShaderKey().

◆ GPU_material_has_displacement_output()

◆ GPU_material_has_surface_output()

bool GPU_material_has_surface_output ( GPUMaterial * mat)

Definition at line 351 of file gpu/intern/gpu_material.cc.

References GPUMaterial::has_surface_output.

◆ GPU_material_has_volume_output()

◆ GPU_material_layer_attributes()

const ListBase * GPU_material_layer_attributes ( const GPUMaterial * material)

◆ gpu_material_node_graph()

◆ GPU_material_optimization_status()

◆ GPU_material_output_displacement()

◆ GPU_material_output_surface()

◆ GPU_material_output_thickness()

void GPU_material_output_thickness ( GPUMaterial * material,
GPUNodeLink * link )

◆ GPU_material_output_volume()

◆ gpu_material_ramp_texture_build()

◆ gpu_material_ramp_texture_row_set()

blender::gpu::Texture ** gpu_material_ramp_texture_row_set ( GPUMaterial * mat,
int size,
const float * pixels,
float * r_row )

◆ gpu_material_sky_texture_build()

◆ gpu_material_sky_texture_layer_set()

blender::gpu::Texture ** gpu_material_sky_texture_layer_set ( GPUMaterial * mat,
int width,
int height,
const float * pixels,
float * row )

◆ GPU_material_split_sub_function()

char * GPU_material_split_sub_function ( GPUMaterial * material,
GPUType 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 570 of file gpu/intern/gpu_material.cc.

References BLI_addtail(), BLI_assert, GPUMaterial::generated_function_len, GPU_FLOAT, GPU_link(), GPU_VEC3, GPU_VEC4, GPUMaterial::graph, GPUNodeGraph::material_functions, MEM_callocN(), GPUNodeGraphFunctionLink::name, GPUNodeGraphFunctionLink::outlink, and SNPRINTF.

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

◆ GPU_material_status()

GPUMaterialStatus GPU_material_status ( GPUMaterial * mat)

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

Definition at line 317 of file gpu/intern/gpu_material.cc.

References GPU_MAT_FAILED, GPU_MAT_QUEUED, GPU_MAT_SUCCESS, GPU_PASS_QUEUED, GPU_pass_status(), GPU_PASS_SUCCESS, and GPUMaterial::pass.

Referenced by blender::eevee::World::sync(), and blender::eevee::WorldVolumePipeline::sync().

◆ GPU_material_textures()

◆ GPU_material_uniform_attributes()

◆ 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 385 of file gpu/intern/gpu_material.cc.

References GPU_uniformbuf_create_from_list(), inputs, GPUMaterial::name, and GPUMaterial::ubo.

Referenced by blender::gpu::shader::GPUCodegen::generate_uniform_buffer().

◆ GPU_material_uniform_buffer_get()

blender::gpu::UniformBuf * GPU_material_uniform_buffer_get ( GPUMaterial * material)

◆ GPU_material_uuid_get()

◆ GPU_materials_free()