3.2.7 release.

This commit is contained in:
Emmanuel Julien 2023-08-14 16:54:47 +02:00 committed by fra
parent 761139559e
commit ef65b8a8f6
11 changed files with 160 additions and 21 deletions

View File

@ -407,7 +407,7 @@ endif()
message(STATUS "Build Go module: " ${HG_BUILD_HG_GO})
message(STATUS "Embedded system build: " ${HG_EMBEDDED})
message(STATUS "Binding defines: " ${HG_BINDING_DEFINES})
message(STATUS "Binding defines: " ${HG_BINDING_DEFINES_LIST})
message(STATUS "Available APIs:")
message(STATUS " - Core")

View File

@ -1599,7 +1599,8 @@ static std::vector<hg::ForwardPipelineLight> _GetSceneForwardPipelineLights(cons
'int sample_count', 'float max_distance', 'float z_thickness',
'float bloom_threshold', 'float bloom_bias', 'float bloom_intensity',
'float motion_blur',
'float exposure', 'float gamma'
'float exposure', 'float gamma',
'float dof_focus_point', 'float dof_focus_length'
])
gen.end_class(forward_pipeline_aaa_config)

View File

@ -69,7 +69,7 @@ CITE_BIB_FILES =
# Configuration options related to warning and progress messages
QUIET = NO
QUIET = YES
WARNINGS = YES
WARN_IF_UNDOCUMENTED = YES
WARN_IF_DOC_ERROR = YES
@ -99,7 +99,6 @@ CLANG_OPTIONS =
# Configuration options related to the alphabetical class index
ALPHABETICAL_INDEX = YES
COLS_IN_ALPHA_INDEX = 3
IGNORE_PREFIX =
# Configuration options related to the HTML output
@ -115,7 +114,6 @@ HTML_EXTRA_FILES =
HTML_COLORSTYLE_HUE = 220
HTML_COLORSTYLE_SAT = 100
HTML_COLORSTYLE_GAMMA = 80
HTML_TIMESTAMP = NO
HTML_DYNAMIC_SECTIONS = NO
HTML_INDEX_NUM_ENTRIES = 100
SEARCHENGINE = YES

View File

