EEVEE Next: Ambient Occlusion #108398

Merged
Miguel Pozo merged 29 commits from pragma37/blender:pull-eevee-next-ao into main 2023-06-30 19:37:37 +02:00
10 changed files with 13 additions and 112 deletions
Showing only changes of commit dda8772851 - Show all commits

View File

@ -439,7 +439,6 @@ set(GLSL_SRC
engines/eevee/shaders/infos/engine_eevee_legacy_shared.h
engines/eevee/engine_eevee_shared_defines.h
engines/eevee_next/shaders/eevee_ambient_occlusion_horizons_frag.glsl
engines/eevee_next/shaders/eevee_ambient_occlusion_lib.glsl
engines/eevee_next/shaders/eevee_ambient_occlusion_pass_comp.glsl
engines/eevee_next/shaders/eevee_attributes_lib.glsl

View File

@ -41,67 +41,28 @@ void AmbientOcclusion::init()
(inst_.film.enabled_passes_get() & EEVEE_RENDER_PASS_AO);
render_pass_enabled_ = data_.enabled && inst_.film.enabled_passes_get() & EEVEE_RENDER_PASS_AO;
if (!data_.enabled) {
/* Early return. */
data_.push_update();
horizons_tx_.free();
return;
}
data_.distance = scene->eevee.gtao_distance;
data_.quality = scene->eevee.gtao_quality;
data_.push_update();
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_ATTACHMENT | GPU_TEXTURE_USAGE_SHADER_READ;
horizons_tx_.ensure_2d(GPU_RGBA8, inst_.film.render_extent_get(), usage);
}
void AmbientOcclusion::sync()
{
if (!data_.enabled) {
if (!render_pass_enabled_) {
return;
}
horizons_search_ps_.init();
horizons_search_ps_.state_set(DRW_STATE_WRITE_COLOR);
horizons_search_ps_.shader_set(inst_.shaders.static_shader_get(AO_HORIZONS));
bind_resources(&horizons_search_ps_, false);
render_pass_ps_.init();
render_pass_ps_.shader_set(inst_.shaders.static_shader_get(AMBIENT_OCCLUSION_PASS));
bind_resources(&render_pass_ps_);
horizons_search_ps_.draw_procedural(GPU_PRIM_TRIS, 1, 3);
render_pass_ps_.bind_image("in_normal_img", &rp_normal_tx_);
render_pass_ps_.bind_image("out_ao_img", &rp_ao_tx_);
if (render_pass_enabled_) {
render_pass_ps_.init();
render_pass_ps_.shader_set(inst_.shaders.static_shader_get(AMBIENT_OCCLUSION_PASS));
bind_resources(&render_pass_ps_);
render_pass_ps_.bind_image("in_normal_img", &rp_normal_tx_);
render_pass_ps_.bind_image("out_ao_img", &rp_ao_tx_);
render_pass_ps_.barrier(GPU_BARRIER_SHADER_IMAGE_ACCESS & GPU_BARRIER_TEXTURE_FETCH);
render_pass_ps_.dispatch(
math::divide_ceil(inst_.film.render_extent_get(), int2(AMBIENT_OCCLUSION_PASS_TILE_SIZE)));
}
}
void AmbientOcclusion::render(View &view)
{
if (!data_.enabled) {
return;
}
inst_.hiz_buffer.update();
fb_.ensure(GPU_ATTACHMENT_NONE, GPU_ATTACHMENT_TEXTURE(horizons_tx_));
fb_.bind();
inst_.manager->submit(horizons_search_ps_, view);
if (GPU_mip_render_workaround() ||
GPU_type_matches_ex(GPU_DEVICE_INTEL_UHD, GPU_OS_WIN, GPU_DRIVER_ANY, GPU_BACKEND_OPENGL))
{
/* Fix dot corruption on intel HD5XX/HD6XX series. */
GPU_flush();
}
render_pass_ps_.barrier(GPU_BARRIER_SHADER_IMAGE_ACCESS & GPU_BARRIER_TEXTURE_FETCH);
render_pass_ps_.dispatch(
math::divide_ceil(inst_.film.render_extent_get(), int2(AMBIENT_OCCLUSION_PASS_TILE_SIZE)));
}
void AmbientOcclusion::render_pass(View &view)

View File

@ -30,13 +30,6 @@ class AmbientOcclusion {
bool render_pass_enabled_;
AODataBuf data_;
Texture dummy_horizons_tx_;
Texture horizons_tx_;
Framebuffer fb_ = {"AO"};
PassSimple horizons_search_ps_ = {"AO Horizons Search"};
PassSimple render_pass_ps_ = {"AO Render Pass"};
/* Used as pointers for texture views in the AO Render Pass. */
@ -44,13 +37,7 @@ class AmbientOcclusion {
GPUTexture *rp_ao_tx_ = nullptr;
public:
AmbientOcclusion(Instance &inst) : inst_(inst)
{
dummy_horizons_tx_.ensure_2d(GPU_RGBA8,
int2(1),
GPU_TEXTURE_USAGE_ATTACHMENT | GPU_TEXTURE_USAGE_SHADER_READ,
float4(0));
};
AmbientOcclusion(Instance &inst) : inst_(inst){};
~AmbientOcclusion(){};
void init();
@ -60,18 +47,13 @@ class AmbientOcclusion {
void render(View &view);
void render_pass(View &view);
template<typename T>
void bind_resources(draw::detail::PassBase<T> *pass, bool bind_horizons = true)
template<typename T> void bind_resources(draw::detail::PassBase<T> *pass)
{
inst_.sampling.bind_resources(pass);
pragma37 marked this conversation as resolved Outdated

Do not bind other resources here. Will result in double binds and it is against the design of this function.

Do not bind other resources here. Will result in double binds and it is against the design of this function.
inst_.hiz_buffer.bind_resources(pass);
inst_.raytracing.bind_resources(pass);
pass->bind_texture(RBUFS_UTILITY_TEX_SLOT, &inst_.pipelines.utility_tx);
pass->bind_ubo(AO_BUF_SLOT, &data_);
if (bind_horizons) {
pass->bind_texture(AO_HORIZONS_TEX_SLOT,
data_.enabled ? &horizons_tx_ : &dummy_horizons_tx_);
}
}
};

View File

@ -99,7 +99,6 @@
/* Only during surface shading (forward and deferred eval). */
#define SHADOW_TILEMAPS_TEX_SLOT 4
#define SHADOW_ATLAS_TEX_SLOT 5
#define AO_HORIZONS_TEX_SLOT 6
/* Only during shadow rendering. */
#define SHADOW_RENDER_MAP_SLOT 4

View File

@ -81,8 +81,6 @@ ShaderModule::~ShaderModule()
const char *ShaderModule::static_shader_create_info_name_get(eShaderType shader_type)
{
switch (shader_type) {
case AO_HORIZONS:
return "eevee_ambient_occlusion_horizons";
case AMBIENT_OCCLUSION_PASS:
return "eevee_ambient_occlusion_pass";
case FILM_FRAG:

View File

@ -27,7 +27,6 @@ namespace blender::eevee {
/* Keep alphabetical order and clean prefix. */
enum eShaderType {
AO_HORIZONS = 0,
AMBIENT_OCCLUSION_PASS = 0,
FILM_FRAG,

View File

@ -1,26 +0,0 @@
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_geom_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_ambient_occlusion_lib.glsl)
/**
* This shader only compute maximum horizon angles for each directions.
* The final integration is done at the resolve stage with the shading normal.
*/
void main()
{
vec2 uvs = uvcoordsvar.xy;
float depth = textureLod(hiz_tx, uvs * hiz_buf.uv_scale, 0.0).r;
vec3 vP = get_view_space_from_depth(uvs, depth);
OcclusionData data = ambient_occlusion_disabled_data();
/* Do not trace for background */
if (depth != 1.0) {
ivec2 texel = ivec2(gl_FragCoord.xy);
data = ambient_occlusion_search(vP, hiz_tx, texel, ao_buf.distance, 0.0, 8.0);
}
out_horizons = ambient_occlusion_pack_data(data);
}

View File

@ -11,18 +11,8 @@ GPU_SHADER_CREATE_INFO(eevee_ambient_occlusion_data)
.additional_info("eevee_raytrace_data", "eevee_sampling_data", "eevee_utility_texture")
.uniform_buf(AO_BUF_SLOT, "AOData", "ao_buf");
GPU_SHADER_CREATE_INFO(eevee_ambient_occlusion_horizons_data)
.additional_info("eevee_ambient_occlusion_data")
.sampler(AO_HORIZONS_TEX_SLOT, ImageType::FLOAT_2D, "horizons_tx");
GPU_SHADER_CREATE_INFO(eevee_ambient_occlusion_horizons)
.additional_info("eevee_ambient_occlusion_data", "draw_fullscreen")
.fragment_source("eevee_ambient_occlusion_horizons_frag.glsl")
.fragment_out(0, Type::VEC4, "out_horizons")
.do_static_compilation(true);
GPU_SHADER_CREATE_INFO(eevee_ambient_occlusion_pass)
.additional_info("eevee_ambient_occlusion_horizons_data")
.additional_info("eevee_ambient_occlusion_data")
.compute_source("eevee_ambient_occlusion_pass_comp.glsl")
.local_group_size(AMBIENT_OCCLUSION_PASS_TILE_SIZE, AMBIENT_OCCLUSION_PASS_TILE_SIZE)
.image(0, GPU_RGBA16F, Qualifier::READ, ImageType::FLOAT_2D, "in_normal_img")

View File

@ -41,7 +41,6 @@ GPU_SHADER_CREATE_INFO(eevee_deferred_light)
"eevee_deferred_base",
"eevee_hiz_data",
"eevee_render_pass_out",
"eevee_ambient_occlusion_horizons_data",
"draw_view",
"draw_fullscreen")
.do_static_compilation(true);

View File

@ -125,7 +125,7 @@ GPU_SHADER_CREATE_INFO(eevee_surf_forward)
"eevee_utility_texture",
"eevee_sampling_data",
"eevee_shadow_data",
"eevee_ambient_occlusion_horizons_data"
"eevee_ambient_occlusion_data"
/* Optionally added depending on the material. */
// "eevee_render_pass_out",
// "eevee_cryptomatte_out",