39void Film::init_aovs(
const Set<std::string> &passes_used_by_viewport_compositor)
41 Vector<ViewLayerAOV *> aovs;
47 if (inst_.is_viewport()) {
52 &inst_.view_layer->aovs, inst_.v3d->shading.aov_name,
offsetof(ViewLayerAOV, name)));
62 if (inst_.is_viewport_compositor_used) {
63 for (ViewLayerAOV &aov : inst_.view_layer->aovs) {
65 if (!aovs.is_empty() && aovs.last() == &aov) {
69 if (passes_used_by_viewport_compositor.contains(aov.name)) {
77 for (ViewLayerAOV &aov : inst_.view_layer->aovs) {
82 if (aovs.size() > AOV_MAX) {
83 inst_.info_append_i18n(
"Error: Too many AOVs");
90 for (ViewLayerAOV *aov : aovs) {
98 for (ViewLayerAOV *aov : aovs) {
108 if (!aovs.is_empty()) {
117 if (pass_tx ==
nullptr) {
129 Texture &accum_tx = is_value ? value_accum_tx_ : color_accum_tx_;
139 for (
int i : (is_value ? value_range : color_range)) {
141 if (candidate_hash ==
hash) {
142 aov_index = i - (is_value ?
aovs_info.color_len : 0);
147 if (aov_index == -1) {
153 int index = aov_index + (is_value ? data_.aov_value_id : data_.aov_color_id);
163void Film::sync_mist()
167 float mist_start = world ? world->miststa : cam.
clip_near;
184 data_.
mist_bias = -mist_start / mist_distance;
219#define ENABLE_FROM_LEGACY(name_legacy, name_eevee) \
220 SET_FLAG_FROM_TEST(result, \
221 (view_layer->passflag & SCE_PASS_##name_legacy) != 0, \
222 EEVEE_RENDER_PASS_##name_eevee);
239#undef ENABLE_FROM_LEGACY
274 if (pass_type == 0) {
279 if (viewport_compositor_needed_passes.
contains(pass_name)) {
280 viewport_compositor_enabled_passes |= pass_type;
285 return viewport_compositor_enabled_passes;
303 using namespace math;
305 Sampling &sampling = inst_.sampling;
306 Scene &scene = *inst_.scene;
308 if (inst_.is_viewport()) {
315 inst_.sampling.reset();
323 if (inst_.is_viewport_compositor_used) {
327 passes_used_by_viewport_compositor, inst_.view_layer);
334 init_aovs(passes_used_by_viewport_compositor);
338 if (inst_.is_viewport()) {
341 inst_.v3d->shading.render_pass) |
342 viewport_compositor_enabled_passes_;
344 if (inst_.overlays_enabled() || inst_.gpencil_engine_enabled()) {
353 inst_.sampling.reset();
372 data_.scaling_factor = 1;
373 if (inst_.is_viewport()) {
377 data_.texture_lod_bias = 1.0f / (data_.scaling_factor * 1.5f);
383 output_rect = &fallback_rect;
386 display_extent = extent;
389 data_.offset =
int2(output_rect->
xmin, output_rect->
ymin);
390 data_.extent_inv = 1.0f /
float2(data_.extent);
391 data_.render_extent =
divide_ceil(data_.extent,
int2(data_.scaling_factor));
393 data_.render_extent += data_.overscan * 2;
397 if (!is_valid_render_extent_) {
398 inst_.info_append_i18n(
399 "Required render size ({}px) is larger than reported texture size limit ({}px).",
400 max_ii(data_.render_extent.x, data_.render_extent.y),
403 data_.extent =
int2(4, 4);
404 data_.render_extent =
int2(4, 4);
405 data_.extent_inv = 1.0f /
float2(data_.extent);
406 data_.offset =
int2(0, 0);
410 if (inst_.camera.is_panoramic()) {
413 int64_t render_pixel_count = data_.render_extent.x *
int64_t(data_.render_extent.y);
414 render_extent_shading_view_ =
int2(
ceilf(
sqrtf(
float(render_pixel_count))));
417 render_extent_shading_view_ = data_.render_extent;
423 data_.filter_radius = 0.0f;
425 if (data_.scaling_factor > 1) {
429 data_.filter_radius =
math::max(data_.filter_radius, 0.0001f);
431 if (inst_.camera.is_panoramic()) {
433 data_.filter_radius =
math::max(data_.filter_radius, 0.0001f);
436 data_.cryptomatte_samples_len = inst_.view_layer->cryptomatte_levels;
439 if (inst_.is_viewport() &&
false ) {
440 data_.background_opacity = inst_.v3d->shading.studiolight_background;
467 if (enabled_passes_ & data_passes) {
470 if (enabled_passes_ & color_passes_1) {
473 if (enabled_passes_ & color_passes_2) {
476 if (enabled_passes_ & color_passes_3) {
479 if (enabled_passes_ & cryptomatte_passes) {
482 if (enabled_passes_ & denoising_passes) {
501 int cryptomatte_id = 0;
505 if (enabled_passes_ & pass_type) {
507 index = data_.color_len++;
510 index = data_.value_len++;
513 index = cryptomatte_id;
514 cryptomatte_id +=
divide_ceil_u(data_.cryptomatte_samples_len, 2u);
520 if (inst_.is_viewport() && inst_.v3d->shading.render_pass == pass_type) {
521 data_.display_id =
index;
522 data_.display_storage_type = storage_type;
547 data_.denoising_specular_albedo_id = pass_index_get(
550 data_.aov_color_id = data_.color_len;
551 data_.aov_value_id = data_.value_len;
553 data_.aov_color_len =
aovs_info.color_len;
554 data_.aov_value_len =
aovs_info.value_len;
556 data_.color_len += data_.aov_color_len;
557 data_.value_len += data_.aov_value_len;
564 int2 weight_extent = (inst_.camera.is_panoramic() || (data_.scaling_factor > 1)) ?
575 reset += depth_tx_.ensure_2d(depth_format, data_.extent);
576 reset += combined_tx_.current().ensure_2d(color_format, data_.extent);
577 reset += combined_tx_.next().ensure_2d(color_format, data_.extent);
579 reset += weight_tx_.current().ensure_2d_array(weight_format, weight_extent, 2);
580 reset += weight_tx_.next().ensure_2d_array(weight_format, weight_extent, 2);
581 reset += color_accum_tx_.ensure_2d_array(color_format,
582 (data_.color_len > 0) ? data_.extent :
int2(1),
583 (data_.color_len > 0) ? data_.color_len : 1);
584 reset += value_accum_tx_.ensure_2d_array(float_format,
585 (data_.value_len > 0) ? data_.extent :
int2(1),
586 (data_.value_len > 0) ? data_.value_len : 1);
590 reset += cryptomatte_tx_.ensure_2d_array(cryptomatte_format,
591 (cryptomatte_array_len > 0) ? data_.extent :
int2(1),
592 (cryptomatte_array_len > 0) ? cryptomatte_array_len :
594 reset += denoising_depth_tx_.ensure_2d(
599 data_.use_history = 0;
600 use_reprojection_ =
false;
603 color_accum_tx_.clear(
float4(0.0f));
604 value_accum_tx_.clear(
float4(0.0f));
605 combined_tx_.current().clear(
float4(0.0f));
606 weight_tx_.current().clear(
float4(0.0f));
607 depth_tx_.clear(
float4(0.0f));
608 cryptomatte_tx_.clear(
float4(0.0f));
609 denoising_depth_tx_.clear(
float4(0.0f));
629 use_compute_ = !inst_.is_viewport() || inst_.camera.is_panoramic() ||
640 accumulate_ps_.
init();
641 init_pass(accumulate_ps_, sh);
648 accumulate_ps_.push_constant(
"display_only", &display_only_);
653 if (use_compute_ && inst_.is_viewport()) {
654 init_pass(copy_ps_, inst_.shaders.static_shader_get(
FILM_COPY));
660 const bool is_cryptomatte_pass_enabled = cryptomatte_layer_count > 0;
661 const bool do_cryptomatte_sorting = !inst_.is_viewport() || inst_.is_viewport_compositor_used;
662 cryptomatte_post_ps_.init();
663 if (is_cryptomatte_pass_enabled && do_cryptomatte_sorting) {
666 cryptomatte_post_ps_.bind_image(
"cryptomatte_img", &cryptomatte_tx_);
667 cryptomatte_post_ps_.bind_resources(inst_.uniform_data);
668 cryptomatte_post_ps_.push_constant(
"cryptomatte_layer_len", cryptomatte_layer_count);
669 cryptomatte_post_ps_.push_constant(
"cryptomatte_samples_per_layer",
670 inst_.view_layer->cryptomatte_levels);
673 cryptomatte_post_ps_.dispatch(
int3(
UNPACK2(dispatch_size), 1));
699 pass.
bind_ubo(
"camera_next", &(*velocity.camera_steps[step_next]));
709 pass.
bind_image(
"in_weight_img", &weight_tx_.current());
710 pass.
bind_image(
"out_weight_img", &weight_tx_.next());
712 pass.
bind_image(
"out_combined_img", &combined_tx_.next());
714 pass.
bind_image(
"color_accum_img", &color_accum_tx_);
715 pass.
bind_image(
"value_accum_img", &value_accum_tx_);
716 pass.
bind_image(
"cryptomatte_img", &cryptomatte_tx_);
717 pass.
bind_image(
"denoising_depth_img", &denoising_depth_tx_);
724 use_reprojection_ = inst_.sampling.interactive_mode() && !inst_.camera.is_panoramic();
727 if (inst_.is_viewport() && !use_reprojection_ && inst_.sampling.is_reset()) {
728 use_reprojection_ =
false;
729 data_.use_history =
false;
741 inst_.manager->warm_shader_specialization(accumulate_ps_);
742 inst_.manager->warm_shader_specialization(copy_ps_);
743 inst_.manager->warm_shader_specialization(cryptomatte_post_ps_);
751 !inst_.sampling.use_custom_pixel_jitter_sample())
759 const float bias = 0.5f;
767 if (data_.scaling_factor > 1) {
772 const int scale = data_.scaling_factor;
776 int prime = (render_pixel_per_final_pixel / 2) - 1;
778 uint64_t index = (inst_.sampling.sample_index() * prime) % render_pixel_per_final_pixel;
783 jitter += ((
float2(pixel_co) + 0.5f) /
scale) - 0.5f;
790 if (inst_.is_viewport() && use_reprojection_) {
794 return enabled_passes_;
800 result += data_.cryptomatte_object_id == -1 ? 0 : 1;
801 result += data_.cryptomatte_asset_id == -1 ? 0 : 1;
802 result += data_.cryptomatte_material_id == -1 ? 0 : 1;
811 int filter_radius_ceil =
ceilf(data_.filter_radius);
812 float filter_radius_sqr =
square_f(data_.filter_radius);
820 data_.samples_len = 0;
821 if (inst_.camera.is_panoramic()) {
823 data_.samples_len = FILM_PANORAMIC_SAMPLE_LEN;
825 else if (data_.scaling_factor > 1) {
830 for (
int y = 0;
y <= 1;
y++) {
831 for (
int x = 0;
x <= 1;
x++) {
838 data_.samples_weight_total = -1.0f;
842 data_.samples[0].texel =
int2(0, 0);
843 data_.samples[0].weight = 1.0f;
844 data_.samples_weight_total = 1.0f;
845 data_.samples_len = 1;
848 else if (data_.filter_radius < 2.20f) {
850 int closest_index = 0;
851 float closest_distance =
FLT_MAX;
852 data_.samples_weight_total = 0.0f;
854 for (
int y = -filter_radius_ceil;
y <= filter_radius_ceil;
y++) {
855 for (
int x = -filter_radius_ceil;
x <= filter_radius_ceil;
x++) {
858 if (distance_sqr < filter_radius_sqr) {
859 if (data_.samples_len >= FILM_PRECOMP_SAMPLE_MAX) {
865 sample.weight = film_filter_weight(data_.filter_radius, distance_sqr);
866 data_.samples_weight_total +=
sample.weight;
868 if (distance_sqr < closest_distance) {
869 closest_distance = distance_sqr;
870 closest_index = data_.samples_len;
877 if (closest_index != 0) {
878 std::swap(data_.samples[closest_index], data_.samples[0]);
882 if (data_.samples_len <= 9) {
883 data_.samples_len = 9;
892 data_.samples_len = sample_table.
size();
893 data_.samples_weight_total = 0.0f;
901 random_2d.x = (random_2d.x + i) /
float(FILM_PRECOMP_SAMPLE_MAX);
907 sample.weight = film_filter_weight(data_.filter_radius, distance_sqr);
908 data_.samples_weight_total +=
sample.weight;
915 if (data_.samples_len == 1) {
916 data_.samples_len = 1;
918 else if (data_.samples_len <= 4) {
919 data_.samples_len = 4;
921 else if (data_.samples_len <= 9) {
922 data_.samples_len = 9;
924 else if (data_.samples_len <= 16) {
925 data_.samples_len = 16;
934 if (inst_.is_viewport()) {
945 combined_final_tx_ = combined_final_tx;
947 display_only_ =
false;
948 inst_.manager->submit(accumulate_ps_, view);
954 inst_.manager->submit(copy_ps_, view);
957 if (data_.use_history == 0) {
958 data_.use_history = 1;
967 inst_.render_buffers.acquire(
int2(1));
973 combined_final_tx_ = inst_.render_buffers.combined_tx;
977 display_only_ =
true;
980 inst_.render_buffers.release();
1016 combined_tx_.current() :
1020 denoising_depth_tx_ :
1021 (is_cryptomatte ? cryptomatte_tx_ :
1022 (is_value ? value_accum_tx_ : color_accum_tx_));
1037 switch (pass_type) {
1062 switch (aov->
type) {
1079 viewport_compositor_enabled_passes_ & (1 << i));
1080 if (pass_type == 0) {
1087 if (!pass_texture) {
1097 const char *pass_name = pass_names[pass_offset].c_str();
1101 PassSimple write_pass_ps = {
"Film.WriteViewportCompositorPass"};
1103 write_pass_ps.
shader_set(inst_.shaders.static_shader_get(write_shader_type));
1106 write_pass_ps.
bind_image(
"output_img", output_pass_texture);
1109 inst_.manager->submit(write_pass_ps);
1119 if (!pass_texture) {
1127 PassSimple write_pass_ps = {
"Film.WriteViewportCompositorPass"};
1129 write_pass_ps.
shader_set(inst_.shaders.static_shader_get(write_shader_type));
1132 write_pass_ps.
bind_image(
"output_img", output_pass_texture);
1135 inst_.manager->submit(write_pass_ps);
#define EEVEE_RENDER_PASS_MAX_BIT
#define BLI_assert_unreachable()
#define SET_FLAG_FROM_TEST(value, test, flag)
#define BLI_assert_msg(a, msg)
constexpr IndexRange()=default
constexpr int64_t size() const
bool contains(const Key &key) const
void submit(PassSimple &pass, View &view)
bool acquire_2d(int2 extent, gpu::TextureFormat format, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, int mip_len=1)
bool ensure_layer_views(bool cube_as_array=false)
gpu::Texture * layer_view(int layer)
static View & default_get()
void bind_resources(U &resources)
void shader_set(gpu::Shader *shader)
void bind_texture(const char *name, gpu::Texture *texture, GPUSamplerState state=sampler_auto)
void specialize_constant(gpu::Shader *shader, const char *name, const float &data)
void bind_image(const char *name, gpu::Texture *image)
void dispatch(int group_len)
void state_set(DRWState state, int clip_plane_count=0)
void barrier(GPUBarrier type)
void bind_ubo(const char *name, gpu::UniformBuf *buffer)
void push_constant(const char *name, const float &data)
const CameraData & data_get() const
float2 pixel_jitter_get() const
int pass_id_get(eViewLayerEEVEEPassType pass_type) const
static bool pass_is_float3(eViewLayerEEVEEPassType pass_type)
gpu::Texture * get_pass_texture(eViewLayerEEVEEPassType pass_type, int layer_offset)
struct blender::eevee::Film::DepthState depth
static const Vector< std::string > pass_to_render_pass_names(eViewLayerEEVEEPassType pass_type, const ViewLayer *view_layer)
void update_sample_table()
int cryptomatte_layer_len_get() const
static ePassStorageType pass_storage_type(eViewLayerEEVEEPassType pass_type)
float * read_pass(eViewLayerEEVEEPassType pass_type, int layer_offset)
void write_viewport_compositor_passes()
static int overscan_pixels_get(float overscan, int2 extent)
void accumulate(View &view, gpu::Texture *combined_final_tx)
void init(const int2 &full_extent, const rcti *output_rect)
float * read_aov(ViewLayerAOV *aov)
StorageBuffer< AOVsInfoData > aovs_info
eViewLayerEEVEEPassType enabled_passes_get() const
static constexpr bool use_box_filter
gpu::Texture * get_aov_texture(ViewLayerAOV *aov)
RenderBuffers render_buffers
UniformDataModule uniform_data
TextureFromPool cryptomatte_tx
TextureFromPool rp_value_tx
TextureFromPool vector_tx
TextureFromPool rp_color_tx
static float2 sample_disk(const float2 &rand)
uint64_t sample_count() const
static float2 sample_spiral(const float2 &rand)
virtual void init(const shader::ShaderCreateInfo &info, bool is_codegen_only)=0
#define ENABLE_FROM_LEGACY(name_legacy, name_eevee)
int divide_ceil(int a, int b)
float3x3 scale(float3x3 mat, float2 scale)
Set< std::string > get_used_passes(const Scene &scene, const ViewLayer *view_layer, ExecutionMode mode)
detail::Pass< command::DrawCommandBuf > PassSimple
@ FILM_PASS_CONVERT_COMBINED
@ FILM_PASS_CONVERT_CRYPTOMATTE
@ FILM_PASS_CONVERT_COLOR
@ FILM_PASS_CONVERT_VALUE
@ FILM_PASS_CONVERT_DEPTH
static eShaderType get_write_pass_shader_type(eViewLayerEEVEEPassType pass_type)
bool operator!=(const CameraData &a, const CameraData &b)
static eViewLayerEEVEEPassType with_light_pass_color_dependencies(eViewLayerEEVEEPassType passes)
static eShaderType get_aov_write_pass_shader_type(const ViewLayerAOV *aov)
static eViewLayerEEVEEPassType enabled_passes(const ViewLayer *view_layer)
bool operator==(const CameraData &a, const CameraData &b)
static eViewLayerEEVEEPassType get_viewport_compositor_enabled_passes(const Set< std::string > &viewport_compositor_needed_passes, const ViewLayer *view_layer)
@ PASS_STORAGE_DENOISING_DEPTH
@ PASS_STORAGE_CRYPTOMATTE
@ PASS_CATEGORY_CRYPTOMATTE
T length_squared(const VecBase< T, Size > &a)
VecBase< T, Size > divide_ceil(const VecBase< T, Size > &a, const VecBase< T, Size > &b)
T max(const T &a, const T &b)
void GPU_framebuffer_bind(gpu::FrameBuffer *fb)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
int BKE_render_preview_pixel_size(const RenderData *r)
unsigned __int64 uint64_t
bool GPU_type_matches_ex(GPUDeviceType device, GPUOSType os, GPUDriverType driver, GPUBackendType backend)
gpu::TextureFormat GPU_texture_format(const gpu::Texture *texture)
draw::TextureFromPool & DRW_viewport_pass_texture_get(const char *pass_name)
bool assign_if_different(T &old_value, T &&new_value)
void GPU_framebuffer_viewport_set(gpu::FrameBuffer *fb, int x, int y, int width, int height)
MINLINE int square_i(int a)
void * BLI_findstring(const ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void GPU_framebuffer_clear_color(gpu::FrameBuffer *fb, const double4 clear_col)
@ GPU_SAMPLER_FILTERING_LINEAR
MINLINE int max_ii(int a, int b)
int GPU_max_texture_size()
MINLINE float pow2f(float x)
VecBase< float, 4 > float4
bool GPU_type_matches(GPUDeviceType device, GPUOSType os, GPUDriverType driver)
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
VecBase< int32_t, 3 > int3
@ WO_MIST_INVERSE_QUADRATIC
void GPU_memory_barrier(GPUBarrier barrier)
int GPU_texture_width(const gpu::Texture *texture)
@ GPU_BARRIER_TEXTURE_FETCH
@ GPU_BARRIER_TEXTURE_UPDATE
@ GPU_BARRIER_SHADER_IMAGE_ACCESS
@ DRW_STATE_DEPTH_GREATER_EQUAL
bool BLI_rcti_is_empty(const struct rcti *rect)
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax)
BLI_INLINE unsigned int BLI_hash_string(const char *str)
@ EEVEE_RENDER_PASS_CRYPTOMATTE_ASSET
@ EEVEE_RENDER_PASS_SPECULAR_LIGHT
@ EEVEE_RENDER_PASS_DIFFUSE_COLOR
@ EEVEE_RENDER_PASS_DENOISING_NORMAL
@ EEVEE_RENDER_PASS_CRYPTOMATTE_MATERIAL
@ EEVEE_RENDER_PASS_ENVIRONMENT
@ EEVEE_RENDER_PASS_VECTOR
@ EEVEE_RENDER_PASS_DENOISING_ROUGHNESS
@ EEVEE_RENDER_PASS_DENOISING_DIFFUSE_ALBEDO
@ EEVEE_RENDER_PASS_DEPTH
@ EEVEE_RENDER_PASS_CRYPTOMATTE_OBJECT
@ EEVEE_RENDER_PASS_COMBINED
@ EEVEE_RENDER_PASS_VOLUME_LIGHT
@ EEVEE_RENDER_PASS_DENOISING_SPECULAR_ALBEDO
@ EEVEE_RENDER_PASS_TRANSPARENT
@ EEVEE_RENDER_PASS_NORMAL
@ EEVEE_RENDER_PASS_UNUSED_8
@ EEVEE_RENDER_PASS_POSITION
@ EEVEE_RENDER_PASS_DIFFUSE_LIGHT
@ EEVEE_RENDER_PASS_SPECULAR_COLOR
@ EEVEE_RENDER_PASS_SHADOW
@ EEVEE_RENDER_PASS_UNUSED_14
@ EEVEE_RENDER_PASS_DENOISING_DEPTH
int GPU_texture_height(const gpu::Texture *texture)
@ VIEW_LAYER_CRYPTOMATTE_ASSET
@ VIEW_LAYER_CRYPTOMATTE_MATERIAL
@ VIEW_LAYER_CRYPTOMATTE_OBJECT
MINLINE uint divide_ceil_u(uint a, uint b)
draw::Manager * DRW_manager_get()
MINLINE float square_f(float a)
@ EEVEE_DENOISING_PASS_STORE
void * GPU_texture_read(gpu::Texture *texture, eGPUDataFormat data_format, int mip_level)
VecBase< float, 3 > float3
VecBase< double, 4 > double4
MINLINE float clamp_f(float value, float min, float max)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
gpu::FrameBuffer * default_fb
ColorManagedViewSettings view_settings
eViewLayerEEVEEPassType render_passes
struct ViewLayerEEVEE eevee
eViewLayerCryptomatteFlags cryptomatte_flag