@ -9,6 +9,7 @@ set(HDRS
cubemap.h
dear_imgui.h
debugger.h
dof.h
file_format.h
font.h
forward_pipeline.h
@ -65,6 +66,7 @@ set(SRCS
cubemap.cpp
dear_imgui.cpp
debugger.cpp
dof.cpp
font.cpp
forward_pipeline.cpp
fps_controller.cpp

92
harfang/engine/dof.cpp Normal file
View File

@ -0,0 +1,92 @@
// HARFANG(R) Copyright (C) 2023 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details.
#include "dof.h"
#include "assets_rw_interface.h"
#include <foundation/file_rw_interface.h>
#include <foundation/format.h>
#include <foundation/log.h>
#include <foundation/projection.h>
#include <foundation/rw_interface.h>
namespace hg {
static bool LoadShaders(Dof &dof, const Reader &ir, const ReadProvider &ip, const char *path) {
// uniforms
dof.u_color = bgfx::createUniform("u_color", bgfx::UniformType::Sampler);
dof.u_attr0 = bgfx::createUniform("u_attr0", bgfx::UniformType::Sampler);
dof.u_params = bgfx::createUniform("u_params", bgfx::UniformType::Vec4);
if (!(bgfx::isValid(dof.u_color) && bgfx::isValid(dof.u_attr0) && bgfx::isValid(dof.u_params))) {
warn("failed to create depth of field uniforms.");
return false;
}
// load programs
dof.prg_dof_coc = LoadProgram(ir, ip, format("%1/shader/dof_coc").arg(path));
if (!(bgfx::isValid(dof.prg_dof_coc))) {
warn("failed to load depth of field programs.");
return false;
}
return true;
}
static const uint64_t g_dof_tex_flags = 0 | BGFX_TEXTURE_RT | BGFX_SAMPLER_U_CLAMP | BGFX_SAMPLER_V_CLAMP;
bool IsValid(const Dof &dof) {
return bgfx::isValid(dof.u_color) && bgfx::isValid(dof.u_attr0) && bgfx::isValid(dof.u_params) && bgfx::isValid(dof.prg_dof_coc);
}
static Dof CreateDof(const Reader &ir, const ReadProvider &ip, const char *path) {
Dof dof;
if (!LoadShaders(dof, ir, ip, path)) {
DestroyDof(dof);
return dof;
}
return dof;
}
Dof CreateDofFromFile(const char *path) { return CreateDof(g_file_reader, g_file_read_provider, path); }
Dof CreateDofFromAssets(const char *path) { return CreateDof(g_assets_reader, g_assets_read_provider, path); }
void DestroyDof(Dof &dof) {
bgfx_Destroy(dof.u_color);
bgfx_Destroy(dof.u_attr0);
bgfx_Destroy(dof.u_params);
bgfx_Destroy(dof.prg_dof_coc);
}
void ApplyDof(bgfx::ViewId &view_id, const iRect &rect, bgfx::BackbufferRatio::Enum ratio, const Texture &color, const Texture &attr0,
bgfx::FrameBufferHandle output, const Dof &dof, float focus_point, float focus_length) {
bgfx::TransientIndexBuffer idx;
bgfx::TransientVertexBuffer vtx;
CreateFullscreenQuad(idx, vtx);
float ortho[16];
memcpy(ortho, to_bgfx(Compute2DProjectionMatrix(0.f, 100.f, 1.f, 1.f, false)).data(), sizeof(float[16]));
bgfx::setViewName(view_id, "DoF");
bgfx::setViewRect(view_id, rect.sx, rect.sy, GetWidth(rect), GetHeight(rect));
bgfx::setViewFrameBuffer(view_id, output);
bgfx::setViewTransform(view_id, NULL, ortho);
bgfx::setViewClear(view_id, BGFX_CLEAR_NONE, 0, 1.f, UINT8_MAX);
bgfx::setTexture(0, dof.u_color, color.handle, uint32_t(color.flags));
bgfx::setTexture(1, dof.u_attr0, attr0.handle, uint32_t(attr0.flags));
float params[4];
params[0] = focus_point;
params[1] = focus_length;
bgfx::setUniform(dof.u_params, params);
bgfx::setState(BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A | BGFX_STATE_DEPTH_TEST_ALWAYS);
bgfx::setIndexBuffer(&idx);
bgfx::setVertexBuffer(0, &vtx);
bgfx::submit(view_id, dof.prg_dof_coc);
view_id++;
}
} // namespace hg

28
harfang/engine/dof.h Normal file
View File

@ -0,0 +1,28 @@
// HARFANG(R) Copyright (C) 2023 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details.
#pragma once
#include "engine/render_pipeline.h"
#include "foundation/rect.h"
namespace hg {
struct Dof {
bgfx::ProgramHandle prg_dof_coc = BGFX_INVALID_HANDLE;
bgfx::UniformHandle u_color = BGFX_INVALID_HANDLE;
bgfx::UniformHandle u_attr0 = BGFX_INVALID_HANDLE; // xyz: normal, w: linear depth
bgfx::UniformHandle u_params = BGFX_INVALID_HANDLE;
};
Dof CreateDofFromFile(const char *path);
Dof CreateDofFromAssets(const char *path);
void DestroyDof(Dof &dof);
void ApplyDof(bgfx::ViewId &view_id, const iRect &rect, bgfx::BackbufferRatio::Enum ratio, const Texture &color, const Texture &attr0,
bgfx::FrameBufferHandle output, const Dof &dof, float focus_point, float focus_length);
bool IsValid(const Dof &dof);
} // namespace hg

View File

@ -216,17 +216,12 @@ static ForwardPipelineAAA _CreateForwardPipelineAAA(const Reader &ir, const Read
aaa.ssr_history_fb[1] = bgfx::createFrameBuffer(1, &aaa.ssr_history[1].handle, true);
}
{ aaa.blur = CreateAAABlurFromAssets(path); }
{ aaa.hiz = CreateHiZFromAssets(path, rb_factory, hg::Min(ssgi_ratio, ssr_ratio)); }
{ aaa.downsample = CreateDownsampleFromAssets(path, rb_factory); }
{ aaa.upsample = CreateUpsampleFromAssets(path); }
{ aaa.temporal_acc = CreateTemporalAccumulationFromAssets(path); }
{ aaa.motion_blur = CreateMotionBlurFromAssets(path); }
aaa.blur = CreateAAABlurFromAssets(path);
aaa.hiz = CreateHiZFromAssets(path, rb_factory, hg::Min(ssgi_ratio, ssr_ratio));
aaa.downsample = CreateDownsampleFromAssets(path, rb_factory);
aaa.upsample = CreateUpsampleFromAssets(path);
aaa.temporal_acc = CreateTemporalAccumulationFromAssets(path);
aaa.motion_blur = CreateMotionBlurFromAssets(path);
{
// RGBA16F
@ -255,6 +250,8 @@ static ForwardPipelineAAA _CreateForwardPipelineAAA(const Reader &ir, const Read
}
aaa.taa = CreateTAAFromAssets(path);
aaa.dof = CreateDofFromAssets(path);
aaa.bloom = CreateBloomFromAssets(hg::format("%1/shader").arg(path), rb_factory, bgfx::BackbufferRatio::Equal);
if (!IsValid(aaa)) {
@ -368,6 +365,7 @@ void DestroyForwardPipelineAAA(ForwardPipelineAAA &aaa) {
//
DestroyTAA(aaa.taa);
DestroyDof(aaa.dof);
DestroyBloom(aaa.bloom);
DestroyHiZ(aaa.hiz);
@ -806,8 +804,16 @@ void SubmitSceneToForwardPipeline(bgfx::ViewId &view_id, const Scene &scene, con
view_id, rect, {attribute_texture_flags, bgfx::getTexture(aaa.next_frame_hdr_fb)}, aaa.attr0, aaa.attr1, noise, aaa.work_frame_hdr_fb, aaa.motion_blur);
// bloom
ApplyBloom(view_id, rect, {attribute_texture_flags, bgfx::getTexture(aaa.work_frame_hdr_fb)}, fb_size, aaa.frame_hdr_fb, aaa.bloom,
aaa_config.bloom_threshold, aaa_config.bloom_bias, aaa_config.bloom_intensity);
if (aaa_config.dof_focus_length == 0.f) { // TODO proper ping-pong, bloom should be optional as well...
ApplyBloom(view_id, rect, {attribute_texture_flags, bgfx::getTexture(aaa.work_frame_hdr_fb)}, fb_size, aaa.frame_hdr_fb, aaa.bloom,
aaa_config.bloom_threshold, aaa_config.bloom_bias, aaa_config.bloom_intensity);
} else {
ApplyBloom(view_id, rect, {attribute_texture_flags, bgfx::getTexture(aaa.work_frame_hdr_fb)}, fb_size, aaa.next_frame_hdr_fb, aaa.bloom,
aaa_config.bloom_threshold, aaa_config.bloom_bias, aaa_config.bloom_intensity);
// dof
ApplyDof(view_id, rect, bgfx::BackbufferRatio::Equal, {attribute_texture_flags, bgfx::getTexture(aaa.next_frame_hdr_fb)}, aaa.attr0, aaa.frame_hdr_fb, aaa.dof, aaa_config.dof_focus_point, aaa_config.dof_focus_length);
}
// final compositing for presentation (exposure/gamma correction)
if (aaa_config.use_tonemapping) {

View File

@ -3,6 +3,7 @@
#pragma once
#include "engine/aaa_blur.h"
#include "engine/dof.h"
#include "engine/bloom.h"
#include "engine/downsample.h"
#include "engine/forward_pipeline.h"
@ -44,6 +45,7 @@ struct ForwardPipelineAAAConfig {
float motion_blur = 1.f;
float exposure = 1.f, gamma = 2.2f;
float sharpen = 0.1f;
float dof_focus_point = 0.f, dof_focus_length = 0.f;
bool use_tonemapping = true;
float specular_weight = 1.f;
@ -112,6 +114,7 @@ struct ForwardPipelineAAA {
//
TAA taa;
Dof dof;
//
AAABlur blur;

View File

@ -1 +1 @@
3.2.6
3.2.7

View File

@ -12,11 +12,11 @@ here = path.abspath(path.dirname(__file__))
# get version
with open(path.join(here, 'version.txt'), encoding='utf-8') as f:
version_string = f.read()
version_string = f.read().strip()
# get the long description from the relevant file
with open(path.join(here, 'DESCRIPTION.rst'), encoding='utf-8') as f:
long_description = f.read()
long_description = f.read().strip()
setup(
name='harfang',

View File

@ -1,3 +1,12 @@
# [3.2.7] - 2023-08-14
This minor release brings the support for the DOF post process.
* Added the support for the depth of field post process (CoC spiral gather method)
* Adds `dof_focus_point` and `dof_focus_length` (see [ForwardPipelineAAAConfig()](https://dev.harfang3d.com/api/3.2.7/cpython/classes/#forwardpipelineaaaconfig))
* Available in the AAA rendering pipeline only.
* Fix CMake warnings.
# [3.2.6] - 2023-06-05
This minor release provides several fixes and brings a functionning API to capture the framebuffer and save it as a picture.