diff options
author | Brecht Van Lommel <brecht> | 2020-03-11 16:58:19 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2020-03-11 16:59:05 +0300 |
commit | b9f6d033beecd75398be14419d37d8aab0609812 (patch) | |
tree | b2385a92388dfb1d17a99a72dd442bc5bc38de85 /source/blender/draw | |
parent | e1e772a80243f3c279fcd076c8311301e8885d41 (diff) |
Eevee: internal support for arbitrary number of volume grids
This has no user visible impact yet since smoke volumes only support a fixed
set of attributes, but will become important with the new volume object.
For GPU shader compilation, volume grids are now handled separately from
image textures. They are somewhere between a vertex attribute and an image
texture, basically an attribute that is stored as a texture.
Differential Revision: https://developer.blender.org/D6952
Diffstat (limited to 'source/blender/draw')
-rw-r--r-- | source/blender/draw/engines/eevee/eevee_materials.c | 11 | ||||
-rw-r--r-- | source/blender/draw/engines/eevee/eevee_volumes.c | 46 | ||||
-rw-r--r-- | source/blender/draw/intern/DRW_render.h | 10 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager_shader.c | 12 |
4 files changed, 53 insertions, 26 deletions
diff --git a/source/blender/draw/engines/eevee/eevee_materials.c b/source/blender/draw/engines/eevee/eevee_materials.c index a37c063adf6..05127585e6c 100644 --- a/source/blender/draw/engines/eevee/eevee_materials.c +++ b/source/blender/draw/engines/eevee/eevee_materials.c @@ -776,6 +776,7 @@ struct GPUMaterial *EEVEE_material_world_lightprobe_get(struct Scene *scene, Wor wo, engine, options, + false, e_data.vert_background_shader_str, NULL, e_data.frag_shader_lib, @@ -796,6 +797,7 @@ struct GPUMaterial *EEVEE_material_world_background_get(struct Scene *scene, Wor wo, engine, options, + false, e_data.vert_background_shader_str, NULL, e_data.frag_shader_lib, @@ -819,6 +821,7 @@ struct GPUMaterial *EEVEE_material_world_volume_get(struct Scene *scene, World * wo, engine, options, + true, e_data.vert_volume_shader_str, e_data.geom_volume_shader_str, e_data.volume_shader_lib, @@ -853,6 +856,7 @@ struct GPUMaterial *EEVEE_material_mesh_get(struct Scene *scene, ma, engine, options, + false, e_data.vert_shader_str, NULL, e_data.frag_shader_lib, @@ -880,6 +884,7 @@ struct GPUMaterial *EEVEE_material_mesh_volume_get(struct Scene *scene, Material ma, engine, options, + true, e_data.vert_volume_shader_str, e_data.geom_volume_shader_str, e_data.volume_shader_lib, @@ -916,6 +921,7 @@ struct GPUMaterial *EEVEE_material_mesh_depth_get(struct Scene *scene, ma, engine, options, + false, (is_shadow) ? e_data.vert_shadow_shader_str : e_data.vert_shader_str, NULL, @@ -945,6 +951,7 @@ struct GPUMaterial *EEVEE_material_hair_get(struct Scene *scene, Material *ma) ma, engine, options, + false, e_data.vert_shader_str, NULL, e_data.frag_shader_lib, @@ -1919,7 +1926,7 @@ void EEVEE_materials_cache_populate(EEVEE_Data *vedata, * to know if the material has a "volume nodetree". */ bool use_volume_material = (gpumat_array[0] && - GPU_material_use_domain_volume(gpumat_array[0])); + GPU_material_has_volume_output(gpumat_array[0])); if ((ob->dt >= OB_SOLID) || DRW_state_is_image_render()) { /* Get per-material split surface */ @@ -1968,7 +1975,7 @@ void EEVEE_materials_cache_populate(EEVEE_Data *vedata, /* Do not render surface if we are rendering a volume object * and do not have a surface closure. */ if (use_volume_material && - (gpumat_array[i] && !GPU_material_use_domain_surface(gpumat_array[i]))) { + (gpumat_array[i] && !GPU_material_has_surface_output(gpumat_array[i]))) { continue; } diff --git a/source/blender/draw/engines/eevee/eevee_volumes.c b/source/blender/draw/engines/eevee/eevee_volumes.c index dcb8b04fbcd..efe2ef5fc17 100644 --- a/source/blender/draw/engines/eevee/eevee_volumes.c +++ b/source/blender/draw/engines/eevee/eevee_volumes.c @@ -351,7 +351,7 @@ void EEVEE_volumes_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata) !LOOK_DEV_STUDIO_LIGHT_ENABLED(draw_ctx->v3d)) { struct GPUMaterial *mat = EEVEE_material_world_volume_get(scene, wo); - if (GPU_material_use_domain_volume(mat)) { + if (GPU_material_has_volume_output(mat)) { grp = DRW_shgroup_material_create(mat, psl->volumetric_world_ps); } @@ -367,10 +367,11 @@ void EEVEE_volumes_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata) grp, "renderpass_block", EEVEE_material_default_render_pass_ubo_get(sldata)); /* Fix principle volumetric not working with world materials. */ - DRW_shgroup_uniform_texture(grp, "sampdensity", e_data.dummy_density); - DRW_shgroup_uniform_texture(grp, "sampcolor", e_data.dummy_density); - DRW_shgroup_uniform_texture(grp, "sampflame", e_data.dummy_flame); - DRW_shgroup_uniform_vec2_copy(grp, "unftemperature", (float[2]){0.0f, 1.0f}); + 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]); @@ -446,6 +447,7 @@ void EEVEE_volumes_cache_object_add(EEVEE_ViewLayerData *sldata, DRW_shgroup_uniform_vec3(grp, "volumeOrcoLoc", texcoloc, 1); DRW_shgroup_uniform_vec3(grp, "volumeOrcoSize", texcosize, 1); + ListBase gpu_grids = GPU_material_volume_grids(mat); /* Smoke Simulation */ if (((ob->base_flag & BASE_FROM_DUPLI) == 0) && (md = modifiers_findByType(ob, eModifierType_Fluid)) && @@ -477,12 +479,25 @@ void EEVEE_volumes_cache_object_add(EEVEE_ViewLayerData *sldata, BLI_addtail(&e_data.smoke_domains, BLI_genericNodeN(mmd)); } - DRW_shgroup_uniform_texture_ref( - grp, "sampdensity", mds->tex_density ? &mds->tex_density : &e_data.dummy_density); - DRW_shgroup_uniform_texture_ref( - grp, "sampcolor", mds->tex_color ? &mds->tex_color : &e_data.dummy_density); - DRW_shgroup_uniform_texture_ref( - grp, "sampflame", mds->tex_flame ? &mds->tex_flame : &e_data.dummy_flame); + 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(gpu_grid->name, "color")) { + DRW_shgroup_uniform_texture_ref( + grp, gpu_grid->sampler_name, mds->tex_color ? &mds->tex_color : &e_data.dummy_density); + } + else if (STREQ(gpu_grid->name, "flame") || STREQ(gpu_grid->name, "temperature")) { + DRW_shgroup_uniform_texture_ref( + grp, gpu_grid->sampler_name, mds->tex_flame ? &mds->tex_flame : &e_data.dummy_flame); + } + else { + DRW_shgroup_uniform_texture_ref(grp, gpu_grid->sampler_name, &e_data.dummy_density); + } + } /* Constant Volume color. */ bool use_constant_color = ((mds->active_fields & FLUID_DOMAIN_ACTIVE_COLORS) == 0 && @@ -492,14 +507,13 @@ void EEVEE_volumes_cache_object_add(EEVEE_ViewLayerData *sldata, grp, "volumeColor", (use_constant_color) ? mds->active_color : white, 1); /* Output is such that 0..1 maps to 0..1000K */ - DRW_shgroup_uniform_vec2(grp, "unftemperature", &mds->flame_ignition, 1); + DRW_shgroup_uniform_vec2(grp, "volumeTemperature", &mds->flame_ignition, 1); } else { - DRW_shgroup_uniform_texture(grp, "sampdensity", e_data.dummy_density); - DRW_shgroup_uniform_texture(grp, "sampcolor", e_data.dummy_density); - DRW_shgroup_uniform_texture(grp, "sampflame", e_data.dummy_flame); + 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_uniform_vec3(grp, "volumeColor", white, 1); - DRW_shgroup_uniform_vec2(grp, "unftemperature", (float[2]){0.0f, 1.0f}, 1); } /* TODO Reduce to number of slices intersecting. */ diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h index 904510b1357..c3e94fda4fc 100644 --- a/source/blender/draw/intern/DRW_render.h +++ b/source/blender/draw/intern/DRW_render.h @@ -211,16 +211,17 @@ struct GPUShader *DRW_shader_create_fullscreen(const char *frag, const char *def struct GPUShader *DRW_shader_create_3d_depth_only(eGPUShaderConfig slot); struct GPUMaterial *DRW_shader_find_from_world(struct World *wo, const void *engine_type, - int options, + const int options, bool deferred); struct GPUMaterial *DRW_shader_find_from_material(struct Material *ma, const void *engine_type, - int options, + const int options, bool deferred); struct GPUMaterial *DRW_shader_create_from_world(struct Scene *scene, struct World *wo, const void *engine_type, - int options, + const int options, + const bool is_volume_shader, const char *vert, const char *geom, const char *frag_lib, @@ -229,7 +230,8 @@ struct GPUMaterial *DRW_shader_create_from_world(struct Scene *scene, struct GPUMaterial *DRW_shader_create_from_material(struct Scene *scene, struct Material *ma, const void *engine_type, - int options, + const int options, + const bool is_volume_shader, const char *vert, const char *geom, const char *frag_lib, diff --git a/source/blender/draw/intern/draw_manager_shader.c b/source/blender/draw/intern/draw_manager_shader.c index 9c34cdbac3b..ed05fb85dc9 100644 --- a/source/blender/draw/intern/draw_manager_shader.c +++ b/source/blender/draw/intern/draw_manager_shader.c @@ -356,7 +356,7 @@ GPUShader *DRW_shader_create_3d_depth_only(eGPUShaderConfig sh_cfg) GPUMaterial *DRW_shader_find_from_world(World *wo, const void *engine_type, - int options, + const int options, bool deferred) { GPUMaterial *mat = GPU_material_from_nodetree_find(&wo->gpumaterial, engine_type, options); @@ -372,7 +372,7 @@ GPUMaterial *DRW_shader_find_from_world(World *wo, GPUMaterial *DRW_shader_find_from_material(Material *ma, const void *engine_type, - int options, + const int options, bool deferred) { GPUMaterial *mat = GPU_material_from_nodetree_find(&ma->gpumaterial, engine_type, options); @@ -389,7 +389,8 @@ GPUMaterial *DRW_shader_find_from_material(Material *ma, GPUMaterial *DRW_shader_create_from_world(struct Scene *scene, World *wo, const void *engine_type, - int options, + const int options, + const bool is_volume_shader, const char *vert, const char *geom, const char *frag_lib, @@ -409,6 +410,7 @@ GPUMaterial *DRW_shader_create_from_world(struct Scene *scene, &wo->gpumaterial, engine_type, options, + is_volume_shader, vert, geom, frag_lib, @@ -426,7 +428,8 @@ GPUMaterial *DRW_shader_create_from_world(struct Scene *scene, GPUMaterial *DRW_shader_create_from_material(struct Scene *scene, Material *ma, const void *engine_type, - int options, + const int options, + const bool is_volume_shader, const char *vert, const char *geom, const char *frag_lib, @@ -446,6 +449,7 @@ GPUMaterial *DRW_shader_create_from_material(struct Scene *scene, &ma->gpumaterial, engine_type, options, + is_volume_shader, vert, geom, frag_lib, |