Merge branch 'blender-v4.2-release'

This commit is contained in:
Clément Foucault
2024-06-14 20:33:25 +02:00
5 changed files with 43 additions and 39 deletions

View File

@@ -164,11 +164,10 @@ static eDRWLevelOfDetail calc_level_of_detail(const float viewport_scale)
return DRW_LOD_LOW;
}
static int calc_sphere_size(const float viewport_scale)
static int calc_sphere_extent(const float viewport_scale)
{
const int sphere_radius = U.lookdev_sphere_size * UI_SCALE_FAC * viewport_scale;
const int sphere_size = sphere_radius * 2;
return sphere_size;
return sphere_radius * 2;
}
void LookdevModule::sync()
@@ -177,29 +176,39 @@ void LookdevModule::sync()
return;
}
const float viewport_scale = calc_viewport_scale();
const int sphere_size = calc_sphere_size(viewport_scale);
const int2 extent(sphere_size, sphere_size);
const int2 extent = int2(calc_sphere_extent(viewport_scale));
const eGPUTextureFormat depth_format = GPU_DEPTH_COMPONENT24;
const eGPUTextureFormat color_format = GPU_RGBA16F;
depth_tx_.ensure_2d(depth_format, extent);
for (int index : IndexRange(num_spheres)) {
if (spheres_[index].color_tx_.ensure_2d(color_format, extent)) {
/* Request redraw if the lightprobe were off and the sampling was already finished. */
if (inst_.sampling.finished_viewport()) {
inst_.sampling.reset();
}
}
spheres_[index].framebuffer.ensure(GPU_ATTACHMENT_TEXTURE(depth_tx_),
spheres_[index].framebuffer.ensure(GPU_ATTACHMENT_NONE,
GPU_ATTACHMENT_TEXTURE(spheres_[index].color_tx_));
}
float4 position = inst_.camera.data_get().viewinv *
float4(0.0, 0.0, -inst_.camera.data_get().clip_near, 1.0);
float4x4 model_m4 = float4x4::identity();
model_m4 = math::translate(model_m4, float3(position));
model_m4 = math::scale(model_m4, float3(sphere_scale));
const Camera &cam = inst_.camera;
float sphere_distance = cam.data_get().clip_near;
int2 display_extent = inst_.film.display_extent_get();
float pixel_radius = inst_.shadows.screen_pixel_radius(
cam.data_get().wininv, cam.is_perspective(), display_extent);
if (cam.is_perspective()) {
pixel_radius *= sphere_distance;
}
this->sphere_radius_ = (extent.x / 2) * pixel_radius;
this->sphere_position_ = cam.position() -
cam.forward() * (sphere_distance + this->sphere_radius_);
float4x4 model_m4 = float4x4(float3x3(cam.data_get().viewmat));
model_m4.location() = this->sphere_position_;
model_m4 = math::scale(model_m4, float3(this->sphere_radius_));
ResourceHandle handle = inst_.manager->resource_handle(model_m4);
gpu::Batch *geom = DRW_cache_sphere_get(calc_level_of_detail(viewport_scale));
@@ -218,8 +227,7 @@ void LookdevModule::sync_pass(PassSimple &pass,
pass.clear_depth(1.0f);
pass.clear_color(float4(0.0, 0.0, 0.0, 1.0));
const DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH |
DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_CULL_BACK;
const DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_CULL_BACK;
GPUMaterial *gpumat = inst_.shaders.material_shader_get(
mat, mat->nodetree, MAT_PIPE_FORWARD, MAT_GEOM_MESH, MAT_PROBE_NONE);

View File

@@ -98,13 +98,10 @@ class LookdevModule {
bool enabled_;
static constexpr int num_spheres = 2;
/**
* The scale of the lookdev spheres.
*
* The lookdev spheres are resized to a small scale. This would reduce shadow artifacts as they
* would most likely be inside or outside shadow.
*/
static constexpr float sphere_scale = 0.01f;
/* Size and position of the look-dev spheres in world space. */
float sphere_radius_;
float3 sphere_position_;
rcti visible_rect_;
@@ -113,8 +110,6 @@ class LookdevModule {
Texture dummy_aov_color_tx_;
Texture dummy_aov_value_tx_;
Texture depth_tx_ = {"Lookdev.Depth"};
struct Sphere {
Framebuffer framebuffer = {"Lookdev.Framebuffer"};
Texture color_tx_ = {"Lookdev.Color"};

View File

@@ -1117,15 +1117,17 @@ void ShadowModule::debug_end_sync()
}
/* Compute approximate screen pixel density (as world space radius). */
float ShadowModule::screen_pixel_radius(const View &view, const int2 &extent)
float ShadowModule::screen_pixel_radius(const float4x4 &wininv,
bool is_perspective,
const int2 &extent)
{
float min_dim = float(min_ii(extent.x, extent.y));
float3 p0 = float3(-1.0f, -1.0f, 0.0f);
float3 p1 = float3(float2(min_dim / extent) * 2.0f - 1.0f, 0.0f);
mul_project_m4_v3(view.wininv().ptr(), p0);
mul_project_m4_v3(view.wininv().ptr(), p1);
p0 = math::project_point(wininv, p0);
p1 = math::project_point(wininv, p1);
/* Compute radius at unit plane from the camera. This is NOT the perspective division. */
if (view.is_persp()) {
if (is_perspective) {
p0 = p0 / p0.z;
p1 = p1 / p1.z;
}
@@ -1201,7 +1203,7 @@ void ShadowModule::set_view(View &view, int2 extent)
1);
max_view_per_tilemap_ = max_view_per_tilemap();
data_.film_pixel_radius = screen_pixel_radius(view, extent);
data_.film_pixel_radius = screen_pixel_radius(view.wininv(), view.is_persp(), extent);
inst_.uniform_data.push_update();
usage_tag_fb_resolution_ = math::divide_ceil(extent, int2(std::exp2(usage_tag_fb_lod_)));

View File

@@ -363,13 +363,16 @@ class ShadowModule {
do_full_update_ = true;
}
/** Compute approximate screen pixel space radius. */
static float screen_pixel_radius(const float4x4 &wininv,
bool is_perspective,
const int2 &extent);
private:
void remove_unused();
void debug_page_map_call(DRWPass *pass);
bool shadow_update_finished();
/** Compute approximate screen pixel space radius. */
float screen_pixel_radius(const View &view, const int2 &extent);
/** Compute approximate punctual shadow pixel world space radius, 1 unit away of the light. */
float tilemap_pixel_radius();

View File

@@ -366,15 +366,11 @@ void LookdevView::render()
}
GPU_debug_group_begin("Lookdev");
const float radius = inst_.lookdev.sphere_radius_;
const float clip = inst_.camera.data_get().clip_near;
const float4x4 win_m4 = math::projection::orthographic_infinite(
-radius, radius, -radius, radius, clip);
const float4x4 &view_m4 = inst_.camera.data_get().viewmat;
const float sphere_scale = inst_.lookdev.sphere_scale;
const float clip_near = inst_.camera.data_get().clip_near;
float4x4 win_m4 = math::projection::orthographic(-sphere_scale,
sphere_scale,
-sphere_scale,
sphere_scale,
clip_near - sphere_scale,
clip_near + sphere_scale);
view_.sync(view_m4, win_m4);
inst_.lookdev.draw(view_);