Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/eevee_next/eevee_film.cc
| Show First 20 Lines • Show All 156 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Film | /** \name Film | ||||
| * \{ */ | * \{ */ | ||||
| static eViewLayerEEVEEPassType enabled_passes(const ViewLayer *view_layer) | |||||
| { | |||||
| eViewLayerEEVEEPassType result = eViewLayerEEVEEPassType(view_layer->eevee.render_passes); | |||||
| #define ENABLE_FROM_LEGACY(name_legacy, name_eevee) \ | |||||
| SET_FLAG_FROM_TEST(result, \ | |||||
| (view_layer->passflag & SCE_PASS_##name_legacy) != 0, \ | |||||
| EEVEE_RENDER_PASS_##name_eevee); | |||||
| ENABLE_FROM_LEGACY(COMBINED, COMBINED) | |||||
| ENABLE_FROM_LEGACY(Z, Z) | |||||
| ENABLE_FROM_LEGACY(MIST, MIST) | |||||
| ENABLE_FROM_LEGACY(NORMAL, NORMAL) | |||||
| ENABLE_FROM_LEGACY(SHADOW, SHADOW) | |||||
| ENABLE_FROM_LEGACY(AO, AO) | |||||
| ENABLE_FROM_LEGACY(EMIT, EMIT) | |||||
| ENABLE_FROM_LEGACY(ENVIRONMENT, ENVIRONMENT) | |||||
| ENABLE_FROM_LEGACY(DIFFUSE_COLOR, DIFFUSE_COLOR) | |||||
| ENABLE_FROM_LEGACY(GLOSSY_COLOR, SPECULAR_COLOR) | |||||
| ENABLE_FROM_LEGACY(DIFFUSE_DIRECT, DIFFUSE_LIGHT) | |||||
| ENABLE_FROM_LEGACY(GLOSSY_DIRECT, SPECULAR_LIGHT) | |||||
| ENABLE_FROM_LEGACY(ENVIRONMENT, ENVIRONMENT) | |||||
| ENABLE_FROM_LEGACY(VECTOR, VECTOR) | |||||
| #undef ENABLE_FROM_LEGACY | |||||
| SET_FLAG_FROM_TEST(result, | |||||
| view_layer->cryptomatte_flag & VIEW_LAYER_CRYPTOMATTE_OBJECT, | |||||
| EEVEE_RENDER_PASS_CRYPTOMATTE_OBJECT); | |||||
| SET_FLAG_FROM_TEST(result, | |||||
| view_layer->cryptomatte_flag & VIEW_LAYER_CRYPTOMATTE_ASSET, | |||||
| EEVEE_RENDER_PASS_CRYPTOMATTE_ASSET); | |||||
| SET_FLAG_FROM_TEST(result, | |||||
| view_layer->cryptomatte_flag & VIEW_LAYER_CRYPTOMATTE_MATERIAL, | |||||
| EEVEE_RENDER_PASS_CRYPTOMATTE_MATERIAL); | |||||
| return result; | |||||
| } | |||||
| void Film::init(const int2 &extent, const rcti *output_rect) | void Film::init(const int2 &extent, const rcti *output_rect) | ||||
| { | { | ||||
| Sampling &sampling = inst_.sampling; | Sampling &sampling = inst_.sampling; | ||||
| Scene &scene = *inst_.scene; | Scene &scene = *inst_.scene; | ||||
| SceneEEVEE &scene_eevee = scene.eevee; | SceneEEVEE &scene_eevee = scene.eevee; | ||||
| init_aovs(); | init_aovs(); | ||||
| { | { | ||||
| /* Enable passes that need to be rendered. */ | /* Enable passes that need to be rendered. */ | ||||
| eViewLayerEEVEEPassType render_passes = eViewLayerEEVEEPassType(0); | eViewLayerEEVEEPassType render_passes = eViewLayerEEVEEPassType(0); | ||||
| if (inst_.is_viewport()) { | if (inst_.is_viewport()) { | ||||
| /* Viewport Case. */ | /* Viewport Case. */ | ||||
| render_passes = eViewLayerEEVEEPassType(inst_.v3d->shading.render_pass); | render_passes = eViewLayerEEVEEPassType(inst_.v3d->shading.render_pass); | ||||
| if (inst_.overlays_enabled() || inst_.gpencil_engine_enabled) { | if (inst_.overlays_enabled() || inst_.gpencil_engine_enabled) { | ||||
| /* Overlays and Grease Pencil needs the depth for correct compositing. | /* Overlays and Grease Pencil needs the depth for correct compositing. | ||||
| * Using the render pass ensure we store the center depth. */ | * Using the render pass ensure we store the center depth. */ | ||||
| render_passes |= EEVEE_RENDER_PASS_Z; | render_passes |= EEVEE_RENDER_PASS_Z; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* Render Case. */ | /* Render Case. */ | ||||
| render_passes = eViewLayerEEVEEPassType(inst_.view_layer->eevee.render_passes); | render_passes = enabled_passes(inst_.view_layer); | ||||
| #define ENABLE_FROM_LEGACY(name_legacy, name_eevee) \ | |||||
| SET_FLAG_FROM_TEST(render_passes, \ | |||||
| (inst_.view_layer->passflag & SCE_PASS_##name_legacy) != 0, \ | |||||
| EEVEE_RENDER_PASS_##name_eevee); | |||||
| ENABLE_FROM_LEGACY(COMBINED, COMBINED) | |||||
| ENABLE_FROM_LEGACY(Z, Z) | |||||
| ENABLE_FROM_LEGACY(MIST, MIST) | |||||
| ENABLE_FROM_LEGACY(NORMAL, NORMAL) | |||||
| ENABLE_FROM_LEGACY(SHADOW, SHADOW) | |||||
| ENABLE_FROM_LEGACY(AO, AO) | |||||
| ENABLE_FROM_LEGACY(EMIT, EMIT) | |||||
| ENABLE_FROM_LEGACY(ENVIRONMENT, ENVIRONMENT) | |||||
| ENABLE_FROM_LEGACY(DIFFUSE_COLOR, DIFFUSE_COLOR) | |||||
| ENABLE_FROM_LEGACY(GLOSSY_COLOR, SPECULAR_COLOR) | |||||
| ENABLE_FROM_LEGACY(DIFFUSE_DIRECT, DIFFUSE_LIGHT) | |||||
| ENABLE_FROM_LEGACY(GLOSSY_DIRECT, SPECULAR_LIGHT) | |||||
| ENABLE_FROM_LEGACY(ENVIRONMENT, ENVIRONMENT) | |||||
| ENABLE_FROM_LEGACY(VECTOR, VECTOR) | |||||
| #undef ENABLE_FROM_LEGACY | |||||
| } | } | ||||
| /* Filter obsolete passes. */ | /* Filter obsolete passes. */ | ||||
| render_passes &= ~(EEVEE_RENDER_PASS_UNUSED_8 | EEVEE_RENDER_PASS_BLOOM); | render_passes &= ~(EEVEE_RENDER_PASS_UNUSED_8 | EEVEE_RENDER_PASS_BLOOM); | ||||
| if (scene_eevee.flag & SCE_EEVEE_MOTION_BLUR_ENABLED) { | if (scene_eevee.flag & SCE_EEVEE_MOTION_BLUR_ENABLED) { | ||||
| /* Disable motion vector pass if motion blur is enabled. */ | /* Disable motion vector pass if motion blur is enabled. */ | ||||
| render_passes &= ~EEVEE_RENDER_PASS_VECTOR; | render_passes &= ~EEVEE_RENDER_PASS_VECTOR; | ||||
| Show All 16 Lines | init_aovs(); | ||||
| data.offset = int2(output_rect->xmin, output_rect->ymin); | data.offset = int2(output_rect->xmin, output_rect->ymin); | ||||
| data.extent_inv = 1.0f / float2(data.extent); | data.extent_inv = 1.0f / float2(data.extent); | ||||
| /* Disable filtering if sample count is 1. */ | /* Disable filtering if sample count is 1. */ | ||||
| data.filter_radius = (sampling.sample_count() == 1) ? 0.0f : | data.filter_radius = (sampling.sample_count() == 1) ? 0.0f : | ||||
| clamp_f(scene.r.gauss, 0.0f, 100.0f); | clamp_f(scene.r.gauss, 0.0f, 100.0f); | ||||
| /* TODO(fclem): parameter hidden in experimental. | /* TODO(fclem): parameter hidden in experimental. | ||||
| * We need to figure out LOD bias first in order to preserve texture crispiness. */ | * We need to figure out LOD bias first in order to preserve texture crispiness. */ | ||||
| data.scaling_factor = 1; | data.scaling_factor = 1; | ||||
| data.cryptomatte_samples_len = inst_.view_layer->cryptomatte_levels; | |||||
| data.background_opacity = (scene.r.alphamode == R_ALPHAPREMUL) ? 0.0f : 1.0f; | data.background_opacity = (scene.r.alphamode == R_ALPHAPREMUL) ? 0.0f : 1.0f; | ||||
| if (inst_.is_viewport() && false /* TODO(fclem): StudioLight */) { | if (inst_.is_viewport() && false /* TODO(fclem): StudioLight */) { | ||||
| data.background_opacity = inst_.v3d->shading.studiolight_background; | data.background_opacity = inst_.v3d->shading.studiolight_background; | ||||
| } | } | ||||
| FilmData &data_prev_ = data_; | FilmData &data_prev_ = data_; | ||||
| if (assign_if_different(data_prev_, data)) { | if (assign_if_different(data_prev_, data)) { | ||||
| Show All 16 Lines | init_aovs(); | ||||
| data_.has_data = (enabled_passes_ & data_passes) != 0; | data_.has_data = (enabled_passes_ & data_passes) != 0; | ||||
| data_.any_render_pass_1 = (enabled_passes_ & color_passes_1) != 0; | data_.any_render_pass_1 = (enabled_passes_ & color_passes_1) != 0; | ||||
| data_.any_render_pass_2 = (enabled_passes_ & color_passes_2) != 0; | data_.any_render_pass_2 = (enabled_passes_ & color_passes_2) != 0; | ||||
| } | } | ||||
| { | { | ||||
| /* Set pass offsets. */ | /* Set pass offsets. */ | ||||
| data_.display_id = aovs_info.display_id; | data_.display_id = aovs_info.display_id; | ||||
| data_.display_is_value = aovs_info.display_is_value; | data_.display_storage_type = aovs_info.display_is_value ? PASS_STORAGE_VALUE : | ||||
| PASS_STORAGE_COLOR; | |||||
| /* Combined is in a separate buffer. */ | /* Combined is in a separate buffer. */ | ||||
| data_.combined_id = (enabled_passes_ & EEVEE_RENDER_PASS_COMBINED) ? 0 : -1; | data_.combined_id = (enabled_passes_ & EEVEE_RENDER_PASS_COMBINED) ? 0 : -1; | ||||
| /* Depth is in a separate buffer. */ | /* Depth is in a separate buffer. */ | ||||
| data_.depth_id = (enabled_passes_ & EEVEE_RENDER_PASS_Z) ? 0 : -1; | data_.depth_id = (enabled_passes_ & EEVEE_RENDER_PASS_Z) ? 0 : -1; | ||||
| data_.color_len = 0; | data_.color_len = 0; | ||||
| data_.value_len = 0; | data_.value_len = 0; | ||||
| auto pass_index_get = [&](eViewLayerEEVEEPassType pass_type) { | auto pass_index_get = [&](eViewLayerEEVEEPassType pass_type) { | ||||
| bool is_value = pass_is_value(pass_type); | ePassStorageType storage_type = pass_storage_type(pass_type); | ||||
| int index = (enabled_passes_ & pass_type) ? | int index = (enabled_passes_ & pass_type) ? | ||||
| (is_value ? data_.value_len : data_.color_len)++ : | (storage_type == PASS_STORAGE_VALUE ? data_.value_len : data_.color_len)++ : | ||||
| -1; | -1; | ||||
| if (inst_.is_viewport() && inst_.v3d->shading.render_pass == pass_type) { | if (inst_.is_viewport() && inst_.v3d->shading.render_pass == pass_type) { | ||||
| data_.display_id = index; | data_.display_id = index; | ||||
| data_.display_is_value = is_value; | data_.display_storage_type = storage_type; | ||||
| } | } | ||||
| return index; | return index; | ||||
| }; | }; | ||||
| data_.mist_id = pass_index_get(EEVEE_RENDER_PASS_MIST); | data_.mist_id = pass_index_get(EEVEE_RENDER_PASS_MIST); | ||||
| data_.normal_id = pass_index_get(EEVEE_RENDER_PASS_NORMAL); | data_.normal_id = pass_index_get(EEVEE_RENDER_PASS_NORMAL); | ||||
| data_.vector_id = pass_index_get(EEVEE_RENDER_PASS_VECTOR); | data_.vector_id = pass_index_get(EEVEE_RENDER_PASS_VECTOR); | ||||
| data_.diffuse_light_id = pass_index_get(EEVEE_RENDER_PASS_DIFFUSE_LIGHT); | data_.diffuse_light_id = pass_index_get(EEVEE_RENDER_PASS_DIFFUSE_LIGHT); | ||||
| Show All 9 Lines | init_aovs(); | ||||
| data_.aov_color_id = data_.color_len; | data_.aov_color_id = data_.color_len; | ||||
| data_.aov_value_id = data_.value_len; | data_.aov_value_id = data_.value_len; | ||||
| data_.aov_color_len = aovs_info.color_len; | data_.aov_color_len = aovs_info.color_len; | ||||
| data_.aov_value_len = aovs_info.value_len; | data_.aov_value_len = aovs_info.value_len; | ||||
| data_.color_len += data_.aov_color_len; | data_.color_len += data_.aov_color_len; | ||||
| data_.value_len += data_.aov_value_len; | data_.value_len += data_.aov_value_len; | ||||
| int cryptomatte_id = 0; | |||||
| auto cryptomatte_index_get = [&](eViewLayerEEVEEPassType pass_type) { | |||||
| int index = -1; | |||||
| if (enabled_passes_ & pass_type) { | |||||
| index = cryptomatte_id; | |||||
| cryptomatte_id += data_.cryptomatte_samples_len / 2; | |||||
| if (inst_.is_viewport() && inst_.v3d->shading.render_pass == pass_type) { | |||||
| data_.display_id = index; | |||||
| data_.display_storage_type = PASS_STORAGE_CRYPTOMATTE; | |||||
| } | |||||
| } | |||||
| return index; | |||||
| }; | |||||
| data_.cryptomatte_object_id = cryptomatte_index_get(EEVEE_RENDER_PASS_CRYPTOMATTE_OBJECT); | |||||
| data_.cryptomatte_asset_id = cryptomatte_index_get(EEVEE_RENDER_PASS_CRYPTOMATTE_ASSET); | |||||
| data_.cryptomatte_material_id = cryptomatte_index_get(EEVEE_RENDER_PASS_CRYPTOMATTE_MATERIAL); | |||||
| } | } | ||||
| { | { | ||||
| /* TODO(@fclem): Over-scans. */ | /* TODO(@fclem): Over-scans. */ | ||||
| data_.render_extent = math::divide_ceil(extent, int2(data_.scaling_factor)); | data_.render_extent = math::divide_ceil(extent, int2(data_.scaling_factor)); | ||||
| int2 weight_extent = inst_.camera.is_panoramic() ? data_.extent : int2(data_.scaling_factor); | int2 weight_extent = inst_.camera.is_panoramic() ? data_.extent : int2(data_.scaling_factor); | ||||
| eGPUTextureFormat color_format = GPU_RGBA16F; | eGPUTextureFormat color_format = GPU_RGBA16F; | ||||
| eGPUTextureFormat float_format = GPU_R16F; | eGPUTextureFormat float_format = GPU_R16F; | ||||
| eGPUTextureFormat weight_format = GPU_R32F; | eGPUTextureFormat weight_format = GPU_R32F; | ||||
| eGPUTextureFormat depth_format = GPU_R32F; | eGPUTextureFormat depth_format = GPU_R32F; | ||||
| eGPUTextureFormat cryptomatte_format = GPU_RGBA32F; | |||||
| int reset = 0; | int reset = 0; | ||||
| reset += depth_tx_.ensure_2d(depth_format, data_.extent); | reset += depth_tx_.ensure_2d(depth_format, data_.extent); | ||||
| reset += combined_tx_.current().ensure_2d(color_format, data_.extent); | reset += combined_tx_.current().ensure_2d(color_format, data_.extent); | ||||
| reset += combined_tx_.next().ensure_2d(color_format, data_.extent); | reset += combined_tx_.next().ensure_2d(color_format, data_.extent); | ||||
| /* Two layers, one for nearest sample weight and one for weight accumulation. */ | /* Two layers, one for nearest sample weight and one for weight accumulation. */ | ||||
| reset += weight_tx_.current().ensure_2d_array(weight_format, weight_extent, 2); | reset += weight_tx_.current().ensure_2d_array(weight_format, weight_extent, 2); | ||||
| reset += weight_tx_.next().ensure_2d_array(weight_format, weight_extent, 2); | reset += weight_tx_.next().ensure_2d_array(weight_format, weight_extent, 2); | ||||
| reset += color_accum_tx_.ensure_2d_array(color_format, | reset += color_accum_tx_.ensure_2d_array(color_format, | ||||
| (data_.color_len > 0) ? data_.extent : int2(1), | (data_.color_len > 0) ? data_.extent : int2(1), | ||||
| (data_.color_len > 0) ? data_.color_len : 1); | (data_.color_len > 0) ? data_.color_len : 1); | ||||
| reset += value_accum_tx_.ensure_2d_array(float_format, | reset += value_accum_tx_.ensure_2d_array(float_format, | ||||
| (data_.value_len > 0) ? data_.extent : int2(1), | (data_.value_len > 0) ? data_.extent : int2(1), | ||||
| (data_.value_len > 0) ? data_.value_len : 1); | (data_.value_len > 0) ? data_.value_len : 1); | ||||
| /* Divided by two as two cryptomatte samples fit in pixel (RG, BA). */ | |||||
| int cryptomatte_array_len = cryptomatte_layer_len_get() * data_.cryptomatte_samples_len / 2; | |||||
| reset += cryptomatte_tx_.ensure_2d_array(cryptomatte_format, | |||||
| (cryptomatte_array_len > 0) ? data_.extent : int2(1), | |||||
| (cryptomatte_array_len > 0) ? cryptomatte_array_len : | |||||
| 1); | |||||
| if (reset > 0) { | if (reset > 0) { | ||||
| sampling.reset(); | sampling.reset(); | ||||
| data_.use_history = 0; | data_.use_history = 0; | ||||
| data_.use_reprojection = 0; | data_.use_reprojection = 0; | ||||
| /* Avoid NaN in uninitialized texture memory making history blending dangerous. */ | /* Avoid NaN in uninitialized texture memory making history blending dangerous. */ | ||||
| color_accum_tx_.clear(float4(0.0f)); | color_accum_tx_.clear(float4(0.0f)); | ||||
| value_accum_tx_.clear(float4(0.0f)); | value_accum_tx_.clear(float4(0.0f)); | ||||
| combined_tx_.current().clear(float4(0.0f)); | combined_tx_.current().clear(float4(0.0f)); | ||||
| weight_tx_.current().clear(float4(0.0f)); | weight_tx_.current().clear(float4(0.0f)); | ||||
| depth_tx_.clear(float4(0.0f)); | depth_tx_.clear(float4(0.0f)); | ||||
| cryptomatte_tx_.clear(float4(0.0f)); | |||||
| } | } | ||||
| } | } | ||||
| force_disable_reprojection_ = (scene_eevee.flag & SCE_EEVEE_TAA_REPROJECTION) == 0; | force_disable_reprojection_ = (scene_eevee.flag & SCE_EEVEE_TAA_REPROJECTION) == 0; | ||||
| } | } | ||||
| void Film::sync() | void Film::sync() | ||||
| { | { | ||||
| Show All 29 Lines | void Film::sync() | ||||
| accumulate_ps_.bind_texture("specular_color_tx", &rbuffers.specular_color_tx); | accumulate_ps_.bind_texture("specular_color_tx", &rbuffers.specular_color_tx); | ||||
| accumulate_ps_.bind_texture("volume_light_tx", &rbuffers.volume_light_tx); | accumulate_ps_.bind_texture("volume_light_tx", &rbuffers.volume_light_tx); | ||||
| accumulate_ps_.bind_texture("emission_tx", &rbuffers.emission_tx); | accumulate_ps_.bind_texture("emission_tx", &rbuffers.emission_tx); | ||||
| accumulate_ps_.bind_texture("environment_tx", &rbuffers.environment_tx); | accumulate_ps_.bind_texture("environment_tx", &rbuffers.environment_tx); | ||||
| accumulate_ps_.bind_texture("shadow_tx", &rbuffers.shadow_tx); | accumulate_ps_.bind_texture("shadow_tx", &rbuffers.shadow_tx); | ||||
| accumulate_ps_.bind_texture("ambient_occlusion_tx", &rbuffers.ambient_occlusion_tx); | accumulate_ps_.bind_texture("ambient_occlusion_tx", &rbuffers.ambient_occlusion_tx); | ||||
| accumulate_ps_.bind_texture("aov_color_tx", &rbuffers.aov_color_tx); | accumulate_ps_.bind_texture("aov_color_tx", &rbuffers.aov_color_tx); | ||||
| accumulate_ps_.bind_texture("aov_value_tx", &rbuffers.aov_value_tx); | accumulate_ps_.bind_texture("aov_value_tx", &rbuffers.aov_value_tx); | ||||
| accumulate_ps_.bind_texture("cryptomatte_tx", &rbuffers.cryptomatte_tx); | |||||
| /* NOTE(@fclem): 16 is the max number of sampled texture in many implementations. | /* NOTE(@fclem): 16 is the max number of sampled texture in many implementations. | ||||
| * If we need more, we need to pack more of the similar passes in the same textures as arrays or | * If we need more, we need to pack more of the similar passes in the same textures as arrays or | ||||
| * use image binding instead. */ | * use image binding instead. */ | ||||
| accumulate_ps_.bind_image("in_weight_img", &weight_tx_.current()); | accumulate_ps_.bind_image("in_weight_img", &weight_tx_.current()); | ||||
| accumulate_ps_.bind_image("out_weight_img", &weight_tx_.next()); | accumulate_ps_.bind_image("out_weight_img", &weight_tx_.next()); | ||||
| accumulate_ps_.bind_texture("in_combined_tx", &combined_tx_.current(), filter); | accumulate_ps_.bind_texture("in_combined_tx", &combined_tx_.current(), filter); | ||||
| accumulate_ps_.bind_image("out_combined_img", &combined_tx_.next()); | accumulate_ps_.bind_image("out_combined_img", &combined_tx_.next()); | ||||
| accumulate_ps_.bind_image("depth_img", &depth_tx_); | accumulate_ps_.bind_image("depth_img", &depth_tx_); | ||||
| accumulate_ps_.bind_image("color_accum_img", &color_accum_tx_); | accumulate_ps_.bind_image("color_accum_img", &color_accum_tx_); | ||||
| accumulate_ps_.bind_image("value_accum_img", &value_accum_tx_); | accumulate_ps_.bind_image("value_accum_img", &value_accum_tx_); | ||||
| accumulate_ps_.bind_image("cryptomatte_img", &cryptomatte_tx_); | |||||
| /* Sync with rendering passes. */ | /* Sync with rendering passes. */ | ||||
| accumulate_ps_.barrier(GPU_BARRIER_TEXTURE_FETCH | GPU_BARRIER_SHADER_IMAGE_ACCESS); | accumulate_ps_.barrier(GPU_BARRIER_TEXTURE_FETCH | GPU_BARRIER_SHADER_IMAGE_ACCESS); | ||||
| if (use_compute) { | if (use_compute) { | ||||
| accumulate_ps_.dispatch(int3(math::divide_ceil(data_.extent, int2(FILM_GROUP_SIZE)), 1)); | accumulate_ps_.dispatch(int3(math::divide_ceil(data_.extent, int2(FILM_GROUP_SIZE)), 1)); | ||||
| } | } | ||||
| else { | else { | ||||
| accumulate_ps_.draw_procedural(GPU_PRIM_TRIS, 1, 3); | accumulate_ps_.draw_procedural(GPU_PRIM_TRIS, 1, 3); | ||||
| } | } | ||||
| const int cryptomatte_layer_count = cryptomatte_layer_len_get(); | |||||
| const bool is_cryptomatte_pass_enabled = cryptomatte_layer_count > 0; | |||||
| const bool do_cryptomatte_sorting = inst_.is_viewport() == false; | |||||
| cryptomatte_post_ps_.init(); | |||||
| if (is_cryptomatte_pass_enabled && do_cryptomatte_sorting) { | |||||
| cryptomatte_post_ps_.state_set(DRW_STATE_NO_DRAW); | |||||
| cryptomatte_post_ps_.shader_set(inst_.shaders.static_shader_get(FILM_CRYPTOMATTE_POST)); | |||||
| cryptomatte_post_ps_.bind_image("cryptomatte_img", &cryptomatte_tx_); | |||||
| cryptomatte_post_ps_.bind_image("weight_img", &weight_tx_.current()); | |||||
| cryptomatte_post_ps_.push_constant("cryptomatte_layer_len", cryptomatte_layer_count); | |||||
| cryptomatte_post_ps_.push_constant("cryptomatte_samples_per_layer", | |||||
| inst_.view_layer->cryptomatte_levels); | |||||
| int2 dispatch_size = math::divide_ceil(int2(cryptomatte_tx_.size()), int2(FILM_GROUP_SIZE)); | |||||
| cryptomatte_post_ps_.dispatch(int3(UNPACK2(dispatch_size), 1)); | |||||
| } | |||||
| } | } | ||||
| void Film::end_sync() | void Film::end_sync() | ||||
| { | { | ||||
| data_.use_reprojection = inst_.sampling.interactive_mode(); | data_.use_reprojection = inst_.sampling.interactive_mode(); | ||||
| /* Just bypass the reprojection and reset the accumulation. */ | /* Just bypass the reprojection and reset the accumulation. */ | ||||
| if (force_disable_reprojection_ && inst_.sampling.is_reset()) { | if (force_disable_reprojection_ && inst_.sampling.is_reset()) { | ||||
| Show All 31 Lines | |||||
| { | { | ||||
| if (inst_.is_viewport() && data_.use_reprojection) { | if (inst_.is_viewport() && data_.use_reprojection) { | ||||
| /* Enable motion vector rendering but not the accumulation buffer. */ | /* Enable motion vector rendering but not the accumulation buffer. */ | ||||
| return enabled_passes_ | EEVEE_RENDER_PASS_VECTOR; | return enabled_passes_ | EEVEE_RENDER_PASS_VECTOR; | ||||
| } | } | ||||
| return enabled_passes_; | return enabled_passes_; | ||||
| } | } | ||||
| int Film::cryptomatte_layer_len_get() const | |||||
| { | |||||
| int result = 0; | |||||
| result += data_.cryptomatte_object_id == -1 ? 0 : 1; | |||||
| result += data_.cryptomatte_asset_id == -1 ? 0 : 1; | |||||
| result += data_.cryptomatte_material_id == -1 ? 0 : 1; | |||||
| return result; | |||||
| } | |||||
| int Film::cryptomatte_layer_max_get() const | |||||
| { | |||||
| if (data_.cryptomatte_material_id != -1) { | |||||
| return 3; | |||||
| } | |||||
| if (data_.cryptomatte_asset_id != -1) { | |||||
| return 2; | |||||
| } | |||||
| if (data_.cryptomatte_object_id != -1) { | |||||
| return 1; | |||||
| } | |||||
| return 0; | |||||
| } | |||||
| void Film::update_sample_table() | void Film::update_sample_table() | ||||
| { | { | ||||
| data_.subpixel_offset = pixel_jitter_get(); | data_.subpixel_offset = pixel_jitter_get(); | ||||
| int filter_radius_ceil = ceilf(data_.filter_radius); | int filter_radius_ceil = ceilf(data_.filter_radius); | ||||
| float filter_radius_sqr = square_f(data_.filter_radius); | float filter_radius_sqr = square_f(data_.filter_radius); | ||||
| data_.samples_len = 0; | data_.samples_len = 0; | ||||
| ▲ Show 20 Lines • Show All 120 Lines • ▼ Show 20 Lines | void Film::display() | ||||
| DRW_manager_get()->submit(accumulate_ps_, drw_view); | DRW_manager_get()->submit(accumulate_ps_, drw_view); | ||||
| inst_.render_buffers.release(); | inst_.render_buffers.release(); | ||||
| /* IMPORTANT: Do not swap! No accumulation has happened. */ | /* IMPORTANT: Do not swap! No accumulation has happened. */ | ||||
| } | } | ||||
| float *Film::read_pass(eViewLayerEEVEEPassType pass_type) | void Film::cryptomatte_sort() | ||||
| { | { | ||||
| DRW_manager_get()->submit(cryptomatte_post_ps_); | |||||
| } | |||||
| float *Film::read_pass(eViewLayerEEVEEPassType pass_type, int layer_offset) | |||||
| { | |||||
| ePassStorageType storage_type = pass_storage_type(pass_type); | |||||
| const bool is_value = storage_type == PASS_STORAGE_VALUE; | |||||
| const bool is_cryptomatte = storage_type == PASS_STORAGE_CRYPTOMATTE; | |||||
| bool is_value = pass_is_value(pass_type); | |||||
| Texture &accum_tx = (pass_type == EEVEE_RENDER_PASS_COMBINED) ? | Texture &accum_tx = (pass_type == EEVEE_RENDER_PASS_COMBINED) ? | ||||
| combined_tx_.current() : | combined_tx_.current() : | ||||
| (pass_type == EEVEE_RENDER_PASS_Z) ? | (pass_type == EEVEE_RENDER_PASS_Z) ? | ||||
| depth_tx_ : | depth_tx_ : | ||||
| (is_value ? value_accum_tx_ : color_accum_tx_); | (is_cryptomatte ? cryptomatte_tx_ : | ||||
| (is_value ? value_accum_tx_ : color_accum_tx_)); | |||||
| accum_tx.ensure_layer_views(); | accum_tx.ensure_layer_views(); | ||||
| int index = pass_id_get(pass_type); | int index = pass_id_get(pass_type); | ||||
| GPUTexture *pass_tx = accum_tx.layer_view(index); | GPUTexture *pass_tx = accum_tx.layer_view(index + layer_offset); | ||||
| GPU_memory_barrier(GPU_BARRIER_TEXTURE_UPDATE); | GPU_memory_barrier(GPU_BARRIER_TEXTURE_UPDATE); | ||||
| float *result = (float *)GPU_texture_read(pass_tx, GPU_DATA_FLOAT, 0); | float *result = (float *)GPU_texture_read(pass_tx, GPU_DATA_FLOAT, 0); | ||||
| if (pass_is_float3(pass_type)) { | if (pass_is_float3(pass_type)) { | ||||
| /* Convert result in place as we cannot do this conversion on GPU. */ | /* Convert result in place as we cannot do this conversion on GPU. */ | ||||
| for (auto px : IndexRange(accum_tx.width() * accum_tx.height())) { | for (auto px : IndexRange(accum_tx.width() * accum_tx.height())) { | ||||
| Show All 10 Lines | |||||