diff options
Diffstat (limited to 'source/blender/draw')
19 files changed, 45 insertions, 48 deletions
diff --git a/source/blender/draw/engines/eevee/eevee_materials.c b/source/blender/draw/engines/eevee/eevee_materials.c index 1cb630e6d59..ff7dda1152c 100644 --- a/source/blender/draw/engines/eevee/eevee_materials.c +++ b/source/blender/draw/engines/eevee/eevee_materials.c @@ -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; diff --git a/source/blender/draw/engines/eevee/eevee_private.h b/source/blender/draw/engines/eevee/eevee_private.h index 6f30ffcb364..b7f2b0ae859 100644 --- a/source/blender/draw/engines/eevee/eevee_private.h +++ b/source/blender/draw/engines/eevee/eevee_private.h @@ -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) diff --git a/source/blender/draw/engines/eevee/eevee_render.c b/source/blender/draw/engines/eevee/eevee_render.c index c3b909f5fb9..1d18056e175 100644 --- a/source/blender/draw/engines/eevee/eevee_render.c +++ b/source/blender/draw/engines/eevee/eevee_render.c @@ -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) diff --git a/source/blender/draw/engines/eevee/shaders/common_uniforms_lib.glsl b/source/blender/draw/engines/eevee/shaders/common_uniforms_lib.glsl index c935eca6a39..0cf36817788 100644 --- a/source/blender/draw/engines/eevee/shaders/common_uniforms_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/common_uniforms_lib.glsl @@ -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) */ diff --git a/source/blender/draw/engines/eevee/shaders/surface_lib.glsl b/source/blender/draw/engines/eevee/shaders/surface_lib.glsl index ac7519195c0..13a6498938b 100644 --- a/source/blender/draw/engines/eevee/shaders/surface_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/surface_lib.glsl @@ -1,6 +1,7 @@ /** 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 \ vec3 worldPosition; \ @@ -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; } diff --git a/source/blender/draw/engines/eevee/shaders/volumetric_frag.glsl b/source/blender/draw/engines/eevee/shaders/volumetric_frag.glsl index eebcf56de28..90c36801dd5 100644 --- a/source/blender/draw/engines/eevee/shaders/volumetric_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/volumetric_frag.glsl @@ -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; } diff --git a/source/blender/draw/engines/eevee_next/eevee_camera.cc b/source/blender/draw/engines/eevee_next/eevee_camera.cc index b9040f0f3ab..ad22219f0ae 100644 --- a/source/blender/draw/engines/eevee_next/eevee_camera.cc +++ b/source/blender/draw/engines/eevee_next/eevee_camera.cc @@ -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) { diff --git a/source/blender/draw/engines/eevee_next/eevee_camera.hh b/source/blender/draw/engines/eevee_next/eevee_camera.hh index 49f9b14e11b..aaef0f5898d 100644 --- a/source/blender/draw/engines/eevee_next/eevee_camera.hh +++ b/source/blender/draw/engines/eevee_next/eevee_camera.hh @@ -99,7 +99,7 @@ class Camera { BLI_assert(data_.initialized); return data_; } - const GPUUniformBuf *ubo_get() const + GPUUniformBuf *ubo_get() const { return data_; } diff --git a/source/blender/draw/engines/eevee_next/eevee_defines.hh b/source/blender/draw/engines/eevee_next/eevee_defines.hh index 248dfae6df9..fca8737f661 100644 --- a/source/blender/draw/engines/eevee_next/eevee_defines.hh +++ b/source/blender/draw/engines/eevee_next/eevee_defines.hh @@ -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 diff --git a/source/blender/draw/engines/eevee_next/eevee_pipeline.cc b/source/blender/draw/engines/eevee_next/eevee_pipeline.cc index cc5a4d56231..e6b37b4ad47 100644 --- a/source/blender/draw/engines/eevee_next/eevee_pipeline.cc +++ b/source/blender/draw/engines/eevee_next/eevee_pipeline.cc @@ -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); diff --git a/source/blender/draw/engines/eevee_next/eevee_shader_shared.hh b/source/blender/draw/engines/eevee_next/eevee_shader_shared.hh index 8e96445d6b9..fd06cdc7f23 100644 --- a/source/blender/draw/engines/eevee_next/eevee_shader_shared.hh +++ b/source/blender/draw/engines/eevee_next/eevee_shader_shared.hh @@ -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. */ diff --git a/source/blender/draw/engines/eevee_next/shaders/eevee_nodetree_lib.glsl b/source/blender/draw/engines/eevee_next/shaders/eevee_nodetree_lib.glsl index 9422cb726b7..4b53375575c 100644 --- a/source/blender/draw/engines/eevee_next/shaders/eevee_nodetree_lib.glsl +++ b/source/blender/draw/engines/eevee_next/shaders/eevee_nodetree_lib.glsl @@ -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; } diff --git a/source/blender/draw/engines/eevee_next/shaders/infos/eevee_material_info.hh b/source/blender/draw/engines/eevee_next/shaders/infos/eevee_material_info.hh index 78d52d4b90e..b632564a9ca 100644 --- a/source/blender/draw/engines/eevee_next/shaders/infos/eevee_material_info.hh +++ b/source/blender/draw/engines/eevee_next/shaders/infos/eevee_material_info.hh @@ -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 diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h index 1752198c349..c65938fd8ce 100644 --- a/source/blender/draw/intern/DRW_render.h +++ b/source/blender/draw/intern/DRW_render.h @@ -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. */ diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index 3272edef750..50ea27efba1 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -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; diff --git a/source/blender/draw/intern/draw_manager_data.cc b/source/blender/draw/intern/draw_manager_data.cc index fc4e444e43e..1d678886380 100644 --- a/source/blender/draw/intern/draw_manager_data.cc +++ b/source/blender/draw/intern/draw_manager_data.cc @@ -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)); diff --git a/source/blender/draw/intern/draw_shader_shared.h b/source/blender/draw/intern/draw_shader_shared.h index 13f21323552..b8c2d8890a5 100644 --- a/source/blender/draw/intern/draw_shader_shared.h +++ b/source/blender/draw/intern/draw_shader_shared.h @@ -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 /** \} */ diff --git a/source/blender/draw/intern/draw_view.cc b/source/blender/draw/intern/draw_view.cc index bf3505c7645..3b16ea74a67 100644 --- a/source/blender/draw/intern/draw_view.cc +++ b/source/blender/draw/intern/draw_view.cc @@ -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())); diff --git a/source/blender/draw/intern/shaders/common_view_lib.glsl b/source/blender/draw/intern/shaders/common_view_lib.glsl index a7f8f858352..2382337e782 100644 --- a/source/blender/draw/intern/shaders/common_view_lib.glsl +++ b/source/blender/draw/intern/shaders/common_view_lib.glsl @@ -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 */ |