[Bf-blender-cvs] [b1dbb99b34f] new-object-types: Cleanup: more refactoring of GPU material requested attributes/textures
Brecht Van Lommel
noreply at git.blender.org
Wed Feb 19 19:46:22 CET 2020
Commit: b1dbb99b34f6ea88a61bcf4f0f912adb594890ce
Author: Brecht Van Lommel
Date: Wed Feb 19 19:26:43 2020 +0100
Branches: new-object-types
https://developer.blender.org/rBb1dbb99b34f6ea88a61bcf4f0f912adb594890ce
Cleanup: more refactoring of GPU material requested attributes/textures
Volume grids are now handled separately from image textures.
===================================================================
M source/blender/draw/engines/eevee/eevee_volumes.c
M source/blender/draw/intern/draw_manager_data.c
M source/blender/gpu/GPU_material.h
M source/blender/gpu/intern/gpu_codegen.c
M source/blender/gpu/intern/gpu_material.c
M source/blender/gpu/intern/gpu_node_graph.c
M source/blender/gpu/intern/gpu_node_graph.h
M source/blender/nodes/shader/node_shader_util.c
M source/blender/nodes/shader/nodes/node_shader_attribute.c
M source/blender/nodes/shader/nodes/node_shader_geometry.c
M source/blender/nodes/shader/nodes/node_shader_normal_map.c
M source/blender/nodes/shader/nodes/node_shader_tangent.c
M source/blender/nodes/shader/nodes/node_shader_tex_coord.c
M source/blender/nodes/shader/nodes/node_shader_tex_environment.c
M source/blender/nodes/shader/nodes/node_shader_tex_image.c
M source/blender/nodes/shader/nodes/node_shader_tex_sky.c
M source/blender/nodes/shader/nodes/node_shader_uvmap.c
M source/blender/nodes/shader/nodes/node_shader_vector_displacement.c
M source/blender/nodes/shader/nodes/node_shader_vertex_color.c
M source/blender/nodes/shader/nodes/node_shader_volume_info.c
M source/blender/nodes/shader/nodes/node_shader_volume_principled.c
===================================================================
diff --git a/source/blender/draw/engines/eevee/eevee_volumes.c b/source/blender/draw/engines/eevee/eevee_volumes.c
index 3631ef69969..57043339829 100644
--- a/source/blender/draw/engines/eevee/eevee_volumes.c
+++ b/source/blender/draw/engines/eevee/eevee_volumes.c
@@ -368,11 +368,10 @@ void EEVEE_volumes_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
DRW_shgroup_uniform_block(grp, "shadow_block", sldata->shadow_ubo);
/* Fix principle volumetric not working with world materials. */
- ListBase textures = GPU_material_textures(mat);
- for (GPUMaterialTexture *tex = textures.first; tex; tex = tex->next) {
- if (tex->volume_grid) {
- DRW_shgroup_uniform_texture(grp, tex->shadername, e_data.dummy_density);
- }
+ ListBase gpu_grids = GPU_material_volume_grids(mat);
+ for (GPUMaterialVolumeGrid *gpu_grid = gpu_grids.first; gpu_grid;
+ gpu_grid = gpu_grid->next) {
+ DRW_shgroup_uniform_texture(grp, gpu_grid->sampler_name, e_data.dummy_density);
}
DRW_shgroup_call_procedural_triangles(grp, NULL, common_data->vol_tex_size[2]);
@@ -437,7 +436,7 @@ void EEVEE_volumes_cache_object_add(EEVEE_ViewLayerData *sldata,
DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
- ListBase textures = GPU_material_textures(mat);
+ ListBase gpu_grids = GPU_material_volume_grids(mat);
bool have_transform = false;
/* Volume Object */
@@ -445,18 +444,18 @@ void EEVEE_volumes_cache_object_add(EEVEE_ViewLayerData *sldata,
Volume *volume = ob->data;
BKE_volume_load(volume, G.main);
- for (GPUMaterialTexture *tex = textures.first; tex; tex = tex->next) {
- if (tex->volume_grid == NULL) {
- continue;
- }
-
- VolumeGrid *volume_grid = BKE_volume_grid_find(volume, tex->volume_grid);
+ for (GPUMaterialVolumeGrid *gpu_grid = gpu_grids.first; gpu_grid; gpu_grid = gpu_grid->next) {
+ VolumeGrid *volume_grid = BKE_volume_grid_find(volume, gpu_grid->name);
DRWVolumeGrid *drw_grid = (volume_grid) ?
DRW_volume_batch_cache_get_grid(volume, volume_grid) :
NULL;
- DRW_shgroup_uniform_texture(
- grp, tex->shadername, (drw_grid) ? drw_grid->texture : e_data.dummy_density);
+ if (drw_grid == NULL) {
+ DRW_shgroup_uniform_texture(grp, gpu_grid->sampler_name, e_data.dummy_density);
+ continue;
+ }
+
+ DRW_shgroup_uniform_texture(grp, gpu_grid->sampler_name, drw_grid->texture);
/* Volume dimensions for texture sampling. */
if (!have_transform && drw_grid) {
@@ -505,25 +504,23 @@ void EEVEE_volumes_cache_object_add(EEVEE_ViewLayerData *sldata,
BLI_addtail(&e_data.smoke_domains, BLI_genericNodeN(mmd));
}
- for (GPUMaterialTexture *tex = textures.first; tex; tex = tex->next) {
- if (tex->volume_grid == NULL) {
- continue;
- }
-
- if (STREQ(tex->volume_grid, "density")) {
- DRW_shgroup_uniform_texture_ref(
- grp, tex->shadername, mds->tex_density ? &mds->tex_density : &e_data.dummy_density);
+ for (GPUMaterialVolumeGrid *gpu_grid = gpu_grids.first; gpu_grid; gpu_grid = gpu_grid->next) {
+ if (STREQ(gpu_grid->name, "density")) {
+ DRW_shgroup_uniform_texture_ref(grp,
+ gpu_grid->sampler_name,
+ mds->tex_density ? &mds->tex_density :
+ &e_data.dummy_density);
}
- else if (STREQ(tex->volume_grid, "color")) {
+ else if (STREQ(gpu_grid->name, "color")) {
DRW_shgroup_uniform_texture_ref(
- grp, tex->shadername, mds->tex_color ? &mds->tex_color : &e_data.dummy_color);
+ grp, gpu_grid->sampler_name, mds->tex_color ? &mds->tex_color : &e_data.dummy_color);
}
- else if (STREQ(tex->volume_grid, "flame") || STREQ(tex->volume_grid, "temperature")) {
+ else if (STREQ(gpu_grid->name, "flame") || STREQ(gpu_grid->name, "temperature")) {
DRW_shgroup_uniform_texture_ref(
- grp, tex->shadername, mds->tex_flame ? &mds->tex_flame : &e_data.dummy_flame);
+ grp, gpu_grid->sampler_name, mds->tex_flame ? &mds->tex_flame : &e_data.dummy_flame);
}
else {
- DRW_shgroup_uniform_texture_ref(grp, tex->shadername, &e_data.dummy_density);
+ DRW_shgroup_uniform_texture_ref(grp, gpu_grid->sampler_name, &e_data.dummy_density);
}
}
@@ -540,11 +537,8 @@ void EEVEE_volumes_cache_object_add(EEVEE_ViewLayerData *sldata,
DRW_shgroup_uniform_vec2_copy(grp, "volumeTemperature", volume_temperature);
}
else {
- for (GPUMaterialTexture *tex = textures.first; tex; tex = tex->next) {
- if (tex->volume_grid) {
- DRW_shgroup_uniform_texture(grp, tex->shadername, e_data.dummy_density);
- continue;
- }
+ for (GPUMaterialVolumeGrid *gpu_grid = gpu_grids.first; gpu_grid; gpu_grid = gpu_grid->next) {
+ DRW_shgroup_uniform_texture(grp, gpu_grid->sampler_name, e_data.dummy_density);
}
}
diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c
index c8c48e582a7..cc1fe815b6b 100644
--- a/source/blender/draw/intern/draw_manager_data.c
+++ b/source/blender/draw/intern/draw_manager_data.c
@@ -1203,6 +1203,19 @@ static DRWShadingGroup *drw_shgroup_material_create_ex(GPUPass *gpupass, DRWPass
return grp;
}
+static void drw_shgroup_material_texture(DRWShadingGroup *grp,
+ GPUMaterialTexture *tex,
+ const char *name,
+ int textarget)
+{
+ GPUTexture *gputex = GPU_texture_from_blender(tex->ima, tex->iuser, NULL, textarget);
+ DRW_shgroup_uniform_texture(grp, name, gputex);
+
+ GPUTexture **gputex_ref = BLI_memblock_alloc(DST.vmempool->images);
+ *gputex_ref = gputex;
+ GPU_texture_ref(gputex);
+}
+
static DRWShadingGroup *drw_shgroup_material_inputs(DRWShadingGroup *grp,
struct GPUMaterial *material)
{
@@ -1210,36 +1223,20 @@ static DRWShadingGroup *drw_shgroup_material_inputs(DRWShadingGroup *grp,
/* Bind all textures needed by the material. */
for (GPUMaterialTexture *tex = textures.first; tex; tex = tex->next) {
- GPUTexture *gputex;
-
if (tex->ima) {
/* Image */
- GPUTexture **gputex_ref = BLI_memblock_alloc(DST.vmempool->images);
-
- int textarget;
- if (tex->type == GPU_TEX2D_ARRAY) {
- textarget = GL_TEXTURE_2D_ARRAY;
- }
- else if (tex->type == GPU_TEX1D_ARRAY) {
- textarget = GL_TEXTURE_1D_ARRAY;
+ if (tex->tiled_mapping_name[0]) {
+ drw_shgroup_material_texture(grp, tex, tex->sampler_name, GL_TEXTURE_2D_ARRAY);
+ drw_shgroup_material_texture(grp, tex, tex->tiled_mapping_name, GL_TEXTURE_1D_ARRAY);
}
else {
- textarget = GL_TEXTURE_2D;
+ drw_shgroup_material_texture(grp, tex, tex->sampler_name, GL_TEXTURE_2D);
}
- *gputex_ref = gputex = GPU_texture_from_blender(tex->ima, tex->iuser, NULL, textarget);
-
- GPU_texture_ref(gputex);
}
else if (tex->colorband) {
/* Color Ramp */
- gputex = *tex->colorband;
+ DRW_shgroup_uniform_texture(grp, tex->sampler_name, *tex->colorband);
}
- else {
- /* Volume grid handled in Eevee volume rendering. */
- continue;
- }
-
- DRW_shgroup_uniform_texture(grp, tex->shadername, gputex);
}
GPUUniformBuffer *ubo = GPU_material_uniform_buffer_get(material);
diff --git a/source/blender/gpu/GPU_material.h b/source/blender/gpu/GPU_material.h
index 2586f98d0ed..8baa2a08f07 100644
--- a/source/blender/gpu/GPU_material.h
+++ b/source/blender/gpu/GPU_material.h
@@ -66,6 +66,7 @@ typedef enum eGPUType {
GPU_VEC4 = 4,
GPU_MAT3 = 9,
GPU_MAT4 = 16,
+ GPU_MAX_CONSTANT_DATA = GPU_MAT4,
/* Values not in GPU_DATATYPE_STR */
GPU_TEX1D_ARRAY = 1001,
@@ -136,13 +137,14 @@ typedef enum eGPUMaterialStatus {
GPU_MAT_SUCCESS,
} eGPUMaterialStatus;
-GPUNodeLink *GPU_attribute(CustomDataType type, const char *name);
-GPUNodeLink *GPU_constant(float *num);
-GPUNodeLink *GPU_uniform(float *num);
-GPUNodeLink *GPU_image(struct Image *ima, struct ImageUser *iuser);
-GPUNodeLink *GPU_image_tilemap(struct Image *ima, struct ImageUser *iuser);
+GPUNodeLink *GPU_constant(const float *num);
+GPUNodeLink *GPU_uniform(const float *num);
+GPUNodeLink *GPU_attribute(GPUMaterial *mat, CustomDataType type, const char *name);
+GPUNodeLink *GPU_image(GPUMaterial *mat, struct Image *ima, struct ImageUser *iuser);
+GPUNodeLink *GPU_image_tiled(GPUMaterial *mat, struct Image *ima, struct ImageUser *iuser);
+GPUNodeLink *GPU_image_tiled_mapping(GPUMaterial *mat, struct Image *ima, struct ImageUser *iuser);
GPUNodeLink *GPU_color_band(GPUMaterial *mat, int size, float *pixels, float *layer);
-GPUNodeLink *GPU_volume_attribute(GPUMaterial *mat, const char *name);
+GPUNodeLink *GPU_volume_grid(GPUMaterial *mat, const char *name);
GPUNodeLink *GPU_builtin(eGPUBuiltin builtin);
bool GPU_link(GPUMaterial *mat, const char *name, ...);
@@ -190,7 +192,6 @@ void GPU_materials_free(struct Main *bmain);
struct Scene *GPU_material_scene(GPUMaterial *material);
struct GPUPass *GPU_material_get_pass(GPUMaterial *material);
-struct ListBase *GPU_material_get_inputs(GPUMaterial *material);
struct Material *GPU_material_get_material(GPUMaterial *material);
eGPUMaterialStatus GPU_material_status(GPUMaterial *mat);
@@ -216,22 +217,31 @@ typedef struct GPUMaterialAttribute {
struct GPUMaterialAttribute *next, *prev;
int type; /* CustomDataType */
char name[64]; /* MAX_CUSTOMDATA_LAYER_NAME */
+ eGPUType gputype;
int id;
+ int users;
} GPUMaterialAttribute;
typedef struct GPUMaterialTexture {
struct GPUMaterialTexture *next, *prev;
- eGPUType type;
struct Image *ima;
struct ImageUser *iuser;
struct GPUTexture **colorband;
- char *volume_grid;
- char shadername[32]; /* Name of sampler in GLSL. */
- int i
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list