DRW: Move CameraTexCoFactors to engine specific storage

This is part of the effor to simplify the View struct in order to implement
multiview rendering.

The CameraTexCoFactors being only valid for a single view, and being only
used in very few places, it make sense to move it to the engine side.
This commit is contained in:
Clément Foucault
2022-10-06 16:42:19 +02:00
parent 055680a89e
commit 03a7f1d7b1
19 changed files with 45 additions and 48 deletions

View File

@@ -231,6 +231,13 @@ void EEVEE_materials_init(EEVEE_ViewLayerData *sldata,
eevee_init_noise_texture();
}
if (draw_ctx->rv3d) {
copy_v4_v4(sldata->common_data.camera_uv_scale, draw_ctx->rv3d->viewcamtexcofac);
}
else {
copy_v4_fl4(sldata->common_data.camera_uv_scale, 1.0f, 1.0f, 0.0f, 0.0f);
}
if (!DRW_state_is_image_render() && ((stl->effects->enabled_effects & EFFECT_TAA) == 0)) {
sldata->common_data.alpha_hash_offset = 0.0f;
sldata->common_data.alpha_hash_scale = 1.0f;

View File

@@ -895,14 +895,11 @@ typedef struct EEVEE_CommonUniformBuffer {
float prb_irradiance_smooth; /* float */
float prb_lod_cube_max; /* float */
/* Misc */
int ray_type; /* int */
float ray_depth; /* float */
float alpha_hash_offset; /* float */
float alpha_hash_scale; /* float */
float pad7; /* float */
float pad8; /* float */
float pad9; /* float */
float pad10; /* float */
int ray_type; /* int */
float ray_depth; /* float */
float alpha_hash_offset; /* float */
float alpha_hash_scale; /* float */
float camera_uv_scale[2], camera_uv_bias[2]; /* vec4 */
} EEVEE_CommonUniformBuffer;
BLI_STATIC_ASSERT_ALIGN(EEVEE_CommonUniformBuffer, 16)

View File

@@ -157,8 +157,6 @@ void EEVEE_render_view_sync(EEVEE_Data *vedata, RenderEngine *engine, struct Dep
DRW_view_reset();
DRW_view_default_set(view);
DRW_view_set_active(view);
DRW_view_camtexco_set(view, g_data->camtexcofac);
}
void EEVEE_render_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)

View File

@@ -1,4 +1,6 @@
#define COMMON_UNIFORMS_LIB
layout(std140) uniform common_block
{
mat4 pastViewProjectionMatrix;
@@ -42,10 +44,8 @@ layout(std140) uniform common_block
float rayDepth;
float alphaHashOffset;
float alphaHashScale;
float pad6;
float pad7;
float pad8;
float pad9;
/* Misc */
vec4 cameraUvScaleBias;
};
/* rayType (keep in sync with ray_type) */

View File

@@ -1,5 +1,6 @@
/** This describe the entire interface of the shader. */
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#define SURFACE_INTERFACE \
@@ -176,13 +177,13 @@ vec3 coordinate_screen(vec3 P)
/* Unsupported. It would make the probe camera-dependent. */
window.xy = vec2(0.5);
#elif defined(WORLD_BACKGROUND)
#elif defined(WORLD_BACKGROUND) && defined(COMMON_UNIFORMS_LIB)
window.xy = project_point(ProjectionMatrix, viewPosition).xy * 0.5 + 0.5;
window.xy = window.xy * CameraTexCoFactors.xy + CameraTexCoFactors.zw;
window.xy = window.xy * cameraUvScaleBias.xy + cameraUvScaleBias.zw;
#else /* MESH */
#elif defined(COMMON_UNIFORMS_LIB) /* MESH */
window.xy = project_point(ProjectionMatrix, transform_point(ViewMatrix, P)).xy * 0.5 + 0.5;
window.xy = window.xy * CameraTexCoFactors.xy + CameraTexCoFactors.zw;
window.xy = window.xy * cameraUvScaleBias.xy + cameraUvScaleBias.zw;
#endif
return window;
}

View File

@@ -53,7 +53,7 @@ vec3 coordinate_screen(vec3 P)
{
vec3 window = vec3(0.0);
window.xy = project_point(ProjectionMatrix, transform_point(ViewMatrix, P)).xy * 0.5 + 0.5;
window.xy = window.xy * CameraTexCoFactors.xy + CameraTexCoFactors.zw;
window.xy = window.xy * cameraUvScaleBias.xy + cameraUvScaleBias.zw;
return window;
}

View File

