Blender
V3.3
|
#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 |
Manages materials, lights and textures.
Definition in file gpu_material.c.
#define BURLEY_TRUNCATE 16.0f |
Definition at line 260 of file gpu_material.c.
#define BURLEY_TRUNCATE_CDF 0.9963790093708328f |
Definition at line 261 of file gpu_material.c.
#define INTEGRAL_RESOLUTION 32 |
Definition at line 377 of file gpu_material.c.
#define INTEGRAL_RESOLUTION 512 |
Definition at line 377 of file gpu_material.c.
#define MAX_COLOR_BAND 128 |
Definition at line 43 of file gpu_material.c.
#define SSS_EXPONENT 2.0f /* Importance sampling exponent */ |
Definition at line 237 of file gpu_material.c.
#define SSS_SAMPLES 65 |
Definition at line 236 of file gpu_material.c.
typedef struct GPUColorBandBuilder GPUColorBandBuilder |
typedef struct GPUSssKernelData GPUSssKernelData |
Definition at line 262 of file gpu_material.c.
Referenced by eval_profile().
|
static |
Definition at line 293 of file gpu_material.c.
References A, GPUSssKernelData::avg_inv_radius, BURLEY_TRUNCATE, copy_v3_v3(), copy_v4_v4(), eval_integral(), fabsf, GPUSssKernelData::kernel, l, M_1_PI, MAX2, MAX3, GPUSssKernelData::max_radius, mul_v3_v3fl(), GPUSssKernelData::param, radii, GPUSssKernelData::samples, sss_calculate_offsets(), SSS_EXPONENT, and sum().
Referenced by GPU_material_sss_profile_get().
|
static |
Definition at line 378 of file gpu_material.c.
References add_v3_v3(), eval_profile(), float(), hypotf, INTEGRAL_RESOLUTION, M_PI, GPUSssKernelData::max_radius, MEM_callocN, mul_v3_fl(), output, GPUSssKernelData::param, r, and sqrtf.
Referenced by GPU_material_sss_profile_get().
Definition at line 277 of file gpu_material.c.
References eval_profile(), float(), INTEGRAL_RESOLUTION, x, and y.
Referenced by compute_sss_kernel().
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().
void GPU_material_acquire | ( | GPUMaterial * | mat | ) |
Definition at line 702 of file gpu_material.c.
References atomic_add_and_fetch_uint32(), and GPUMaterial::refcount.
Referenced by drw_deferred_shader_compilation_exec().
void GPU_material_add_output_link_aov | ( | GPUMaterial * | material, |
GPUNodeLink * | link, | ||
int | hash | ||
) |
Definition at line 533 of file gpu_material.c.
References BLI_addtail(), hash, GPUNodeGraphOutputLink::hash, material, MEM_callocN, and GPUNodeGraphOutputLink::outlink.
Referenced by blender::nodes::node_shader_output_aov_cc::node_shader_gpu_output_aov().
ListBase GPU_material_attributes | ( | GPUMaterial * | material | ) |
Definition at line 216 of file gpu_material.c.
References material.
Referenced by attribute_index_in_material(), curves_batch_cache_ensure_procedural_pos(), curves_ensure_attributes(), DRW_shgroup_volume_create_sub(), mesh_cd_calc_used_gpu_layers(), and particle_batch_cache_ensure_procedural_pos().
void GPU_material_compile | ( | GPUMaterial * | mat | ) |
Definition at line 712 of file gpu_material.c.
References BLI_assert, ELEM, GPUMaterial::flag, GPU_MAT_CREATED, GPU_MAT_FAILED, GPU_MAT_QUEUED, GPU_MAT_SUCCESS, GPU_MATFLAG_UPDATED, gpu_node_graph_free(), gpu_node_graph_free_nodes(), GPU_pass_compile(), GPU_pass_release(), GPU_pass_shader_get(), GPUMaterial::graph, GPUMaterial::name, NULL, GPUMaterial::pass, sh, and GPUMaterial::status.
Referenced by drw_deferred_shader_add(), drw_deferred_shader_compilation_exec(), and blender::eevee::ShaderModule::material_shader_get().
struct GPUUniformBuf* GPU_material_create_sss_profile_ubo | ( | void | ) |
Definition at line 494 of file gpu_material.c.
References GPU_uniformbuf_create.
eGPUMaterialFlag GPU_material_flag | ( | const GPUMaterial * | mat | ) |
Definition at line 606 of file gpu_material.c.
References GPUMaterial::flag.
Referenced by GPUCodegen::GPUCodegen().
bool GPU_material_flag_get | ( | const GPUMaterial * | mat, |
eGPUMaterialFlag | flag | ||
) |
Definition at line 601 of file gpu_material.c.
References GPUMaterial::flag.
Referenced by EEVEE_material_bind_resources(), eevee_shader_material_create_info_amend(), GPUCodegen::generate_resources(), GPUCodegen::GPUCodegen(), blender::eevee::ForwardPipeline::material_add(), blender::eevee::ShaderModule::material_create_info_ammend(), material_opaque(), blender::nodes::node_shader_tex_environment_cc::node_shader_gpu_tex_environment(), blender::eevee::ForwardPipeline::prepass_add(), and blender::eevee::shader_closure_bits_from_flag().
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().
Definition at line 171 of file gpu_material.c.
References BLI_freelistN(), DRW_deferred_shader_remove, gpu_material_free_single(), LISTBASE_FOREACH, and material.
Referenced by BKE_material_copybuf_paste(), BKE_material_defaults_free_gpu(), BKE_material_eval(), BKE_world_eval(), ED_node_set_active(), GPU_materials_free(), material_free_data(), and world_free_data().
|
static |
Definition at line 144 of file gpu_material.c.
References atomic_sub_and_fetch_uint32(), gpu_node_graph_free(), GPU_pass_release(), GPU_texture_free(), GPU_uniformbuf_free(), material, MEM_freeN, and NULL.
Referenced by GPU_material_free(), and GPU_material_release().
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 | ||
) |
Definition at line 624 of file gpu_material.c.
References BLI_addtail(), BLI_assert, BLI_ghashutil_ptrcmp(), BLI_ghashutil_ptrhash(), BLI_gset_new(), callback, LinkData::data, GPUMaterial::flag, GPU_generate_pass(), GPU_MAT_CREATED, GPU_MAT_FAILED, GPU_MAT_SUCCESS, gpu_material_ramp_texture_build(), GPU_MATFLAG_LOOKDEV_HACK, GPU_MATFLAG_UPDATED, gpu_node_graph_free(), gpu_node_graph_free_nodes(), GPU_pass_shader_get(), GPUMaterial::graph, bNodeTree::id, if(), GPUMaterial::is_volume_shader, LISTBASE_FOREACH, GPUMaterial::ma, MEM_callocN, MEM_freeN, GPUMaterial::name, ntree, ntreeFreeLocalTree, ntreeGPUMaterialNodes, ntreeLocalize, NULL, GPUMaterial::pass, ID::py_instance, GPUMaterial::refcount, scene, GPUMaterial::scene, sh, GPUMaterial::status, STRNCPY, UNUSED_VARS, GPUNodeGraph::used_libraries, and GPUMaterial::uuid.
Referenced by DRW_shader_from_material(), DRW_shader_from_world(), and blender::eevee::ShaderModule::material_shader_get().
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().
GPUPass* GPU_material_get_pass | ( | GPUMaterial * | material | ) |
Definition at line 186 of file gpu_material.c.
References material.
Referenced by DRW_shgroup_material_create().
GPUShader* GPU_material_get_shader | ( | GPUMaterial * | material | ) |
Definition at line 191 of file gpu_material.c.
References GPU_pass_shader_get(), material, and NULL.
Referenced by eevee_lookdev_hdri_preview_init(), EEVEE_volumes_cache_object_add(), material_opaque(), material_shadow(), material_transparent(), and blender::eevee::ShaderKey::ShaderKey().
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().
bool GPU_material_has_volume_output | ( | GPUMaterial * | mat | ) |
Definition at line 591 of file gpu_material.c.
References GPUMaterial::has_volume_output.
Referenced by EEVEE_materials_cache_populate(), and EEVEE_volumes_cache_init().
GPUNodeGraph* gpu_material_node_graph | ( | GPUMaterial * | material | ) |
Definition at line 569 of file gpu_material.c.
References material.
Referenced by GPU_attribute(), GPU_attribute_default_color(), GPU_color_band(), GPU_image(), GPU_image_tiled(), GPU_image_tiled_mapping(), GPU_link(), gpu_stack_link_v(), and GPU_uniform_attribute().
void GPU_material_output_displacement | ( | GPUMaterial * | material, |
GPUNodeLink * | link | ||
) |
Definition at line 519 of file gpu_material.c.
References material.
Referenced by blender::nodes::node_shader_output_material_cc::node_shader_gpu_output_material().
void GPU_material_output_surface | ( | GPUMaterial * | material, |
GPUNodeLink * | link | ||
) |
Definition at line 503 of file gpu_material.c.
References material.
Referenced by blender::nodes::node_shader_output_light_cc::node_shader_gpu_output_light(), blender::nodes::node_shader_output_material_cc::node_shader_gpu_output_material(), and blender::nodes::node_shader_output_world_cc::node_shader_gpu_output_world().
void GPU_material_output_thickness | ( | GPUMaterial * | material, |
GPUNodeLink * | link | ||
) |
Definition at line 526 of file gpu_material.c.
References material.
Referenced by blender::nodes::node_shader_output_material_cc::node_shader_gpu_output_material().
void GPU_material_output_volume | ( | GPUMaterial * | material, |
GPUNodeLink * | link | ||
) |
Definition at line 511 of file gpu_material.c.
References material.
Referenced by blender::nodes::node_shader_output_material_cc::node_shader_gpu_output_material(), and blender::nodes::node_shader_output_world_cc::node_shader_gpu_output_world().
|
static |
Definition at line 129 of file gpu_material.c.
References CM_TABLE, GPUMaterial::coba_builder, GPUMaterial::coba_tex, GPUColorBandBuilder::current_layer, GPU_RGBA16F, GPU_texture_create_1d_array(), MEM_freeN, NULL, and GPUColorBandBuilder::pixels.
Referenced by GPU_material_from_nodetree().
GPUTexture** gpu_material_ramp_texture_row_set | ( | struct GPUMaterial * | mat, |
int | size, | ||
float * | pixels, | ||
float * | row | ||
) |
Returns the address of the future pointer to coba_tex.
Definition at line 99 of file gpu_material.c.
References BLI_assert, CM_TABLE, GPUMaterial::coba_builder, GPUMaterial::coba_tex, GPUColorBandBuilder::current_layer, float(), MAX_COLOR_BAND, MEM_mallocN, NULL, GPUColorBandBuilder::pixels, size(), and UNUSED_VARS_NDEBUG.
Referenced by GPU_color_band().
bool GPU_material_recalc_flag_get | ( | GPUMaterial * | mat | ) |
Definition at line 612 of file gpu_material.c.
References GPUMaterial::flag, and GPU_MATFLAG_UPDATED.
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().
Scene* GPU_material_scene | ( | GPUMaterial * | material | ) |
Definition at line 181 of file gpu_material.c.
References material.
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.
return_type | sub function return type. Output is cast to this type. |
link | link to use as the sub function output. |
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().
bool GPU_material_sss_profile_create | ( | GPUMaterial * | material, |
float | radii[3] | ||
) |
Definition at line 438 of file gpu_material.c.
References copy_v3_v3(), GPU_uniformbuf_create, material, NULL, and radii.
Referenced by blender::nodes::node_shader_bsdf_principled_cc::node_shader_gpu_bsdf_principled(), and blender::nodes::node_shader_subsurface_scattering_cc::node_shader_gpu_subsurface_scattering().
struct GPUUniformBuf* GPU_material_sss_profile_get | ( | GPUMaterial * | material, |
int | sample_len, | ||
GPUTexture ** | tex_profile | ||
) |
Definition at line 455 of file gpu_material.c.
References compute_sss_kernel(), compute_sss_translucence_kernel(), GPU_RGBA16F, GPU_texture_create_1d(), GPU_texture_free(), GPU_uniformbuf_update(), material, MEM_freeN, and NULL.
Referenced by EEVEE_subsurface_add_pass().
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().
void GPU_material_status_set | ( | GPUMaterial * | mat, |
eGPUMaterialStatus | status | ||
) |
Definition at line 579 of file gpu_material.c.
References GPUMaterial::status.
Referenced by drw_deferred_shader_add(), DRW_deferred_shader_remove(), and blender::eevee::ShaderModule::material_shader_get().
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().
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().
void GPU_material_uniform_buffer_create | ( | GPUMaterial * | material, |
ListBase * | inputs | ||
) |
Create dynamic UBO from parameters
Definition at line 206 of file gpu_material.c.
References GPU_uniformbuf_create_from_list(), inputs, and material.
Referenced by GPUCodegen::generate_uniform_buffer().
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().
uint64_t GPU_material_uuid_get | ( | GPUMaterial * | mat | ) |
Definition at line 619 of file gpu_material.c.
References GPUMaterial::uuid.
Referenced by eevee_material_post_eval(), eevee_shader_material_create_info_amend(), GPUCodegen::GPUCodegen(), and blender::eevee::ShaderModule::material_create_info_ammend().
Definition at line 747 of file gpu_material.c.
References BKE_material_defaults_free_gpu(), GPU_material_free(), LISTBASE_FOREACH, Main::materials, and Main::worlds.
Referenced by outliner_id_remap_exec().
|
static |
Definition at line 249 of file gpu_material.c.
References count, fabsf, float(), powf, and KDL::sign().
Referenced by compute_sss_kernel().