Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/eevee_next/shaders/eevee_film_lib.glsl
| /** | /** | ||||||||
| * Film accumulation utils functions. | * Film accumulation utils functions. | ||||||||
| **/ | **/ | ||||||||
| #pragma BLENDER_REQUIRE(common_view_lib.glsl) | #pragma BLENDER_REQUIRE(common_view_lib.glsl) | ||||||||
| #pragma BLENDER_REQUIRE(common_math_geom_lib.glsl) | #pragma BLENDER_REQUIRE(common_math_geom_lib.glsl) | ||||||||
| #pragma BLENDER_REQUIRE(eevee_camera_lib.glsl) | #pragma BLENDER_REQUIRE(eevee_camera_lib.glsl) | ||||||||
| #pragma BLENDER_REQUIRE(eevee_velocity_lib.glsl) | #pragma BLENDER_REQUIRE(eevee_velocity_lib.glsl) | ||||||||
| #pragma BLENDER_REQUIRE(eevee_colorspace_lib.glsl) | #pragma BLENDER_REQUIRE(eevee_colorspace_lib.glsl) | ||||||||
| #pragma BLENDER_REQUIRE(eevee_cryptomatte_lib.glsl) | |||||||||
| /* Return scene linear Z depth from the camera or radial depth for panoramic cameras. */ | /* Return scene linear Z depth from the camera or radial depth for panoramic cameras. */ | ||||||||
| float film_depth_convert_to_scene(float depth) | float film_depth_convert_to_scene(float depth) | ||||||||
| { | { | ||||||||
| if (false /* Panoramic */) { | if (false /* Panoramic */) { | ||||||||
| /* TODO */ | /* TODO */ | ||||||||
| return 1.0; | return 1.0; | ||||||||
| } | } | ||||||||
| ▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | void film_sample_accum_combined(FilmSample samp, inout vec4 accum, inout float weight_accum) | ||||||||
| /* Weight by luma to remove fireflies. */ | /* Weight by luma to remove fireflies. */ | ||||||||
| float weight = film_luma_weight(color.x) * samp.weight; | float weight = film_luma_weight(color.x) * samp.weight; | ||||||||
| accum += color * weight; | accum += color * weight; | ||||||||
| weight_accum += weight; | weight_accum += weight; | ||||||||
| } | } | ||||||||
| void film_sample_cryptomatte_accum(FilmSample samp, | |||||||||
| int layer, | |||||||||
| sampler2D tex, | |||||||||
| inout vec2 crypto_samples[4]) | |||||||||
| { | |||||||||
| float hash = texelFetch(tex, samp.texel, 0)[layer]; | |||||||||
| /* Find existing entry. */ | |||||||||
| for (int i = 0; i < 4; i++) { | |||||||||
| if (crypto_samples[i].x == hash) { | |||||||||
| crypto_samples[i].y += samp.weight; | |||||||||
| return; | |||||||||
| } | |||||||||
| } | |||||||||
| /* Overwrite entry with less weight. */ | |||||||||
| for (int i = 0; i < 4; i++) { | |||||||||
| if (crypto_samples[i].y < samp.weight) { | |||||||||
| crypto_samples[i] = vec2(hash, samp.weight); | |||||||||
| return; | |||||||||
| } | |||||||||
| } | |||||||||
| } | |||||||||
| void film_cryptomatte_layer_accum_and_store( | |||||||||
| FilmSample dst, ivec2 texel_film, int pass_id, int layer_component, inout vec4 out_color) | |||||||||
| { | |||||||||
| if (pass_id == -1) { | |||||||||
| return; | |||||||||
| } | |||||||||
| /* x = hash, y = accumed weight. Only keep track of 4 highest weighted samples. */ | |||||||||
| vec2 crypto_samples[4] = vec2[4](vec2(0.0), vec2(0.0), vec2(0.0), vec2(0.0)); | |||||||||
fclem: This is not a correct GLSL array declaration. | |||||||||
| for (int i = 0; i < film_buf.samples_len; i++) { | |||||||||
| FilmSample src = film_sample_get(i, texel_film); | |||||||||
| film_sample_cryptomatte_accum(src, layer_component, cryptomatte_tx, crypto_samples); | |||||||||
| } | |||||||||
| for (int i = 0; i < 4; i++) { | |||||||||
| cryptomatte_store_film_sample(dst, pass_id, crypto_samples[i], out_color); | |||||||||
| } | |||||||||
| } | |||||||||
| /** \} */ | /** \} */ | ||||||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||||||
| /** \name Load/Store Data | /** \name Load/Store Data | ||||||||
| * \{ */ | * \{ */ | ||||||||
| /* Returns the distance used to store nearest interpolation data. */ | /* Returns the distance used to store nearest interpolation data. */ | ||||||||
| float film_distance_load(ivec2 texel) | float film_distance_load(ivec2 texel) | ||||||||
| ▲ Show 20 Lines • Show All 524 Lines • ▼ Show 20 Lines | for (int aov = 0; aov < film_buf.aov_value_len; aov++) { | ||||||||
| float aov_accum = 0.0; | float aov_accum = 0.0; | ||||||||
| for (int i = 0; i < film_buf.samples_len; i++) { | for (int i = 0; i < film_buf.samples_len; i++) { | ||||||||
| FilmSample src = film_sample_get(i, texel_film); | FilmSample src = film_sample_get(i, texel_film); | ||||||||
| film_sample_accum(src, aov, aov_value_tx, aov_accum); | film_sample_accum(src, aov, aov_value_tx, aov_accum); | ||||||||
| } | } | ||||||||
| film_store_value(dst, film_buf.aov_value_id + aov, aov_accum, out_color); | film_store_value(dst, film_buf.aov_value_id + aov, aov_accum, out_color); | ||||||||
| } | } | ||||||||
| if (film_buf.cryptomatte_samples_len != 0) { | |||||||||
| /* Cryptomatte passes cannot be cleared by a weighted store like other passes. */ | |||||||||
Done Inline Actions
fclem: | |||||||||
| if (!film_buf.use_history || film_buf.use_reprojection) { | |||||||||
| cryptomatte_clear_samples(dst); | |||||||||
| } | |||||||||
| film_cryptomatte_layer_accum_and_store( | |||||||||
| dst, texel_film, film_buf.cryptomatte_object_id, 0, out_color); | |||||||||
| film_cryptomatte_layer_accum_and_store( | |||||||||
| dst, texel_film, film_buf.cryptomatte_asset_id, 1, out_color); | |||||||||
| film_cryptomatte_layer_accum_and_store( | |||||||||
| dst, texel_film, film_buf.cryptomatte_material_id, 2, out_color); | |||||||||
| } | |||||||||
| } | } | ||||||||
This is not a correct GLSL array declaration.