@@ -85,7 +85,9 @@ void Camera::sync()
DRW_view_winmat_get(inst_.drw_view, data.wininv.ptr(), true);
DRW_view_persmat_get(inst_.drw_view, data.persmat.ptr(), false);
DRW_view_persmat_get(inst_.drw_view, data.persinv.ptr(), true);
DRW_view_camtexco_get(inst_.drw_view, data.uv_scale);
/* TODO(fclem): Derive from rv3d instead. */
data.uv_scale = float2(1.0f);
data.uv_bias = float2(0.0f);
}
else if (inst_.render) {
/* TODO(@fclem): Over-scan. */
@@ -106,6 +108,8 @@ void Camera::sync()
data.wininv = data.winmat.inverted();
data.persmat = data.winmat * data.viewmat;
data.persinv = data.persmat.inverted();
data.uv_scale = float2(1.0f);
data.uv_bias = float2(0.0f);
}
if (camera_eval) {

View File

@@ -99,7 +99,7 @@ class Camera {
BLI_assert(data_.initialized);
return data_;
}
const GPUUniformBuf *ubo_get() const
GPUUniformBuf *ubo_get() const
{
return data_;
}

View File

@@ -90,6 +90,8 @@
#define VELOCITY_CAMERA_CURR_BUF 4
#define VELOCITY_CAMERA_NEXT_BUF 5
#define CAMERA_BUF_SLOT 6
/* Storage Buffers. */
#define LIGHT_CULL_BUF_SLOT 0
#define LIGHT_BUF_SLOT 1

View File

@@ -79,6 +79,8 @@ void ForwardPipeline::sync()
/* Textures. */
prepass_ps_.bind_texture(RBUFS_UTILITY_TEX_SLOT, inst_.pipelines.utility_tx);
/* Uniform Buf. */
prepass_ps_.bind_ubo(CAMERA_BUF_SLOT, inst_.camera.ubo_get());
inst_.velocity.bind_resources(&prepass_ps_);
inst_.sampling.bind_resources(&prepass_ps_);
@@ -117,6 +119,8 @@ void ForwardPipeline::sync()
opaque_ps_.bind_ssbo(RBUFS_AOV_BUF_SLOT, &inst_.film.aovs_info);
/* Textures. */
opaque_ps_.bind_texture(RBUFS_UTILITY_TEX_SLOT, inst_.pipelines.utility_tx);
/* Uniform Buf. */
opaque_ps_.bind_ubo(CAMERA_BUF_SLOT, inst_.camera.ubo_get());
inst_.lights.bind_resources(&opaque_ps_);
inst_.sampling.bind_resources(&opaque_ps_);
@@ -140,6 +144,8 @@ void ForwardPipeline::sync()
/* Textures. */
sub.bind_texture(RBUFS_UTILITY_TEX_SLOT, inst_.pipelines.utility_tx);
/* Uniform Buf. */
opaque_ps_.bind_ubo(CAMERA_BUF_SLOT, inst_.camera.ubo_get());
inst_.lights.bind_resources(&sub);
inst_.sampling.bind_resources(&sub);

View File

@@ -163,7 +163,7 @@ struct CameraData {
float4x4 viewinv;
float4x4 winmat;
float4x4 wininv;
/** Camera UV scale and bias. Also known as `viewcamtexcofac`. */
/** Camera UV scale and bias. */
float2 uv_scale;
float2 uv_bias;
/** Panorama parameters. */

View File

@@ -345,7 +345,7 @@ vec3 coordinate_screen(vec3 P)
else {
/* TODO(fclem): Actual camera transform. */
window.xy = project_point(ProjectionMatrix, transform_point(ViewMatrix, P)).xy * 0.5 + 0.5;
window.xy = window.xy * CameraTexCoFactors.xy + CameraTexCoFactors.zw;
window.xy = window.xy * camera_buf.uv_scale + camera_buf.uv_bias;
}
return window;
}

View File

@@ -20,6 +20,8 @@ GPU_SHADER_CREATE_INFO(eevee_sampling_data)
GPU_SHADER_CREATE_INFO(eevee_utility_texture)
.sampler(RBUFS_UTILITY_TEX_SLOT, ImageType::FLOAT_2D_ARRAY, "utility_tx");
GPU_SHADER_CREATE_INFO(eevee_camera).uniform_buf(CAMERA_BUF_SLOT, "CameraData", "camera_buf");
/** \} */
/* -------------------------------------------------------------------- */
@@ -114,7 +116,8 @@ GPU_SHADER_CREATE_INFO(eevee_surf_deferred)
// .image_out(6, Qualifier::READ_WRITE, GPU_RGBA16F, "rpass_volume_light")
/* TODO: AOVs maybe? */
.fragment_source("eevee_surf_deferred_frag.glsl")
// .additional_info("eevee_aov_out", "eevee_sampling_data", "eevee_utility_texture")
// .additional_info("eevee_aov_out", "eevee_sampling_data", "eevee_camera",
// "eevee_utility_texture")
;
GPU_SHADER_CREATE_INFO(eevee_surf_forward)
@@ -127,6 +130,7 @@ GPU_SHADER_CREATE_INFO(eevee_surf_forward)
.fragment_source("eevee_surf_forward_frag.glsl")
.additional_info("eevee_cryptomatte_out",
"eevee_light_data",
"eevee_camera",
"eevee_utility_texture",
"eevee_sampling_data"
// "eevee_lightprobe_data",
@@ -141,7 +145,7 @@ GPU_SHADER_CREATE_INFO(eevee_surf_forward)
GPU_SHADER_CREATE_INFO(eevee_surf_depth)
.vertex_out(eevee_surf_iface)
.fragment_source("eevee_surf_depth_frag.glsl")
.additional_info("eevee_sampling_data", "eevee_utility_texture");
.additional_info("eevee_sampling_data", "eevee_camera", "eevee_utility_texture");
GPU_SHADER_CREATE_INFO(eevee_surf_world)
.vertex_out(eevee_surf_iface)
@@ -151,6 +155,7 @@ GPU_SHADER_CREATE_INFO(eevee_surf_world)
.additional_info("eevee_aov_out",
"eevee_cryptomatte_out",
"eevee_render_pass_out",
"eevee_camera",
"eevee_utility_texture");
#undef image_out

View File

@@ -683,8 +683,6 @@ const DRWView *DRW_view_get_active(void);
* \note planes must be in world space.
*/
void DRW_view_clip_planes_set(DRWView *view, float (*planes)[4], int plane_len);
void DRW_view_camtexco_set(DRWView *view, float texco[4]);
void DRW_view_camtexco_get(const DRWView *view, float r_texco[4]);
/* For all getters, if view is NULL, default view is assumed. */

View File

@@ -566,7 +566,6 @@ static void drw_manager_init(DRWManager *dst, GPUViewport *viewport, const int s
dst->pixsize = rv3d->pixsize;
dst->view_default = DRW_view_create(rv3d->viewmat, rv3d->winmat, NULL, NULL, NULL);
DRW_view_camtexco_set(dst->view_default, rv3d->viewcamtexcofac);
if (dst->draw_ctx.sh_cfg == GPU_SHADER_CFG_CLIPPED) {
int plane_len = (RV3D_LOCK_FLAGS(rv3d) & RV3D_BOXCLIP) ? 4 : 6;

View File

@@ -2213,8 +2213,6 @@ DRWView *DRW_view_create(const float viewmat[4][4],
view->visibility_fn = visibility_fn;
view->parent = nullptr;
copy_v4_fl4(view->storage.viewcamtexcofac, 1.0f, 1.0f, 0.0f, 0.0f);
if (DST.draw_ctx.evil_C && DST.draw_ctx.region) {
int region_origin[2] = {DST.draw_ctx.region->winrct.xmin, DST.draw_ctx.region->winrct.ymin};
wmWindow *win = CTX_wm_window(DST.draw_ctx.evil_C);
@@ -2357,16 +2355,6 @@ void DRW_view_clip_planes_set(DRWView *view, float (*planes)[4], int plane_len)
}
}
void DRW_view_camtexco_set(DRWView *view, float texco[4])
{
copy_v4_v4(view->storage.viewcamtexcofac, texco);
}
void DRW_view_camtexco_get(const DRWView *view, float r_texco[4])
{
copy_v4_v4(r_texco, view->storage.viewcamtexcofac);
}
void DRW_view_frustum_corners_get(const DRWView *view, BoundBox *corners)
{
memcpy(corners, &view->frustum_corners, sizeof(view->frustum_corners));

View File

@@ -69,8 +69,6 @@ struct ViewInfos {
float4 clip_planes[6];
float4 viewvecs[2];
/* Should not be here. Not view dependent (only main view). */
float4 viewcamtexcofac;
float2 viewport_size;
float2 viewport_size_inverse;
@@ -94,7 +92,6 @@ BLI_STATIC_ASSERT_ALIGN(ViewInfos, 16)
# define ProjectionMatrixInverse drw_view.wininv
# define clipPlanes drw_view.clip_planes
# define ViewVecs drw_view.viewvecs
# define CameraTexCoFactors drw_view.viewcamtexcofac
#endif
/** \} */

View File

@@ -21,8 +21,6 @@ void View::sync(const float4x4 &view_mat, const float4x4 &win_mat)
data_.viewinv = view_mat.inverted();
data_.winmat = win_mat;
data_.wininv = win_mat.inverted();
/* Should not be used anymore. */
data_.viewcamtexcofac = float4(1.0f, 1.0f, 0.0f, 0.0f);
data_.is_inverted = (is_negative_m4(view_mat.ptr()) == is_negative_m4(win_mat.ptr()));

View File

@@ -21,9 +21,6 @@ layout(std140) uniform viewBlock
/* View frustum corners [NDC(-1.0, -1.0, -1.0) & NDC(1.0, 1.0, 1.0)].
* Fourth components are near and far values. */
vec4 ViewVecs[2];
/* TODO: move it elsewhere. */
vec4 CameraTexCoFactors;
};
#endif /* USE_GPU_SHADER_CREATE_INFO */